Transports

MCP Transports: How Clients Talk to Servers

Transports define how MCP clients and servers communicate. There are two main options: stdio for local servers and Streamable HTTP for remote servers.
typescript
// STDIO Transport (local)
// Host spawns server as child process
// Communication via stdin/stdout
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const transport = new StdioServerTransport();
await server.connect(transport);

// Streamable HTTP Transport (remote)
// Server runs on a URL
import express from "express";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";

const app = express();
app.post("/mcp", async (req, res) => {
  const transport = new StreamableHTTPServerTransport("/mcp");
  await server.connect(transport);
  await transport.handleRequest(req, res);
});
app.listen(3001);

Tip:Use stdio for development and local tools. Use HTTP when you need to deploy your server to the cloud or share it with others.

PreviewTypeScriptRead Only
Copy this code and run it locally with npx tsx server.ts

💬 Got questions? Ask me anything!