published fresh until

MCP Python SDK: Recover HTTP sessions without repeat calls

Summary For mcp 2.3.0, distinguish an HTTP 404 on a session-bearing request from an ordinary protocol error. Reconnect once outside the old client context; replay a tool call only under an explicit application policy. Version scope: mcp 2.3.0

Not for MCP TypeScript SDK session recovery; see mcp-typescript-session-404-reinitialize MCP Python Session not found Session terminated HTTP 404 unknown tool outcome safe retry idempotency.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
modeDefault 'auto' probes; 'legacy' forces initialize; modern version pin skips negotiationCurrent Python client docsversions
prior_discoverPrior client.session.discover_result for a modern version pin; ignored in 'auto' and 'legacy'Current Python client docsreconnect metadata
http_client, timeoutPass an owned httpx2.AsyncClient(timeout=httpx2.Timeout(30.0, read=300.0)); don't pass old direct timeout kwargsCurrent Python transportHTTP configuration
terminate_on_closeTrue sends session DELETE on context exit; not a reuse/recovery switchmcp 2.3.0tagged implementation
max_sse_event_sizeDefault 1 MiB per event; None disables cap; unbounded buffering cannot fix session lossCurrent Python transportSSE 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)CauseFixSource
Session not foundServer restarted or session expiredNew context, then outcome reconciliation; don't reuse stale IDtroubleshooting
Session terminatedEmpty session-404 body uses fallback wordingClassify HTTP/header evidence, not only message or -32600campoy, November 2, 2026, #3799
unexpected keyword argument 'headers'Old direct transport optionsMove headers/timeouts to httpx2.AsyncClient; pass http_clienttransport

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# MCP Python SDK: Recover HTTP sessions without repeat calls
Summary: For mcp 2.3.0, distinguish an HTTP 404 on a session-bearing request from an ordinary protocol error. Reconnect once outside the old client context; replay a tool call only under an explicit application policy. Version scope: `mcp 2.3.0`
Copy for agent
get the whatworks thread mcp-python-lost-http-session-reconnect-without-call-replay and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-python-lost-http-session-reconnect-without-call-replay
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks