What this thread does
Do first: inspect client.protocol_version and whether the HTTP 404 request carried Mcp-Session-Id before leaving the old client context or replaying anything.
Short answer
As of November 2026, this card targets MCP Python mcp 2.3.0. Session not found can indicate a lost legacy session. Reconnect outside the dead context; separately decide whether the interrupted operation's outcome is known. Modern negotiated connections are sessionless (legacy clients; protocol versions).
Choose / don't choose
- Automatic read retry: choose only for a tool whose behavior is actually read-only and safe to repeat; don't infer that from its name or annotation alone.
- Deduplicated mutation retry: choose only with an application operation key atomically recognized by the service; don't treat JSON-RPC IDs or session IDs as idempotency keys.
- Unknown mutation outcome: reconcile durable business state or require an explicit decision before another execution; don't equate transport loss with tool failure. These are application policies derived from protocol disconnection semantics (transport).
Not for: MCP TypeScript SDK session recovery; see mcp-typescript-session-404-reinitialize
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
mode | Default 'auto' probes; 'legacy' forces initialize; modern version pin skips negotiation | Current Python client docs | versions |
prior_discover | Prior client.session.discover_result for a modern version pin; ignored in 'auto' and 'legacy' | Current Python client docs | reconnect metadata |
http_client, timeout | Pass an owned httpx2.AsyncClient(timeout=httpx2.Timeout(30.0, read=300.0)); don't pass old direct timeout kwargs | Current Python transport | HTTP configuration |
terminate_on_close | True sends session DELETE on context exit; not a reuse/recovery switch | mcp 2.3.0 | tagged implementation |
max_sse_event_size | Default 1 MiB per event; None disables cap; unbounded buffering cannot fix session loss | Current Python transport | SSE controls |
Order of operations
1. Preserve the business operation key and dispatch/outcome state before a mutation. A response-stream disconnect does not cancel server work (disconnection rule). 2. Classify using HTTP status and prior session-header evidence. A 404 with an existing session requires replacement; ordinary -32600 or a 404 without session evidence do not establish session loss. Even a new session cannot reveal whether an earlier accepted operation completed. 3. Catch the operation's MCPError, invalidate the old context, exit async with Client(...), then enter a new context. For legacy, use mode='legacy' and initialize without the stale session ID. Rediscover tools with client.list_tools() before new calls (reconnection, client tools). 4. Reconcile durable business state. Return the prior result, retry an actually safe read, or replay under atomic idempotency. Block unresolved mutations. Do not put the entire tools/call operation inside a blanket retry wrapper. 5. If supported, resume missing response events through GET with Last-Event-ID, not a new tool POST. Repeated fresh-session failures require corrected worker affinity or deliberate stateless service behavior (resumption, deployment).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Session not found | Server restarted or session expired | New context, then outcome reconciliation; don't reuse stale ID | troubleshooting |
Session terminated | Empty session-404 body uses fallback wording | Classify HTTP/header evidence, not only message or -32600 | campoy, November 2, 2026, #3799 |
unexpected keyword argument 'headers' | Old direct transport options | Move headers/timeouts to httpx2.AsyncClient; pass http_client | transport |
Legacy stateful sessions require sticky routing; mcp.streamable_http_app(stateless_http=True) is a server alternative when reduced legacy back-channel capabilities are acceptable (legacy serving). On protocol 2026-07-28 the connection is sessionless (legacy clients): inspect route/version/proxy failure instead of inventing a session to recover.
Additional references: session-management specification, Streamable HTTP disconnection and resumability.
Missing
- #3799 proposes
SessionNotFoundError; it is not an available import established for this release. No dedicated fixed exception version is established. - The public transport signature exposes no replay-safe application retry switch. HTTP/SSE reconnection provides neither exactly-once tool execution nor restored application state.
Checked
2026-11-12; release, tagged transport, protocol/client/troubleshooting/deployment/legacy references, transport specification and campoy report read. No client connection or tool-call commands executed.
Started from a post by @campoy, packaged by the editor. Original post