Create a new MCP connection.
Resolves the server binary path, gateway URL, and authentication options
from the explicit options, then from environment variables, and finally
module-level defaults. The connection is not opened until connect
is called.
Connection options including server path, gateway URL, API key, retry policy, and human-readable server label for log messages.
Check if client is connected
Connection status
Check if using gateway HTTP transport
True if gateway mode is active
Get the configured gateway URL
Gateway URL or null if using stdio transport
Get the configured gateway API key
Gateway API key or null if not set
Get the current MCP session ID
Session ID returned by the gateway, or null if not yet connected
Get connection health metrics for telemetry
Object with timeout count, reconnection count, and current connection status
Connect to the MCP server with retry logic
Private_Advance the attempt counter and compute the next retry delay. Throws immediately for non-retriable errors or when exhausted.
The error from the failed attempt
Delay in milliseconds to wait before the next attempt
Private_Build a GatewayContext adapter for gateway.ts helpers.
Context adapter for gateway.ts helpers
Private_Build a SpawnContext adapter for process.ts spawn helpers.
Context adapter for stdio spawn helpers
Private_Attempt a single connection via stdio (spawns server binary). Delegates to attemptStdioConnection in process.ts.
Resolves when the spawn has completed (or rejects on spawn failure)
Disconnect from the MCP server
Handle incoming messages from MCP server (stdio mode only). Delegates to handleIncomingMessage in process.ts.
JSON message line from server
Send a request to the MCP server
RPC method name
Method parameters
Server response
List available MCP tools
List of available tools
Call an MCP tool
Tool name
Tool arguments (must be a plain object, non-null, not an array)
Tool execution result
Private_Build a ReconnectOps adapter for reconnect.ts helpers.
Context adapter for reconnect/retry helpers
Attempt to reconnect to the MCP server. Deduplicates concurrent calls — only one reconnect runs at a time.
Resolves when reconnect succeeds or all attempts are exhausted
Call an MCP tool with automatic retry on timeout or connection loss. Reconnects automatically if the connection was lost between attempts.
Only transient failures are retried (see isRetriableError). Non-retriable
errors — rate-limit (429), session-expired (401), and programmer errors such
as TypeError — are re-thrown immediately without consuming any retry budget.
Tool name
Tool arguments (plain object, non-null, not an array)
OptionalmaxRetries: numberOverride the default retry count from options
Tool execution result
PrivateserverPrivateconnectedPrivateprocessPrivaterequestPrivatependingPrivateconnectionPrivatemaxPrivateconnectionPrivatemaxPrivatereconnectingPrivatetimeoutPrivatereconnectPrivategatewayGateway URL for HTTP transport mode
PrivategatewayAPI key for gateway authentication
PrivatemcpMCP session ID returned by the gateway
ProtectedserverHuman-readable server name for log messages
Base MCP connection managing JSON-RPC 2.0 transport over stdio or HTTP gateway. Extended by domain-specific clients to add tool wrapper methods.