Stateless Transports & Multiplexing
The Dual-Transport Problem
Section titled “The Dual-Transport Problem”The MCP client landscape currently contains two competing transport styles:
- Legacy Server-Sent Events (SSE): Traditional transport where the client opens a persistent GET stream and receives a session URL for subsequent POST requests.
- Streamable HTTP: Modern transport where client requests are atomic and self-contained over HTTP POST.
The Solution: McpMultiplexerHandler
Section titled “The Solution: McpMultiplexerHandler”McpMultiplexerHandler inspects incoming HTTP requests and routes them to the appropriate SDK transport handler:
func (h *McpMultiplexerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Header.Get("X-Mcp-Force-Sse") == "true" { h.sseHandler.ServeHTTP(w, r) return }
if r.Header.Get("Mcp-Session-Id") != "" || r.Method == "DELETE" || (r.Method == "POST" && !hasSessionID(r)) { h.streamableHandler.ServeHTTP(w, r) return }
h.sseHandler.ServeHTTP(w, r)}Why Stateless: true Matters
Section titled “Why Stateless: true Matters”When hosting on serverless platforms (Google Cloud Run, AWS ECS, Fly.io), containers scale to zero when idle and recycle frequently.
Configuring Stateless: true in StreamableHTTPOptions removes in-memory session dependencies:
- Each POST request creates a temporary, self-contained transport.
- Reconnected or restarted clients never encounter
404 session not founderrors. - Container cold starts do not disrupt tool executions.