How MCP Works Under The Covers The 2026-07-28 version of the Model Context Protocol (MCP) specification makes MCP a stateless protocol, removing the initialize handshake and the Mcp-Session-Id header so any server instance can handle any request, according to developer Timmy Kokke's technical breakdown. Kokke writes that each request now carries the protocol version and client capabilities in its _meta field, which lets remote MCP servers run behind a plain load balancer without sticky sessions or a shared session store, and that the GET stream is replaced by a subscriptions/listen request. Kokke also notes that MCP requires OAuth 2.1, which applies only to the Streamable HTTP transport, and that a stray console.log to stdout can break a stdio connection. How MCP Works Under The Covers https://timmykokke.com/blog/2026/2026-12-03-how-mcp-works-under-the-covers/ Hello Coders πŸ‘Ύ At work I’m currently implementing MCP, the Model Context Protocol. I’ve used MCP servers for a while as a developer, so I thought I knew it pretty well. It turned out I only knew my own side of it. What actually happens inside the AI client? How does it find the tools, and how does the model decide to call one? And then there was OAuth. I didn’t know MCP needs OAuth 2.1 specifically, or what that means for my server. So in this post I want to look under the covers. Everything here is based on the 2026-07-28 version of the MCP specification https://modelcontextprotocol.io/specification/2026-07-28 . That version changed quite a lot, so older tutorials might show you things that are gone now. The big picture MCP gives AI applications one standard way to talk to tools and data. Before MCP, every AI app had its own plugin format. Now you build a server once and every client that speaks MCP can use it. There are three roles: - Host : the application the user works in, like an IDE, a chat app, or a coding agent. - Client : a component inside the host. It keeps one connection to one server. - Server : the program that offers tools, resources, and prompts. A host usually runs several clients, one per server. The model itself is not part of MCP at all. The host sends the conversation and the tool definitions to the model, and that is where MCP stops. php flowchart LR User User -- Host subgraph Host Host application C1 MCP client A C2 MCP client B end Host <-- "conversation + tool definitions" -- Model LLM C1 <-- stdio -- S1 Local MCP server C2 <-- Streamable HTTP -- S2 Remote MCP server Two ways to connect MCP has two standard transports. With stdio , the host starts the server as a child process. They send JSON-RPC messages over stdin and stdout, one message per line. The server can write logs to stderr, but only MCP messages may go to stdout. So one stray console.log can break the connection. With Streamable HTTP , the server has one endpoint, for example https://example.com/mcp . The client sends every message as an HTTP POST. The server answers with plain JSON or with a stream of server-sent events. Most of the interesting stuff, like OAuth, only applies to HTTP. A stateless protocol This is the biggest change in the 2026-07-28 spec. MCP is now stateless. Every request stands on its own, and the server doesn’t need to remember anything about the client between requests. Older versions started with an initialize request. The client and server exchanged versions and capabilities, and on HTTP the server gave back a session ID. Every next request had to carry that Mcp-Session-Id header. That handshake is gone, and so is the session ID. Instead, every request now carries the protocol version and the client capabilities in its meta field. So any server instance can handle any request. Why this matters With sessions, a remote MCP server was hard to scale. The session lived in the memory of one server instance. So you needed sticky sessions on the load balancer, or a shared store for the session state. Serverless hosting was also tricky, because a function can disappear between two requests. Now you can put a few instances behind a load balancer and it just works: php flowchart LR C MCP client -- LB Load balancer LB -- I1 Server instance 1 LB -- I2 Server instance 2 LB -- I3 Server instance 3 What else went away A few things depended on that session, so they changed too: - The GET stream is gone. Before, a client could keep a stream open to get messages from the server. For updates, like a changed tool list, the client now opens a subscriptions/listen request. - The server can’t send its own requests anymore. Before, a server could ask the client for input in the middle of a tool call. Now the server returns a result with resultType: "input required" . The client gets the input from the user and sends the call again, with the answers. - State is up to you. If a tool needs to remember something, like an open document or a game, it returns a handle. The model passes that handle back as an argument in the next call. Discovery and headers Every server must implement server/discover . It tells the client which protocol versions, capabilities, and identity the server has. On HTTP, a few values from the body are also copied into headers. That way a load balancer or gateway can route a request without parsing the JSON: - MCP-Protocol-Version on every POST - Mcp-Method on every request, for example tools/call - Mcp-Name on tools/call , resources/read , and prompts/get If a header and the body don’t match, the server must reject the request with a 400. A nice side effect is that the traffic is much easier to read in the network logs. Getting in with OAuth 2.1 I knew MCP servers on HTTP use OAuth. What I didn’t know is that MCP asks for OAuth 2.1 specifically. The authorization server must implement it, and the MCP server and client play the OAuth 2.1 roles. OAuth 2.1 is still a draft, but it bundles years of security best practices. For example, the authorization code flow uses PKCE. The tricky part is that the client has never seen your server before. So it has to discover everything by itself: sequenceDiagram participant C as MCP client participant S as MCP server participant A as Authorization server C- S: POST /mcp no token S-- C: 401 + where to find the metadata C- S: GET protected resource metadata S-- C: Which authorization server to use C- A: Log in the user PKCE, resource A-- C: Access token C- S: POST /mcp + Authorization: Bearer token The MCP server only checks tokens. It doesn’t hand them out. For that it points the client to an authorization server, with Protected Resource Metadata RFC 9728 https://datatracker.ietf.org/doc/html/rfc9728 . For the MCP server I’m building, these were the important requirements: - Publish the protected resource metadata, and point to it in the WWW-Authenticate header of a 401. - Check that each token was issued for this server. The client sends the server’s URL in the resource parameter, so the token has the right audience. - Never forward the token to another API. If the server calls other APIs, it needs its own tokens. - Return a 403 with insufficient scope when a token is missing a scope, so the client can ask for more. The client side has more work, like getting a client ID and checking the issuer. The authorization part of the spec https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization has all the details. How the client knows the tools Once connected, the client calls tools/list . The server returns every tool with a name, an optional title and description, and a JSON Schema for the input: { "name": "get high scores", "title": "Get high scores", "description": "Returns the top scores for one of my games. Use this when the user asks about scores or rankings.", "inputSchema": { "type": "object", "properties": { "game": { "type": "string", "description": "Slug of the game, for example rainbow-reboot" }, "limit": { "type": "integer", "minimum": 1, "maximum": 50 } }, "required": "game" } } The result also has ttlMs and cacheScope , so the client knows how long it can cache the list. The list can depend on the token. A user with fewer permissions can see fewer tools. When the tools change, the server can send notifications/tools/list changed . The client has to subscribe first with a subscriptions/listen request. Then it calls tools/list again. Tools aren’t the only thing a server can offer. Resources are data the host can read, like files or records. Prompts are templates the user can pick. Tools get the most attention, because they are what the model uses. How the model picks a tool This is the part that cleared up a lot for me. The model doesn’t run anything. It only produces text, and some of that text is a structured tool call. The host puts the tool definitions into the request to the model, next to the conversation. When the model thinks a tool helps, it returns the tool name and the arguments as JSON. The host then does the real work: sequenceDiagram actor U as User participant H as Host + MCP client participant M as LLM participant S as MCP server U- H: "What are the top 3 scores in Rainbow Reboot?" H- M: Conversation + tool definitions M-- H: Tool call: get high scores game, limit H- U: Ask permission if needed H- S: tools/call S-- H: Result content H- M: Conversation + tool result M-- H: Final answer H- U: "The top 3 scores are..." The tools/call request over HTTP looks like this: POST /mcp HTTP/1.1 Content-Type: application/json Accept: application/json, text/event-stream Authorization: Bearer eyJhbGciOi... MCP-Protocol-Version: 2026-07-28 Mcp-Method: tools/call Mcp-Name: get high scores { "jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": { "name": "get high scores", "arguments": { "game": "rainbow-reboot", "limit": 3 }, " meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {} } } } And the server answers with content blocks: { "jsonrpc": "2.0", "id": 7, "result": { "resultType": "complete", "content": { "type": "text", "text": "1. Sorskoot 9120\n2. Pixel 8740\n3. Neo 8015" } , "isError": false } } If the tool fails, the server still returns a result, with isError: true . The client gives that error to the model, so the model can try again or explain what went wrong. Because the model only sees the name, description, and schema, those are basically your user interface. A vague description means the model calls the wrong tool, or no tool at all. What is in the context It helps to picture what the model actually receives on every turn: - The system prompt of the host - The definitions of all available tools - The conversation so far - All earlier tool calls and their results Here is a shortened example of the high score question from above. The exact format differs per host and model, but the parts are the same: β”Œβ”€ SYSTEM PROMPT ─────────────────────────────────────────────┐ You are an AI assistant running in