MCP "Session terminated" / 404 "Session not found" after an idle break or a server restart

By MV2 of Munim, Inc., with AI agents. Written on 12 November 2026 from the source of the MCP Python SDK (v1.29.1, v1.30.0, v2.0.0 to v2.3.0), the TypeScript SDK (1.32.2 and main), the Rust SDK (main), Open WebUI v0.13.3 and the issues linked below. Read from the source, not run. See the limits.

An MCP client on the Streamable HTTP transport works, then every call fails with one of these:

mcp.shared.exceptions.McpError: Session terminated
Streamable HTTP error: Error POSTing to endpoint: {... "Session not found" ...}
MCP error -32001: Request timed out
HTTP 404 Not Found: Session not found

They are all the same event. The server no longer knows the client's Mcp-Session-Id and answers HTTP 404, as the MCP spec tells it to. The spec then says the client must start a new session (2025-11-25 transports, Session Management, rule 4). The official SDKs leave that step to the application, and many applications don't take it, so the old session ID is sent again and every call fails until the client is restarted.

Why the server forgot the session

CauseHow to recognise it
Idle expiry, new default since 7 September 2026. Python MCP SDK servers on mcp 2.2.0+ or 1.30.0+ close a stateful session that has had nothing in flight for 30 minutes (DEFAULT_SESSION_IDLE_TIMEOUT: Final = 30 * 60). Up to v2.1.1 and v1.29.1 the default was None, no expiry. Per the v2.2.0 release notes (PR #3395; #3426 on 1.x), clients that keep the GET stream open, such as the SDK's own Client, aren't affected.The first call after a gap of 30 minutes or more fails, and the reconnect or retry works. On v2.3.0 the server logs Session <id> idle timeout, then Rejected request with unknown or expired session ID: <id> (INFO).
Idle expiry in the Rust SDK (rmcp). LocalSessionManager's SessionConfig::keep_alive "Defaults to 5 minutes" (DEFAULT_KEEP_ALIVE = Duration::from_secs(300) on main, 12 November 2026). Per rust-sdk#689, older rmcp answered an unknown session with 401 instead of 404.Same pattern, after a 5-minute gap. This is the case in claude-code#83404 (rmcp 2.2.0 server).
Server restart or redeploy. The Python and TypeScript SDKs keep sessions in memory, so a restart forgets all of them.Every client fails at once, right after a deploy, a container restart or a crash.
Several replicas behind a load balancer. The session lives on one replica, and the next request lands on another (per higress#4788).Intermittent 404s from the first minutes of a session, with no idle gap.
The session was deleted (the client or a proxy sent DELETE).Fails after a tab, chat or proxy connection was closed.

The TypeScript SDK server (1.32.2) has no idle timeout. Its sessions end only on DELETE or close(). If you see this error against a TypeScript server, look at restarts and load balancing first.

Not this error: a 404 on the first request, before any session exists, means a wrong URL (often /mcp vs /mcp/, or a missing path). The Python client then says Not Found, not Session terminated: it only uses "Session terminated" when it already holds a session ID.

What each server sends

ServerUnknown or expired sessionIdle defaultSession cap
Python mcp 2.2.0 to 2.3.0, 1.30.0404, JSON-RPC error (no id), code INVALID_REQUEST, message Session not found. A known session presented with a different credential gets the same answer.30 min (session_idle_timeout)10,000 (max_sessions); per the release notes, new sessions beyond it get 503
Python mcp 2.0.0 to 2.1.1, 1.29.1same 404 Session not found (message checked on 2.0.0)none (None; the docstring recommends 1800)none
TypeScript SDK 1.32.2404, code -32001, Session not foundnonenone
Rust SDK (rmcp), main404 Session not found (per claude-code#83404 for 2.2.0)5 min (keep_alive)not checked
FastMCP 4.0.5 on mcp 2.2.0(uses the Python SDK)None unless you set it, per fastmcp#5210the SDK's 10,000. With no expiry, abandoned sessions fill it and new clients get HTTP 503 {"error":{"code":-32603,"message":"Too many open sessions"}} (#5210, closed 5 October 2026)

What each client prints, and whether it recovers

ClientWhat you seeRe-initializes by itself?
MCP Python SDK 2.x client (v2.3.0)An error with message Session terminated, code INVALID_REQUEST. Per a traceback in agent-framework#10161: MCPError(-32600, 'Session terminated', None). The server's own body is thrown away.No. session_id is never reset after it is set, so every later call gets the same 404. python-sdk#3799 asks for a distinct error type.
MCP Python SDK 1.30.0 clientMcpError: Session terminated, with code 32600: a positive literal in the source, not -32600. Match on the message, not the code.No.
TypeScript SDK 1.32.2 clientStreamableHTTPError, code 404, message Streamable HTTP error: Error POSTing to endpoint: followed by the server's body (which says Session not found).No. _sessionId is only cleared by terminateSession().
TypeScript SDK main (12 November 2026, after v2.4.0)SdkHttpError with Error POSTing to endpoint: …, status in the details.No automatic retry. A new initialize strips the old ID and a sessionless handshake clears it, so reconnecting is enough.
Claude CodeOn 2.1.220: MCP error -32001: Request timed out, and the call was never run (#83404).Per the maintainer's reply, the client re-initializes and replays the call on v2.1.233; it couldn't be reproduced there (closed 25 August 2026). Update.
Hermes AgentSession terminatedYes, since PR #19380 (merged 3 May 2026).
mcp-proxy (sparfenyuk)Old session reused after a backend restart (#149)Fixed on its main branch by PR #241 (merged 2 November 2026), "recover lost upstream sessions without replaying operations". We didn't check which release includes it.
mcpo (Open WebUI's MCP-to-OpenAPI proxy)mcp.shared.exceptions.McpError: Session terminated, returned to the caller as HTTP 500No. The fix, PR #310, has been open since 4 September 2026. Restart mcpo.
Microsoft Agent Framework (Python)ToolExecutionException: ('Session terminated', MCPError(-32600, 'Session terminated', None))Tool calls do; get_prompt and tool/prompt discovery don't (#10161, open).
BeeAI FrameworkSession terminated on every call after a server restartNo (#1889, open).
Open WebUI v0.13.3 (native MCP tool servers)—Builds new MCP connections for each chat request (mcp_clients = {} in utils/middleware.py), so a session that went idle between messages isn't reused. A session lost in the middle of a request is logged as Lost connection to MCP server '…' with no retry. Read from the source, not tested.

"-32001: Request timed out" can hide a 404. In the TypeScript SDK, -32001 is ErrorCode.RequestTimeout, and it is also the code the TypeScript SDK server puts on its own Session not found answer. If a "timeout" comes back in milliseconds, and always after an idle gap, check the server log for a 404 before raising any timeout (see the initialize-timeout page for real timeouts).

Fixes on the server

  1. Make the idle window longer than your users' gaps. Python mcp 2.2.0+: mcp.run(transport="streamable-http", session_idle_timeout=4 * 3600) (also on streamable_http_app() and run_streamable_http_async()). mcp 1.30.0: FastMCP(..., session_idle_timeout=...). rmcp: set keep_alive on the SessionConfig of your LocalSessionManager.
  2. Turning expiry off (session_idle_timeout=None) brings back the old behaviour, but sessions that are abandoned without a DELETE then stay until restart. With the SDK's 10,000-session cap still on, that ends in the 503 Too many open sessions of fastmcp#5210. Set both or neither: the release notes' way to turn both off is session_idle_timeout=None, max_sessions=None. A long timeout is usually the better choice.
  3. Go stateless if the server never needs to send requests to the client (sampling, elicitation). A stateless server issues no session ID, so there is nothing to expire, lose on restart or route to the wrong replica. In the Python SDK's stateless mode, server-to-client requests raise NoBackChannelError; notifications still work. In rmcp, one project did it with NeverSessionManager and stateful_mode = false (openab#1578).
  4. Several replicas: route by the Mcp-Session-Id header (sticky sessions), or go stateless.
  5. Restarts always drop in-memory sessions. Only clients that re-initialize recover, so check the table above for the clients your users run.

Fixes in a client you write

Do what the spec says: on a 404 to a request that carried a session ID, drop the session, send a fresh initialize without the old ID, and then decide whether to retry.

How this was made, and its limits

AI agents working for MV2 of Munim, Inc. read the files named above at the tags named above (mcp/client/streamable_http.py, mcp/server/streamable_http_manager.py, the TypeScript SDK's streamableHttp.ts, webStandardStreamableHttp.ts and types.ts, rmcp's session/local.rs, Open WebUI's utils/mcp/client.py and utils/middleware.py), plus the release notes and issues linked above, on 12 November 2026. Limits:

Corrections are welcome as issues at github.com/munimtechnologies/local-ai-checkup.

Related

Check the rest of your setup

The free local-ai-checkup script shows which AI ports on your machine other computers can reach. The CVE checker tells you which security advisories affect your Open WebUI or Ollama version. Both are read-only and send nothing off the machine.

Want someone to check it for you?

MV2 of Munim, Inc. does a $49 local AI health check for one machine, or a $199 small-office check for up to 5 machines or one shared Ollama, vLLM or Open WebUI server. You get a written report of what's exposed, risky or slow and what to fix first, with exact commands for your OS. See a sample report. Pay $49 or pay $199 on Stripe, then email mv2@munimtech.com the output of python3 local_ai_checkup.py --json, your OS, and what you use it for. MV2 never asks for passwords, keys or remote access.