The authorization layer is covered in building a remote MCP server with OAuth 2.1; this post is about what happens in MCP Streamable HTTP after the token is checked.
What stateless means in Streamable HTTP
Streamable HTTP is one endpoint that accepts POST. Every JSON-RPC request or notification is its own HTTP request. The server answers a request with either one JSON object or an SSE stream scoped to that request; there is no long-lived connection that belongs to the client.
That is different from a session-oriented server. Under the 2025-11-25 revision, a server could mint an MCP-Session-Id during initialize, require it on every later request and terminate it with DELETE. The session was optional, but many servers used it because it made per-connection state easy. The 2026-07-28 revision removed the mechanism: no session IDs, no GET stream, no resumability via Last-Event-ID.
The practical consequence is that a request must carry everything the server needs. Identity comes from the bearer token, account scope comes from the token or the API key, and any multi-step workflow has to pass a handle rather than rely on the server remembering the previous call.
Why stateless survives replicas
A stateful MCP server needs sticky routing. If the session lives in one process’s memory, a load balancer that sends the next request to another replica breaks the conversation. Sticky sessions work until a replica restarts, and then the client has to reinitialize in the middle of a task.
A stateless handler has no such failure mode. Each POST constructs a server and a transport, runs the request, and tears both down. Any replica can serve any request because no request depends on a previous one. Restarts are invisible, and horizontal scaling is a matter of adding processes rather than pinning clients to them.
The teardown detail matters more than it sounds. A long-lived SSE transport holds a keep-alive interval for the life of the connection. If the transport is created per request and not disposed, those intervals accumulate until the process is doing nothing but keeping dead streams warm. The rank tracker’s configuration avoids the problem by never creating a long-lived transport in the first place.
There is a second, less obvious benefit: no in-process dispatch hop. The MCP tools call the same /v1 handlers the public API uses, either directly through a client that dispatches in process or over HTTP when an internal API URL is configured. Scopes, Redis rate limits, monthly quotas, test-mode accounts, credit holds and audit rows all behave the same because there is only one implementation behind both.
stdio versus Streamable HTTP
| stdio | Streamable HTTP | |
|---|---|---|
| Process model | Client launches the server as a child process | Server runs independently |
| Transport | Newline-delimited JSON-RPC on stdin and stdout | One POST per message; JSON or request-scoped SSE |
| Identity | Environment variables, usually an API key | Bearer token, OAuth access token or API key |
| State | Process memory for the life of the session | None; explicit handles only |
| Scaling | One process per client | Any replica, no sticky sessions |
| Best for | Local editors, scripts, single-user tools | Hosted connectors, multiple users, web clients |
Which should you choose? Use stdio when the tool runs on the same machine as the caller and the credentials can live in its environment. Use Streamable HTTP when more than one person or client reaches the service, when the service already has an account model, or when you cannot ask a user to install a process. Running both is reasonable: the same tool definitions can serve a local package and a hosted endpoint.
The handler
The whole server fits in a route handler. The context factory is the only place that knows how a request becomes an account.
export const POST = (request: Request) =>
handleMcpHttp(request, {
ctxFactory: () => buildAccountScopedContext(request),
});
Inside the handler, the transport is built per request and given no session generator. JSON responses keep the common case simple; a tool that needs to stream can still return an SSE response for that request.
const transport = new WebStandardStreamableHTTPServerTransport({
sessionIdGenerator: undefined,
enableJsonResponse: true,
});
const server = buildMcpServer(ctx);
await server.connect(transport);
return transport.handleRequest(request);
Two rules keep this honest. The handler must never read state left by a previous request, and the context factory must never assume a session exists. If a tool needs the account, it reads it from the context; if it needs a workflow, it takes a handle.
Auth without a session
Every request is authenticated on its own. The MCP endpoint accepts an OAuth access token or a platform API key as a Bearer header. The token resolves to an account, scope set and client identity, and the tool wrapper checks the scope for the specific tool being called.
That per-request check is simpler than it looks in a session model. There is no “logged in” state to expire mid-conversation, and no need to revalidate a cookie on a stream that has been open for an hour. A revoked token stops working on the next request because the next request is the only thing that exists.
The property that needs care is scope discovery. The protected-resource metadata advertises the default scopes so a client requests them automatically, while the authorization-server metadata also advertises the optional write scopes. Billing and admin scopes are never advertised. Getting that list wrong produces a client that connects with fewer permissions than the user intended and no obvious reason why.
What you give up
Statelessness is not free. Four things are harder or unavailable, and each has a workaround.
- No server-initiated messages on a standing stream. A stateless server cannot push a notification to a client that is not making a request. Long-lived change notifications need a
subscriptions/listenrequest in the 2026-07-28 revision, or the client polls. - No resumability. A dropped stream cannot be resumed from an event ID because there is no stream to resume. A retry is a new request.
- No implicit multi-step state. A tool that opens a browser context, a cart or a transaction must return a handle and accept it back. The handle is an ordinary string in a result and an ordinary argument on the next call.
- No progress across calls. Progress notifications belong to the request that is running. A long job needs a job ID and a status tool, not a stream that stays open.
The workaround for the last two is the same pattern: make the job a resource. check_rank returns a lookup ID, get_lookup reads it, and a webhook fires when it finishes. The client does not need the server to remember anything, because the ID is the memory.
What broke and what we changed
The 2026-07-28 revision removed protocol-level sessions and the standalone GET stream. That breaks the session model directly: a server built on the previous revision mints a session ID at initialize, and a client that lands on a different replica on its next request gets a 404 for a session that replica never had, with no way to recover except reinitializing mid-task.
This endpoint did not have to change shape, because it never minted a session. Three things were pinned so it stays that way:
- No session generator.
sessionIdGenerator: undefinedmakes it impossible to depend on a session by accident. There is no ID to store, so a missing session cannot present as a protocol error. GETreturns 405. The specification allows a server to decline the standalone stream, and a clear 405 is better than an idle connection. Clients that support the previous revision skip the stream when they see it, and the decision log records that as the reason.- State lives in handles. A tool that needs to remember something returns an ID and accepts it back. That is not a workaround for stateless transport; it is what the current tools specification tells servers to do, because the protocol has no session to hang state on.
The one part that needed real work was scope advertisement. The protected-resource metadata lists the default scopes so a client requests them automatically, while the authorization-server metadata also lists the optional write scopes. Billing and admin scopes are never advertised. Get that list wrong and the connector connects with fewer permissions than the user intended, with no error until the first write call fails.
Related
Frequently asked questions
Is Streamable HTTP stateful or stateless?
It can be either, but the current revision is stateless by default. The 2026-07-28 specification removed protocol-level sessions and the GET stream, so a server that follows it treats every POST as a complete request. Earlier revisions allowed an MCP-Session-Id, and servers that need to support older clients may still handle one.
Why does GET return 405 on an MCP endpoint?
Because there is no standalone server-to-client stream to open. The specification says a server must either return an SSE stream for GET or answer 405. A 405 is explicit: the client knows not to wait for push messages and can fall back to polling or a subscription request.
Do MCP servers need sticky sessions?
Only if they keep per-connection state. A stateless server does not, which is the main reason to build one: any replica can serve any request, restarts are invisible, and scaling does not require a load balancer that understands MCP. It also means a replica can restart mid-conversation without the client noticing.
How do you keep state across MCP tool calls?
Return an explicit handle from the tool that creates the state and accept that handle as an argument on later calls. The protocol has no session concept, so a handle is just a string in a result. It can be a database ID, a job ID or an opaque token; what matters is that the client passes it back.
Can a stateless MCP server send progress updates?
Yes, for the duration of one request. The server can return an SSE response scoped to that request and send progress notifications on it. It cannot send an update after the response ends, so long-running work should return a job ID and expose a status tool.
Does stateless mean no authentication state?
No. Every request is authenticated, which is stronger than caching a session. The token is verified per request and its scopes are checked per tool. There is no logged-in state to expire and no session store to breach. A revoked token fails on the next call because there is no cached login to keep alive.
How do you test a stateless MCP server?
Send the same request twice to two different processes and assert identical results. Then send a request with no prior initialize and assert it still works. If either test fails, something is holding state that the next request cannot see.
