Skip to content
mentoor

Topic 1 of 5 · 4 min read

Streamable HTTP requests, headers and streaming responses

Goal: Trace a Streamable HTTP exchange and find the missing header, Origin check or session assumption that breaks it.

Streamable HTTP puts the whole protocol behind one URL: every message is its own POST, the reply is either plain JSON or a stream for that one request, and the server remembers nothing between calls. That is the rule from protocol revision 2026-07-28, which removed the separate GET stream and protocol-level sessions.

Check yourself · 1 of 3

How many HTTP endpoints does a Streamable HTTP MCP server need to expose for the protocol itself?

Choose one answer

Why it matters

A remote server sits behind proxies, gateways and load balancers. Code that works on localhost often fails there because a header is missing, a proxy buffers the stream, or the server stored something in memory that the next request cannot find. Knowing what each request must carry tells you where to look.

How an exchange works

  1. One endpoint. The server exposes a single path such as https://example.com/mcp that accepts POST.
  2. Every message is a new POST. The client sends Accept: application/json, text/event-stream and one JSON-RPC request or notification as the body.
  3. Headers mirror the body so intermediaries can route without parsing JSON. MCP-Protocol-Version must equal the version in the body's _meta (a mismatch gets 400 with a HeaderMismatch error). Mcp-Method is required on all requests. Mcp-Name carries the tool, resource or prompt name on tools/call, resources/read and prompts/get.
  4. The reply has two shapes. A request gets either one JSON object or a Server-Sent Events (SSE) stream that carries progress notifications and then the final response. A notification gets 202 with no body. Closing the stream cancels the request.
  5. Origin check. The server must validate the Origin header and answer 403 when it is present and invalid. This blocks DNS rebinding. A local server should bind to 127.0.0.1, not 0.0.0.0.
  6. Server questions ride inside results. Sampling or elicitation comes back as an input-required result, and the client retries the request with the answers. Change notifications use a long-lived subscriptions/listen stream.

Before and after

A client written for an older revision:

POST /mcp HTTP/1.1
Content-Type: application/json
Mcp-Session-Id: 9f2c

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_weather"}}

It has no Accept list, no version or method headers, and relies on a session id. The fixed request:

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: get_weather

What goes wrong

  • The header and the body disagree on the version, and the gateway rejects every call.
  • A proxy buffers the SSE stream, so progress arrives all at once. The server should send X-Accel-Buffering: no.
  • The server keeps per-client state keyed by a session id, which no longer exists, and breaks when a second instance answers.

Examples

Version mismatch

A gateway log shows 400 HeaderMismatch on every call from one client. The header says MCP-Protocol-Version: 2025-11-25 while the body _meta says 2026-07-28. The client library set the header from a cached value. The fix is to build both from the same constant.

Buffered progress

A tool streams progress through SSE. In staging the client sees nothing for 40 seconds, then everything at once. The nginx in front buffers the response. Adding X-Accel-Buffering: no to the stream response, or turning buffering off for that location, restores live progress.

Key points

  • Every JSON-RPC message is its own POST to one MCP endpoint; since 2026-07-28 there is no GET stream and no protocol-level session.
  • Requests carry MCP-Protocol-Version, Mcp-Method and, for named operations, Mcp-Name, and the version header must match the body.
  • A request is answered with one JSON object or an SSE stream scoped to that request; closing the stream cancels it.
  • Servers must validate Origin (403 if present and invalid) and should bind local servers to 127.0.0.1.
  • State that used to hang off a session id must move into the request or into your own storage.

Common mistakes

  • Sending only the JSON body and forgetting the required headers.
  • Reading the Origin header as optional security and never checking it on a public server.
  • Keeping conversation state in server memory keyed by a session id.
  • Expecting a GET stream or Last-Event-ID resume, which this revision does not have.

Check yourself · 2 of 3

A POST with a tools/call body arrives with MCP-Protocol-Version 2026-07-28 in the header but 2025-11-25 in the body _meta. What must the server do?

Choose one answer

Check yourself · 3 of 3

A browser page on another site sends requests to your MCP server, and the Origin header is present but not on your allow list. What should the server return?

Choose one answer

Practice items, not counted towards your mastery.

Start here