Transports and the HTTP Header Contract
A transport does not change what a message means, only how it travels: stdio hands a JSON-RPC line to a subprocess, and Streamable HTTP posts one message at a time while mirroring a few of its fields into headers a gateway can read without touching the body. Frame and parse newline-delimited JSON-RPC messages the way the stdio transport requires, and explain why an embedded newline breaks that framing. Describe the Streamable HTTP request and response shapes: one POST per message, a JSON object or a per-request SSE stream, 202 Accepted for an accepted notification, and no GET endpoint. Build and validate the required HTTP headers, MCP-Protocol-Version, Mcp-Method, and Mcp-Name, and mirror a tool argument through x-mcp-header with the base64 sentinel encoding. Explain why Origin validation and localhost binding defend against DNS rebinding, and what a modern server returns for GET, DELETE, and a disallowed Origin. Tell a HeaderMismatch (-32020) protocol error apart from the plain HTTP status codes a transport returns for outcomes that never become a JSON-RPC message. Every MCP message already carries everything it needs to be understood: a method, parameters, and per-request metadata in meta. Nothing about that content depends on how the bytes travel between a client and a server. But something still has to carry those bytes, frame one message off from the next, tell…
Transports and the HTTP Header Contract: A transport does not change what a message means, only how it travels: stdio hands a JSON-RPC line to a subprocess,…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.