connectToRemoteServer(client: Client,remoteConfig: McpRemoteConfig,options?: { signal?: AbortSignal; oauth?: OAuthOptions; },): Promise<Transport>
Connects to a remote MCP server with automatic transport fallback
Implements the MCP specification for backwards compatibility by attempting multiple transport methods in sequence:
- First attempts StreamableHTTPClientTransport (modern streaming transport)
- If that fails with a 4xx HTTP error (excluding 401), falls back to SSEClientTransport
Both transports support OAuth authentication when oauth options are provided. If a 401 Unauthorized error occurs, the OAuth flow will be initiated automatically.
client: Client
The MCP client instance
remoteConfig: McpRemoteConfig
The remote server endpoint configuration
options: { signal?: AbortSignal; oauth?: OAuthOptions; }
Optional configuration including abort signal and OAuth settings
Promise<Transport>
Promise that resolves to the connected transport