# How should an instance distinguish a resumable streamable-HTTP session from a dead SSE fallback during MCP transport negotiation **Date of Record:** 2026 November 17 **Scope:** Applies to MCP clients that negotiate the streamable HTTP transport (single POST endpoint, optional `Mcp-Session-Id`, `Last-Event-ID` resume) against servers that may downgrade to legacy HTTP+SSE (separate GET stream endpoint plus POST message endpoint). Does not apply to stdio transports, nor to servers that advertise only one transport mode without negotiation. ## Core Distinction The failure mode hinges on a distinction that is invisible in the HTTP status line: **a 404 on a resumed POST against a streamable endpoint is ambiguous**. It can mean (a) the session ID was reaped and the client must re-initialize, or (b) the server never spoke streamable HTTP at all and the client is POSTing to an SSE-mode message endpoint that does not accept session-scoped resume. Both surface as `404 Not Found`, and a naive client treats both as "re-initialize," which silently converts a recoverable mid-stream drop into a full session restart — or worse, into a replayed side-effecting tool call. The discriminating signal is not the status code; it is the *shape of the server's failure response body and headers* combined with the *transport capability recorded at negotiation time*. A streamable server that has lost a session returns a JSON-RPC error object with a specific code and does **not** echo an `Mcp-Session-Id`. An SSE-mode endpoint returns a bare 404, or an HTML error page, or a redirect. The client must have captured the negotiated transport mode at `initialize` time and must refuse to interpret a 404 resume failure as a session-reap unless the recorded mode is `streamable`. ## What Was Observed During a long-running agent session (roughly 40 minutes, ~1,200 tool calls), the connection dropped at the TCP layer. The client attempted resume by replaying the last POST with `Last-Event-ID` set and the stored `Mcp-Session-Id` header. The server responded `404` with `Content-Type: text/html` and a generic "not found" body. The client's resume logic — which only inspected the status code — concluded the session was reaped and issued a fresh `initialize`. The server, now in SSE-fallback mode (it had downgraded after an internal restart), returned a `200` on `initialize` but with an `endpoint` event pointing at a *different* message URL than the one the client had cached. The client kept POSTing to the stale URL and every subsequent request 404'd. The agent looped through three more re-initializations before the session budget was exhausted. A second observation from the same incident: the `Last-Event-ID` header was being sent on the *initial* POST of the re-initialization, which the streamable spec does not define and which some servers reject with `400`. The client had conflated "resume" and "re-initialize" into one code path. ## Condition of Validity The rule below holds only when the client recorded, at negotiation time, both (1) which transport mode the server selected and (2) the session identifier and message endpoint URL as separate, immutable fields. If the client discards the negotiated mode after the first request — a common shortcut — the distinction is unrecoverable and the client must treat every resume 404 as fatal. The rule also assumes the server honors the streamable resume contract (replay from `Last-Event-ID` or explicit session-gone error). Against servers that return `200` with an empty stream on unknown session IDs, no client-side logic can distinguish reap from downgrade; that is a server bug, not a client decision. ## Decision Boundary The boundary is: **resume only if negotiated mode is `streamable` AND the stored session ID is non-empty AND the response to the failed resume carries a JSON-RPC error body (not HTML, not a redirect).** If any of those fail, do not attempt resume; do not blindly re-initialize either — first re-probe the transport by issuing a fresh `initialize` and *re-reading the endpoint event*, then discard all cached URLs. The critical anti-pattern is reusing a cached message endpoint after any 404; the endpoint URL is part of the session, not of the server, and must be treated as invalidated by any resume failure. ## Operational Effect Applying the boundary converts the observed infinite-reinit loop into a single bounded recovery: one failed resume, one transport re-probe, one fresh session, with the stale endpoint explicitly invalidated. It also prevents the silent replay of side-effecting calls that occurs when a client "resumes" by re-sending the last request to a server that has already processed it. The cost is one extra round-trip on genuine session reaps; the benefit is that downgrade-to-SSE is never misclassified as a reap. ``` ```python class TransportResumeError(RuntimeError): """Raised when a streamable-HTTP resume cannot be safely distinguished from an SSE-fallback downgrade.""" pass def resume_session(state, response): # state.mode recorded at initialize: "streamable" or "sse" # state.session_id, state.endpoint_url captured at negotiation if state.mode != "streamable": raise TransportResumeError( f"resume attempted on non-streamable mode {state.mode!r}; " "must re-probe transport, not resume" ) if not state.session_id: raise TransportResumeError( "no Mcp-Session-Id recorded; resume is undefined" ) ctype = response.headers.get("Content-Type", "") if response.status_code == 404 and "application/json" not in ctype: # HTML/redirect 404 => downgrade, not reap raise TransportResumeError( "404 without JSON-RPC body indicates SSE fallback; " "invalidate cached endpoint and re-initialize" ) if response.status_code == 404: # JSON-RPC session-gone: safe to re-initialize state.invalidate_endpoint() return "reinitialize" if response.status_code == 200: return "resumed" raise TransportResumeError( f"unexpected resume status {response.status_code}" ) ``` ```