Fix guide · updated 2026-11-19
MCP server "Session not found" (404) after initialize
Streamable HTTP error: Error POSTing to endpoint: {"jsonrpc":"2.0","error":{"code":-32001,"message":"Session not found"},"id":null}
Your MCP server connects, then the next request fails with HTTP 404 and Session not found. Often not every time: the tools load once, fail the next time, work again. That pattern almost always means your server runs as more than one copy and keeps each session in the memory of the copy that created it. We reproduced it with the official TypeScript SDK (1.29) and read the code of the current SDKs (TypeScript 1.32.2, Python 1.30.0 and 2.3.0, November 2026). Here's how to confirm it in one minute, and the three ways to fix it.
What the error looks like
Clients built on the TypeScript SDK show the server's answer inside their own message:
Streamable HTTP error: Error POSTing to endpoint: {"jsonrpc":"2.0","error":{"code":-32001,"message":"Session not found"},"id":null}
The server's part tells you what it's built with:
- TypeScript SDK: code
-32001, as above. - Python SDK: code
-32600. Version 1.x also sends"id":"server-error", version 2.x"id":null.
Servers copied from the TypeScript SDK's examples answer 400 with Bad Request: No valid session ID provided instead. Same cause, same fixes.
Why it happens
A Streamable HTTP server that uses sessions gives each client a session ID, in the Mcp-Session-Id header of its answer to initialize. The client sends that ID with every request after that. Both SDKs keep the session itself in the memory of the process that answered initialize: a plain map in the TypeScript examples, a dictionary in the Python SDK's session manager. No other process has ever heard of it, so when a request lands on another one, the answer is 404 Session not found. That's the answer the MCP spec asks for when a server doesn't have the session.
"More than one process" is easy to have without knowing it:
- more than one replica or instance on your host (Railway, Render, Fly, Kubernetes, ECS), or autoscaling that adds copies under load;
- serverless functions (Vercel, AWS Lambda, Cloud Run, Netlify), where each request can reach a different instance;
- several worker processes on one machine:
uvicorn --workers 4,gunicorn -w 4, PM2 cluster mode or Node'sclustermodule; - a restart or a redeploy, which empties the memory of the only copy you have. Scale-to-zero does the same every time the server goes to sleep.
With two copies taking turns, about half of the requests after initialize fail; with four, about three in four. With several workers on one machine, a client that reuses its connection stays on one worker until that connection closes, so it can work for a while and then fail. That's why it looks random.
In our test (TypeScript SDK 1.29, Node 24), two copies of the same server sat behind a proxy that alternates between them. With sessions in memory, 25 of 50 tools/list calls failed with 404 Session not found, every notifications/initialized failed too, and the SDK's own client stopped with the error above. Our test server answers an unknown session with 404, as the spec asks. The same two copies in stateless mode: 0 failures out of 50. With sessions kept, but the proxy sending each session back to the copy that created it: 0 out of 50.
Check it in one minute
Run this with your server's address. It starts one session, then sends the same request ten times with it:
URL="https://your-server.example.com/mcp"
SID=$(curl -s -o /dev/null -D - "$URL" \
-H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}' \
| tr -d '\r' | awk 'tolower($1)=="mcp-session-id:"{print $2}')
echo "Session: $SID"
curl -s -o /dev/null "$URL" -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
-H "Mcp-Session-Id: $SID" -H "MCP-Protocol-Version: 2025-11-25" \
-d '{"jsonrpc":"2.0","method":"notifications/initialized"}'
for i in 1 2 3 4 5 6 7 8 9 10; do
curl -s -o /dev/null -w "%{http_code} " "$URL" \
-H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
-H "Mcp-Session-Id: $SID" -H "MCP-Protocol-Version: 2025-11-25" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
done; echo
200ten times: sessions survive, so your problem is elsewhere (see the end of this page).- A mix of
200and404: more than one copy. Pick a fix below. 404every time: many copies (typical on serverless), or a server that forgets the session at once. Same fixes.Session:is empty: your server doesn't use sessions, and this page isn't your problem.
If your server needs a token, add -H "Authorization: Bearer YOUR_TOKEN" to each curl. On a Python server (SDK 2.x), the copy that refused a request logs Rejected request with unknown or expired session ID at INFO level.
Fix 1: make the server stateless
This is the right fix for most servers. If your tools take arguments and return a result, they don't need a session, and any copy can answer any request.
TypeScript SDK: create the server and the transport inside the handler, for every request, with sessionIdGenerator: undefined. That's what the SDK's own stateless example does:
app.post('/mcp', async (req, res) => {
const server = buildServer(); // your McpServer, with its tools
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
res.on('close', () => { transport.close(); server.close(); });
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
});
// No sessions means nothing to stream or delete: answer GET and DELETE with 405.
app.get('/mcp', (req, res) => res.status(405).end());
app.delete('/mcp', (req, res) => res.status(405).end());
Python SDK 1.x (FastMCP):
mcp = FastMCP("my-server", stateless_http=True)
Python SDK 2.x (MCPServer, the new name of FastMCP): pass it where you start the server.
app = mcp.streamable_http_app(stateless_http=True) # mounted in FastAPI or Starlette
mcp.run(transport="streamable-http", stateless_http=True) # or running on its own
What you give up: everything that needs the server to remember the client between two requests. That's the server asking the client something (sampling, elicitation), change notifications, resource subscriptions, and resuming a dropped stream. If a tool depends on one of them, use fix 2 or 3.
Fix 2: run a single copy
If you need sessions, run exactly one process: one replica or instance on your host, uvicorn without --workers (or gunicorn -w 1), no PM2 cluster mode. A small MCP server rarely needs more. Serverless platforms can't promise one instance, so there, use fix 1.
Restarts still forget every session. The spec tells clients to start a new session when they get a 404, but the TypeScript SDK's client (1.32.2) doesn't do it by itself: it throws the error above, and the user has to reconnect. Answer an unknown session with 404, never 400 or 500, so the clients that do follow the spec recover on their own.
Fix 3: send each session back to the copy that created it
With several copies and sessions, the load balancer has to remember which copy answered initialize (the Mcp-Session-Id in its response) and send every request with that ID to the same copy. Two traps:
- Hashing the header isn't enough.
initializehas no session ID yet, so it lands on any copy, and a hash of the ID can point to a different copy than the one that created it. - Cookie stickiness isn't reliable: not every client keeps cookies, and the TypeScript SDK's client doesn't.
The session still dies when its copy restarts or the balancer scales it away, so the 404 advice from fix 2 applies here too.
After the fix
Run the check again: you should get ten 200s. Directories that test servers, like mcptry, see the fix at their next check.
Give your AI tool this prompt:
My MCP server (Streamable HTTP) answers initialize, but later requests sometimes fail with HTTP 404 "Session not found". It keeps sessions in memory and runs as more than one copy (replicas, serverless instances or worker processes). Make it stateless. With the TypeScript SDK: create a new McpServer and a new StreamableHTTPServerTransport with sessionIdGenerator: undefined for each request, close both when the response closes, and answer GET and DELETE on the MCP route with 405. With the Python SDK 1.x: FastMCP(..., stateless_http=True). With 2.x: pass stateless_http=True to streamable_http_app() or run(). Keep every tool, its name, description and behaviour exactly the same. If a tool uses sampling, elicitation, notifications or subscriptions, stop and tell me instead of changing it. Don't change anything else.
Not quite your error?
400 Bad Request: Mcp-Session-Id header is required: the client didn't send the session ID back. Behind a proxy, check that it passes the header through. For a client that runs in a browser, your CORS settings must listMcp-Session-IdinAccess-Control-Expose-Headers, or the browser hides the header from it.400 Bad Request: Server not initialized(TypeScript SDK): the request reached a transport that never answered aninitialize. Most often the code creates a new transport with asessionIdGeneratorfor every request. Keep a map of transports by session ID, or go stateless (fix 1).400 Invalid Request: Server already initialized(TypeScript SDK): one transport is shared by every client, so the second client'sinitializeis refused. Create one transport per session, or go stateless.- A
404oninitializeitself, or your website's HTML at the MCP address: the route moved or disappeared in a deploy. That's not a session problem. Our MCP Rescue page lists the other ways servers fail.
Still stuck?
Look at when it started. If the 404s began right after a deploy and stop once clients reconnect, it's restarts: answer 404 and let clients start over (fix 2). If they never stop, count your copies in three places: the hosting dashboard (replicas, instances, autoscaling), the start command (--workers, -w), and your process manager. One of them says more than one.