# Under what conditions must an instance treat MCP streamable-HTTP SSE resumption as unsafe after a session-ID reissue, and how to bound the failure **Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients and servers using the HTTP-native "streamable HTTP" transport, where a POST returns `text/event-stream` and event IDs drive `Last-Event-ID` resumption against a `Mcp-Session-Id`. Does not apply to stdio transports, to legacy HTTP+SSE dual-endpoint transports, or to servers that never emit `id:` fields on SSE frames. ## Core Distinction The failure is not "the stream dropped." A dropped stream is recoverable by design: the client reconnects with `Last-Event-ID` and the server replays from its event log. The boundary condition is subtler: **a reconnect can succeed at the HTTP layer while silently attaching the resumption to a different logical session than the one that produced the events.** This happens when the server, under load or after a rolling restart, issues a *new* `Mcp-Session-Id` in the response header of the resumption POST (or the client's stale session ID is silently re-bound to a fresh event-log namespace) while still honoring the supplied `Last-Event-ID` as a *positional cursor* into that new namespace. The client sees `200 OK`, a well-formed `text/event-stream`, and frames whose IDs are numerically ≥ the requested `Last-Event-ID` — all the surface signals of a correct resume. What it does *not* see is that the events behind those IDs belong to a different tool-call lineage. The replay is well-formed and wrong. This is distinct from a plain 404/410 (session expired, client must re-initialize) because the transport layer reports success. It is distinct from event-log truncation (server replays from the oldest retained event, client can detect a gap because IDs skip) because here IDs are contiguous and plausible. The invariant that breaks is: *an event ID is only meaningful as a cursor within the session namespace that issued it.* ## What Was Observed A stateless tool-invocation agent issued a `tools/call` over streamable HTTP. The POST body carried the request; the server responded `202`-style with an SSE stream carrying progress notifications and finally the `tools/call` result, each frame tagged with a monotonic `id:`. Mid-stream, the TCP connection was severed by an intermediate proxy idle-timeout (the tool was a long-running retrieval, ~90s of silence between progress frames). The agent's transport layer did what the spec invites: it reconnected, replaying `Last-Event-ID: 41` and the stored `Mcp-Session-Id: sess-7f3a`. The server had, in the intervening seconds, been recycled by its orchestrator; the new process had no memory of `sess-7f3a`, allocated `sess-b91c`, and — critically — its event-log implementation was a per-process monotonic counter that *also* started fresh, but the server's resumption handler interpreted the incoming `Last-Event-ID: 41` as "skip the first 41 events in my log" rather than "replay event 41 onward." Because the new process had already emitted 44 events for *other* concurrent sessions before this reconnect landed, the handler skipped 41 of them and began streaming from event 42 — which belonged to an unrelated session's tool call. The agent received, in order: a progress notification for a different tool, a partial result fragment, and a `tools/call` result payload for a query it had never issued. It had no way to distinguish this from a legitimate resume, because: - HTTP status was `200`. - `Content-Type: text/event-stream` was correct. - Frame IDs were strictly increasing and ≥ 41. - The session ID in the response header (`sess-b91c`) differed from the request, but the client's resumption logic treated the response session header as advisory on a resume path (it had already "established" a session). The agent merged the foreign result into its working state. The error compounded: subsequent reasoning steps treated the foreign payload as the answer to its own query, and a downstream verification agent — receiving the same corrupted state via a baton pass — confirmed it, because the payload was internally consistent. ## Condition of Validity The unsafe-resume window is open exactly when all of the following hold simultaneously: 1. The transport permits resumption via `Last-Event-ID` (server advertises or accepts it). 2. The server's event-ID space is **not** globally unique and session-scoped — i.e., IDs are per-process counters, per-connection counters, or bare integers rather than opaque tokens that encode session identity (e.g., `sess-b91c:42` or a UUID). 3. The server can change the effective session identity across a reconnect (process recycle, load-balancer re-pin, session-table eviction) *without* returning a terminal status that forces re-initialization. 4. The client treats a `200` on the resumption POST as authoritative and does not cross-check the response `Mcp-Session-Id` against the request. Remove any one and the failure is bounded. If IDs encode session identity (2), the cursor cannot cross namespaces. If the server returns `404` on unknown session (3), the client re-initializes. If the client enforces session-header equality on resume (4), it aborts. The dangerous configuration is the *default-looking* one: integer IDs, a server that "helpfully" tolerates unknown sessions by minting a new one, and a client that trusts `200`. ## Decision Boundary The client must draw the line as follows. On any resumption POST: - **Hard invariant:** the `Mcp-Session-Id` returned by the server on a resumption response MUST equal the one sent. Any divergence is a session-identity break, not a resume. Abort the resume, discard all frames received on that connection, and re-initialize from scratch — do not merge. - **Cursor validity:** an event ID is admissible only if the client can bind it to the session that issued it. If IDs are bare integers, the client must treat the session ID as the namespace and refuse to replay a cursor across a namespace change. If the server cannot guarantee session-stable ID spaces, the client must not use `Last-Event-ID` at all and instead re-issue the `tools/call` idempotently (with a client-generated idempotency key) and discard the partial stream. - **Ambiguity is failure:** if the server does not echo the session ID on resumption, or echoes it only in a trailer the client may not have consumed, the resume is indeterminate. Indeterminate resumes must be treated as failed, not as best-effort. The server's corresponding obligation: never honor a `Last-Event-ID` whose namespace does not match the request's session; return `404` (unknown session) or `409` (namespace mismatch) rather than silently re-binding. A server that mints a new session on an unknown-session resume is non-conformant for stateless tool invocation, because it converts a detectable expiry into an undetectable cross-session replay. ## Operational Effect The practical consequence is that **statelessness at the tool layer does not imply statelessness at the transport layer.** The tool call itself may be pure, but the SSE resumption channel is stateful, and its state (the event-ID namespace) is exactly what a rolling restart destroys. An agent that assumes "the tool is stateless, so any 200 is fine" will silently ingest foreign results whenever the server's event-ID space is recycled under it. The guardrail that bounds the blast radius is cheap: a single equality check between request and response session headers on every resumption, plus a refusal to replay bare-integer cursors across a session change. Without it, the failure is silent, self-consistent, and propagates through baton passes because downstream verifiers have no independent view of the original query. With it, the worst case degrades to a re-initialize and a re-issued idempotent call — a latency cost, not a correctness cost. The invariant to encode: *a resume is a claim about session identity, and a claim that cannot be checked must be rejected.* ```python class UnsafeResumeError(RuntimeError): """Raised when an SSE resumption cannot be bound to the originating session.""" pass def resume_stream(request_session_id: str, last_event_id: str | None, response_status: int, response_session_id: str | None, event_id_is_session_scoped: bool) -> str: """ Decide whether an MCP streamable-HTTP resumption is safe to merge. Returns the session ID to continue under, or raises UnsafeResumeError. """ if response_status != 200: # Terminal / retryable status: caller re-initializes. Not our failure. raise UnsafeResumeError( f"resumption returned {response_status}; must re-initialize, not merge" ) if response_session_id is None: raise UnsafeResumeError( "server did not echo Mcp-Session-Id on resumption; resume is indeterminate" ) if response_session_id != request_session_id: # The silent-rebind case: 200 OK but a different logical session. raise UnsafeResumeError( f"session identity break: sent {request_session_id!r}, " f"server bound {response_session_id!r}; discarding all frames" ) if last_event_id is not None and not event_id_is_session_scoped: # Bare-integer cursor cannot be proven to belong to this namespace. raise UnsafeResumeError( f"cursor {last_event_id!r} is not session-scoped; " "refusing Last-Event-ID replay, re-issue call idempotently" ) return response_session_id ```