[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

Remote Client Connections

🔗 Client Development10 min110 BASE XP

Connecting to Cloud-Hosted Servers

Not all MCP servers run locally. For cloud-hosted servers, you use the SSE (Server-Sent Events) Client Transport.

SSE Client Setup

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

const transport = new SSEClientTransport(
  new URL("https://mcp.example.com/sse")
);

const client = new Client({ name: "my-app", version: "1.0.0" });
await client.connect(transport);

// Now use the client exactly like stdio — the API is identical
const { tools } = await client.listTools();
const result = await client.callTool("search_knowledge_base", {
  query: "refund policy"
});

Authentication

// For OAuth-secured remote servers:
const transport = new SSEClientTransport(
  new URL("https://mcp.example.com/sse"),
  {
    requestInit: {
      headers: {
        "Authorization": "Bearer eyJhbG..."
      }
    }
  }
);

Transport Comparison for Clients

TransportSetupSecurityLatencyBest For
StdioLaunch child processOS-level (local only)~1msLocal tools, dev environments
SSEHTTP URL + authOAuth 2.1 / Bearer~50-200msCloud servers, shared services

Error Handling & Reconnection

// Handle connection errors gracefully
client.onclose = () => {
  console.error("Connection lost. Attempting reconnect...");
  setTimeout(async () => {
    try {
      await client.connect(transport);
      console.log("Reconnected successfully");
    } catch (e) {
      console.error("Reconnection failed:", e);
    }
  }, 5000);
};

// Handle transport errors
transport.onerror = (error) => {
  console.error("Transport error:", error);
};
💡 Key Insight: The beauty of MCP's transport abstraction is that your application code doesn't change between local and remote servers. You only swap the transport — all tool calls, resource reads, and prompt fetches remain identical.
SYNAPSE VERIFICATION
QUERY 1 // 3
What transport do you use for connecting to cloud-hosted MCP servers?
StdioClientTransport
SSEClientTransport
WebSocketTransport
HTTPTransport
Watch: 139x Rust Speedup
Remote Client Connections | Client Development — MCP Academy