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
Private_Compute the delay before the next connection attempt.
Respects Retry-After carried by MCPRateLimitError; otherwise uses
exponential back-off (connectionRetryDelay * 2^(attempt - 1)).
The error from the failed attempt
Number of attempts made so far (1-indexed)
Delay in milliseconds
Private_Handle a single connection attempt error: re-throw immediately for non-retriable errors (e.g. session expiry), increment the attempt counter, and return the delay to wait before the next attempt. Throws when the maximum attempts have been exhausted.
The error from the failed attempt
Delay in milliseconds to wait before the next attempt
Connect to the MCP server with retry logic
Private_Validate a gateway response body, throwing on JSON-RPC errors.
Response content-type header
Raw response body text
Private_Build the Authorization header value for gateway requests. Keys that already contain a valid RFC 7235 scheme token followed by whitespace (e.g. "Bearer …", "Token …", "AWS4-HMAC-SHA256 …") are passed through unchanged. Otherwise the raw key is sent directly unless EP_MCP_GATEWAY_AUTH_SCHEME is set to a valid token, in which case that scheme prefix is prepended. The EP MCP gateway expects raw-token auth by default (no "Bearer " prefix).
Raw or pre-prefixed gateway API key
The full Authorization header value, or empty string for empty keys
Private_Attempt a single connection via MCP Gateway (HTTP transport)
Private_Attempt a single connection via stdio (spawns server binary)
Disconnect from the MCP server
Handle incoming messages from MCP server (stdio mode only)
JSON message line from server
Private_Throw an appropriate error for a non-OK gateway response.
Extracted to keep _sendGatewayRequest within cognitive-complexity limits.
The non-OK fetch Response
Private_Send a request via MCP Gateway (HTTP transport)
RPC method name
Method parameters
Server response
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
PrivatereconnectAttempt to reconnect to the MCP server with exponential back-off. Concurrent callers await the same in-flight reconnect instead of no-oping, ensuring the connection is re-established before all waiting callers continue.
Promise that resolves when reconnection succeeds or all attempts are exhausted
Private_Internal reconnect helper.
Waits for an exponential back-off delay derived from the current
reconnectCount, then delegates to connect() which handles its own
retry loop. This avoids composing N×N attempts.
Promise that resolves when reconnection succeeds or logs on failure
Private_Log a retry warning and, if disconnected, attempt to reconnect before waiting.
The error from the failed attempt
Zero-based current attempt index
Total retry count
Promise that resolves after logging, optional reconnect, and inter-retry delay
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.