
Transports: stdio and stateless Streamable HTTP
Transports: stdio and stateless Streamable HTTP
Where you are: Module 1, lesson 7. You know what a request looks like (L06). Now: how it travels, as lines on a subprocess's stdin and stdout or as HTTP POSTs to one endpoint. No video: the earlier one presented HTTP+SSE as current and is removed in V2.
What changed in V2: sessions, resumable streams and server-initiated messages were taught as Streamable HTTP features. 2026-07-28 removed all three; they appear here only as legacy behaviour.
What you will be able to do
- Pick stdio or Streamable HTTP and state the security baseline for each.
- Write a correct 2026-07-28 Streamable HTTP request with all required headers, and read the error when a header is wrong.
- Cancel a request correctly on each transport.
- Recognise legacy Streamable HTTP and HTTP+SSE traffic and how a current server treats it.
stdio (current, 2026-07-28)
The client launches the server as a subprocess. Rules from the stdio page:
- Each message is one JSON-RPC request, notification or response, delimited by newlines, and MUST NOT contain embedded newlines.
- The server MUST NOT write anything to stdout that is not a valid MCP message. Logs go to stderr, which the client may capture or ignore and SHOULD NOT treat as an error signal.
- The server MUST NOT write JSON-RPC requests; input requests go inside
InputRequiredResult(L05). Metadata lives in_meta; no headers. - Cancellation: the client MUST send
notifications/cancelledwith the request'srequestId. The server SHOULD stop work and MUST NOT send further messages for it. - Shutdown: the client SHOULD close stdin, wait, then terminate (SIGTERM, then SIGKILL on POSIX). Servers SHOULD exit when stdin closes. A crashed server SHOULD be restarted; in-flight requests are lost and can be retried.
The lab-l08 server logs [notes-server] ... to stderr; one print() to stdout would corrupt the stream. stdio implementations SHOULD NOT use the OAuth framework; they take credentials from the environment.
Streamable HTTP (current, 2026-07-28)
The server exposes one MCP endpoint (for example https://example.com/mcp) that accepts POST.
- Every client message is a new POST whose body is a single JSON-RPC request or notification.
- The client MUST send
Accept: application/json, text/event-stream. - For a request, the server replies with either one JSON object (
application/json) or an SSE stream scoped to that request, carrying related notifications (such asnotifications/progress) and then the final response. The client MUST support both. - The server MUST NOT send independent requests on the stream.
- Long-lived change notifications come only on the response stream of a
subscriptions/listenrequest.
Required headers on every POST:
| Header | Value | Required for |
|---|---|---|
MCP-Protocol-Version | same as _meta io.modelcontextprotocol/protocolVersion | all requests |
Mcp-Method | the JSON-RPC method | all requests |
Mcp-Name | params.name or params.uri | tools/call, resources/read, prompts/get |
Headers mirror the body so gateways can route without parsing JSON. The server MUST reject a mismatch or missing required header with HTTP 400 and -32020 (HeaderMismatch). Non-ASCII values use =?base64?...?=. x-mcp-header in a tool's schema mirrors a parameter into Mcp-Param-{Name}; servers SHOULD NOT mark secrets or personal data that way (intermediaries see headers).
Security (Security & Endpoint section):
- Servers MUST validate
Originon all incoming connections and MUST return 403 if it is present and invalid. This blocks DNS rebinding (a web page reaching a local server). - When running locally, servers SHOULD bind to
127.0.0.1, not0.0.0.0. - Servers SHOULD authenticate all connections (OAuth, L13).
Cancellation: closing the SSE response stream is the signal; the server MUST treat it as cancellation and MUST NOT send further messages for that request. No notifications/cancelled on HTTP. If a stream breaks, the request is lost; the client MUST re-issue it with a new id (no resumption).
Worked example: one endpoint, captured
Captured 2026-11-26 from servers on 127.0.0.1 built with the official Python SDK mcp 2.3.0 (as in the L11 lab). A tool call:
POST /mcp HTTP/1.1
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: release_reservation
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"release_reservation","arguments":{"sku":"ELC-0002"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{"elicitation":{"form":{}}}}}}
What the server returned for variations of that request:
| Variation | HTTP status | Body |
|---|---|---|
Correct server/discover | 200 | DiscoverResult (L06) |
Mcp-Name: other_tool but body names release_reservation | 400 | -32020, "mcp-name header does not match the request body's 'name' parameter" |
No Mcp-Method header | 400 | -32020, "mcp-method header does not match the request body's method" |
MCP-Protocol-Version: 2099-01-01 (and same in _meta) | 400 | -32022, "supported":["2026-07-28"] |
params without _meta | 400 | -32602 |
GET /mcp with MCP-Protocol-Version: 2026-07-28 | 405 | Allow: POST |
GET /mcp with no version header | 400 | -32600, "Bad Request: Missing session ID" (routed to the legacy path, see below) |
Origin: http://evil.example | 403 | Invalid Origin header |
Host: evil.example:8000 (lab-l11) | 421 | (DNS-rebinding protection) |
The 403 is the spec's MUST. The 421 is extra SDK protection for loopback servers; the L11 lab also sets the allow-lists explicitly.
Legacy: what older clients send (interoperability)
Versions 2025-03-26 to 2025-11-25 used Streamable HTTP differently: Mcp-Session-Id sessions (ended with DELETE), a standalone GET stream, server requests on SSE streams, and Last-Event-ID resumption. A server supporting only 2026-07-28 SHOULD answer GET or DELETE with 405 and ignore Mcp-Session-Id and Last-Event-ID.
The labs' SDK is dual-era (an SDK compatibility layer): a request with no MCP-Protocol-Version header, or a handshake-era one, takes the legacy path on the same /mcp. Captured: a plain initialize POST got 200, text/event-stream, an mcp-session-id header and an SSE event: message with "protocolVersion":"2025-11-25". Modern requests on that endpoint stay stateless.
HTTP+SSE (2024-11-05) is deprecated since 2025-03-26: a GET stream announces a POST URL in an endpoint event. New implementations SHOULD NOT adopt it (Claude Code also marks its SSE transport deprecated). Clients detect it by a 400, 404 or 405 without a modern error body, then a GET that yields an endpoint event.
Choosing a transport
| Situation | Transport | Baseline |
|---|---|---|
| Local tool for one user, launched by the host | stdio | No port; credentials from the environment; logs to stderr |
| Local HTTP for development | Streamable HTTP on 127.0.0.1 | Origin and Host checks; never 0.0.0.0 |
| Shared or remote service | Streamable HTTP over HTTPS | Origin checks, OAuth 2.1 resource server (L13), rate limits |
Statelessness lets any instance serve any request, including an MRTR retry, without sticky sessions.
Practice task
In lab-l11, start the server with ./run.sh serve. In another terminal:
U=http://127.0.0.1:8000/mcp
H=(-H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28')
META='"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}'
# 1. valid tool call
curl -s -i $U "${H[@]}" -H 'Mcp-Method: tools/call' -H 'Mcp-Name: get_item' \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"get_item\",\"arguments\":{\"sku\":\"ELC-0002\"},$META}}"
# 2. header does not match body
curl -s -i $U "${H[@]}" -H 'Mcp-Method: tools/call' -H 'Mcp-Name: search_items' \
-d "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\",\"params\":{\"name\":\"get_item\",\"arguments\":{\"sku\":\"ELC-0002\"},$META}}"
# 3. GET stream, as a modern client, then with no version header (legacy path)
curl -s -i $U -H 'Accept: text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28' --max-time 3
curl -s -i $U -H 'Accept: text/event-stream' --max-time 3
# 4. foreign Origin
curl -s -i $U "${H[@]}" -H 'Origin: http://evil.example' -H 'Mcp-Method: server/discover' \
-d "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"server/discover\",\"params\":{$META}}"
Check your result: request 1 returns 200 with "isError":false and structuredContent for ELC-0002; request 2 returns 400 with code -32020; the first request 3 returns 405 (no standalone stream in 2026-07-28) and the second returns 400 "Missing session ID", because without a version header the dual-era SDK treats it as legacy traffic that lacks a session; request 4 returns 403.
Check your understanding
-
A user cancels a long tool call. What should the client do on stdio, and on Streamable HTTP? On stdio, send
notifications/cancelledwith therequestId, because all requests share one channel. On Streamable HTTP, close that request's SSE response stream; the server MUST treat the disconnect as cancellation and no notification is expected. -
A gateway routes on
Mcp-Namewhile the server executes the body. Why must the server reject a mismatch? Otherwise the gateway could apply one policy ("allowget_item") while the server runs another tool named in the body. Servers that process the body MUST reject mismatches with 400 and-32020. -
Your local HTTP server works from your host, so you bind it to
0.0.0.0to share it with a colleague. What is wrong? It exposes the server to your whole network with no authentication. Local servers SHOULD bind to127.0.0.1and SHOULD authenticate all connections. To share, deploy over HTTPS with OAuth (L13).
Sources
- Transports overview: https://modelcontextprotocol.io/specification/2026-07-28/basic/transports
- stdio: https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio
- Streamable HTTP: https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http
- Cancellation: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation
- Deprecated features: https://modelcontextprotocol.io/specification/2026-07-28/deprecated
- Base protocol (Auth section): https://modelcontextprotocol.io/specification/2026-07-28/basic
- Claude Code MCP docs (SSE deprecated): https://code.claude.com/docs/en/mcp
- Labs:
lab-l11/README.md,lab-l11/VERIFY-OUTPUT.txt,lab-l08/notes_server.py
