Skip to content

Transports — HTTP vs stdio

FieldValue
TypeAgent Reference
Source~/.copilot/agents/_refs/typescript-mcp-expert/transports.md
DescriptionNot specified

Source Content

Transports — HTTP vs stdio

Reference for TypeScript MCP Server Expert. Choose transport based on deployment shape.

Decision matrix

ScenarioTransport
Local CLI tool launched by host (Claude Desktop, Cursor)StdioServerTransport
Container/process serving multiple clientsStreamableHTTPServerTransport
Browser-based clientStreamableHTTPServerTransport (with CORS)
Long-lived sessions across reconnectsHTTP with session management
Legacy clients onlySSE fallback (deprecated, see below)

stdio

  • One client per process. The host spawns the server and pipes stdin/stdout.
  • No CORS, no auth — the host owns the lifecycle.
  • Read configuration from environment variables.
const transport = new StdioServerTransport();
await server.connect(transport);

Streamable HTTP — stateless mode

Create a fresh transport per request. Simplest model; works well behind load balancers.

app.post('/mcp', async (req, res) => {
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
res.on('close', () => transport.close());
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
});

Always:

  • Bind cleanup to res.on('close', ...).
  • Set enableDnsRebindingProtection: true for any local server.
  • Configure CORS to expose the Mcp-Session-Id header for browser clients.

Streamable HTTP — session mode

For stateful workflows, supply a sessionIdGenerator and persist transports keyed by the Mcp-Session-Id header. Reuse the existing transport on subsequent requests with the same session id; create a new one on initialize.

Legacy SSE

The old SSEServerTransport is deprecated. Support it only for backwards compatibility: mount the legacy endpoint alongside the streamable HTTP endpoint and route by client capability negotiation. Prefer Streamable HTTP for all new work.

Configuration

  • Ports, hosts, API keys, paths → environment variables.
  • Document required env in the README and validate at startup with zod.