← Back to Dashboard
1. The Client SDK2. Discovering & Calling Tools3. Remote Client Connections
Remote Client Connections
Connecting to Cloud-Hosted Servers
Not all MCP servers run locally. For cloud-hosted servers, you use the Streamable HTTP Client Transport (with SSE as a legacy fallback).
Streamable HTTP Client Setup
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const transport = new StreamableHTTPClientTransport(
new URL("https://mcp.example.com/mcp")
);
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 StreamableHTTPClientTransport(
new URL("https://mcp.example.com/mcp"),
{
requestInit: {
headers: {
"Authorization": "Bearer eyJhbG..."
}
}
}
);
Transport Comparison for Clients
| Transport | Setup | Security | Latency | Best For |
|---|---|---|---|---|
| Stdio | Launch child process | OS-level (local only) | ~1ms | Local tools, dev environments |
| Streamable HTTP | HTTP URL + auth | OAuth 2.1 / Bearer | ~50-200ms | Cloud servers, shared services (SSE available as legacy fallback) |
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.
⌨ HANDS-ON LABConnect to a Cloud-Hosted MCP Server
⭐ +150 XPNo install, no build - production MCP servers live at a URL. Register Linear's hosted server over HTTP transport and verify the connection details.
1Add Linear's remote server using the http transport flag.
2Inspect the registered server's transport, URL, and scope.
OBJECTIVE 1 / 2 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
What transport do you use for connecting to cloud-hosted MCP servers?
StdioClientTransport
StreamableHTTPClientTransport
WebSocketTransport
SSEClientTransport (legacy)