Transports — HTTP vs stdio
| Field | Value |
|---|---|
| Type | Agent Reference |
| Source | ~/.copilot/agents/_refs/typescript-mcp-expert/transports.md |
| Description | Not specified |
Source Content
Transports — HTTP vs stdio
Reference for TypeScript MCP Server Expert. Choose transport based on deployment shape.
Decision matrix
| Scenario | Transport |
|---|---|
| Local CLI tool launched by host (Claude Desktop, Cursor) | StdioServerTransport |
| Container/process serving multiple clients | StreamableHTTPServerTransport |
| Browser-based client | StreamableHTTPServerTransport (with CORS) |
| Long-lived sessions across reconnects | HTTP with session management |
| Legacy clients only | SSE 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: truefor any local server. - Configure CORS to expose the
Mcp-Session-Idheader 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.