Back to Learn
intermediate10 min read

MCP Transport Protocols

Learn about the different ways to connect MCP clients and servers.

MCP supports multiple transport protocols to suit different use cases. The transport layer handles communication between the MCP client and server, but the MCP protocol itself remains the same regardless of which transport you choose.

Transport Types

Stdio Transport
Standard input/output communication for local servers

Best for:

Local development, CLI tools, desktop applications

Pros

  • Simple to implement and debug
  • No network overhead
  • Works great with Claude Desktop
  • Perfect for local file system access

Cons

  • Only works locally
  • Cannot be accessed remotely
  • One client per server process

Code Examples

Stdio Transport
Perfect for local development and Claude Desktop integration
stdio-server.js
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "stdio-server",
  version: "1.0.0",
});

// Add your tools
server.tool(
  "get_time",
  "Get the current time",
  {},
  async () => ({
    content: [{
      type: "text",
      text: `Current time: ${new Date().toISOString()}`
    }],
  })
);

// Connect using stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);

console.error("Stdio MCP Server running...");
Stdio is the default transport for Claude Desktop. Use console.error() for logging since stdout is used for MCP messages.

Running with Claude Desktop:

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "my-server": {
      "command": "node",
      "args": ["path/to/stdio-server.js"]
    }
  }
}

Quick Comparison

FeatureStdioHTTP/SSEWebSocket
Local/RemoteLocal onlyBothBoth
ComplexitySimpleModerateModerate
PerformanceExcellentGoodExcellent
Real-timeYesOne-wayYes
Best ForDesktop appsWeb servicesReal-time apps
Claude Desktop

When to Use Each Transport

Use Stdio When...
  • You're building a tool for Claude Desktop
  • Your server needs local file system access
  • You want the simplest setup for development
  • You don't need remote access
Use HTTP/SSE When...
  • You're deploying a public API or web service
  • You need to serve multiple clients
  • You want to use standard HTTP infrastructure
  • You need server-to-client updates
Use WebSocket When...
  • You need bidirectional real-time communication
  • You're building collaborative tools
  • You need low-latency updates
  • You're streaming data or events
Try It in the Playground
Experiment with different transport implementations
Instead of setting up a local environment, you can test MCP servers with different transports right in our interactive playground. Try modifying the code and testing the tools!
Transport Playground

Try changing the transport implementation and testing the server

Loading...

Key Takeaways

  • The transport layer handles communication, but the MCP protocol stays the same
  • Stdio is perfect for local development and Claude Desktop integration
  • HTTP/SSE enables web-based deployments and public APIs
  • WebSocket provides bidirectional real-time communication
  • Choose based on your deployment needs and use case

Ready for more?

Now that you understand MCP transports, explore more advanced topics or try building something!