# Where must an instance renegotiate an MCP streamable-SSE upgrade when a resumable session token survives the transport it was minted on **Date of Record:** 2026 December 4 **Scope:** Applies to MCP servers exposing HTTP-native transport with optional SSE upgrade and `Last-Event-ID`-based resumption across reconnects. Does not apply to stdio transport, nor to stateless request/response MCP endpoints that never issue resumable tokens. ## Core Distinction The distinction that matters is between **session identity** and **transport binding**. An MCP session token (returned by `initialize`, echoed in `Mcp-Session-Id`) is a logical handle to server-side agent state: negotiated capabilities, subscriptions, in-flight tool calls, pending server-to-client requests. The SSE upgrade — the `Accept: text/event-stream` negotiation that promotes a POST/GET pair into a long-lived event channel — is a *transport binding* layered on top of that session. These two have different lifetimes and different failure semantics. The non-obvious boundary: a session token can outlive the transport binding that minted it. When a client reconnects with a valid `Mcp-Session-Id` and a `Last-Event-ID`, the server is tempted to treat resumption as "same session, same channel, replay from offset." That is wrong whenever the *upgrade negotiation parameters* that governed the original SSE channel are not recoverable from the session token alone. The token proves *who* the session is; it does not prove *what transport contract* the replay must honor. The instance must renegotiate the upgrade, not merely resume the stream. ## What Was Observed A client agent held a session `S` established over a POST-initiated SSE upgrade with `Accept: text/event-stream, application/json` and server-assigned event IDs. Mid-tool-call, the underlying TCP connection dropped (load balancer idle timeout at 60s while the agent was blocked on a slow `filesystem.read` fan-out). The client reconnected with `Mcp-Session-Id: S` and `Last-Event-ID: 4471`. The server accepted the session, found event 4471 in its replay buffer, and resumed emitting from 4472 — but on a *new* SSE channel whose negotiated `Content-Type` was `application/json` because the reconnect request had dropped the `text/event-stream` accept header (the client's retry logic had rebuilt the request from a template that only carried the JSON accept). The server, seeing a valid session and a valid `Last-Event-ID`, did not reject the mismatch: it streamed SSE frames into a response the client's parser had already committed to decoding as a single JSON body. The client buffered ~40 events, then attempted `json.loads` on the concatenated `event:`/`data:` frames, raised a parse error, and tore down the session — discarding the in-flight tool result that event 4473 carried. The agent's next action was a retry of the same tool call. The server, whose session state still recorded the original call as *in flight* (the client's teardown never sent a cancellation), rejected the retry as a duplicate and returned the original result — which the client, now on a fresh session, had no event offset to associate with. Result: silent divergence between the agent's belief ("I am retrying") and the server's belief ("I already answered this"). ## Condition of Validity Resumption via `Last-Event-ID` is only valid when the reconnecting request re-establishes the *same* upgrade negotiation as the channel that produced the event IDs. Concretely, an instance may resume without renegotiation only if all of the following hold at the server: 1. The `Accept` header on the reconnect includes `text/event-stream` with the same media-type parameters (notably `charset` and any `Last-Event-ID`-relevant extensions) as the original upgrade. 2. The `Mcp-Session-Id` resolves to session state whose recorded transport binding matches the request's `Content-Type`/`Accept` pair. 3. The event ID namespace is scoped to the session *and* the transport binding generation — i.e., event IDs from generation *g* are not replayable on a channel negotiated as generation *g+1*. If any of these fail, the correct behavior is to **reject the resume with a `409 Conflict` carrying a `Mcp-Session-Id` reissue directive**, forcing the client to re-run `initialize` negotiation for the transport, not to silently downgrade the channel. The invariant: *a `Last-Event-ID` is a claim about a stream, and a stream is defined by its negotiation, not by its session.* ## Decision Boundary The boundary the instance must resolve at reconnect time: - **Resume** (no renegotiation) when the reconnect's `Accept`/`Content-Type` and the recorded binding generation match, and the `Last-Event-ID` falls within the replay buffer for that generation. - **Renegotiate** (re-run upgrade, mint new binding generation, *retain* session state) when the session is valid but the binding parameters differ. The session token survives; the event-ID namespace resets; the server must emit a `session-renegotiated` control event and re-emit any pending server-to-client requests that the old binding had queued. - **Reject** (close, do not resume) when the session token is invalid or the binding generation is unknown. Do not fall back to a fresh unauthenticated stream; that is the silent-downgrade path that produced the parse failure above. The trap is treating "valid session token" as sufficient for resume. It is necessary, not sufficient. The upgrade negotiation is a second, independent precondition that the token does not encode. ## Operational Effect Agents that skip renegotiation on binding mismatch exhibit a characteristic failure signature: a burst of event frames decoded as garbage, a client-side parse exception, session teardown without cancellation, and a subsequent duplicate-suppression collision on the server. The observable symptom is *divergence without error at the protocol layer* — both sides believe they are in a consistent state, but the client's event offset and the server's in-flight ledger disagree. The guardrail is to make the transport binding generation an explicit field in the session record, to scope event IDs to `(session, generation)`, and to require the reconnect to echo the generation (e.g., via a `Mcp-Binding-Generation` header or a media-type parameter). Any reconnect whose generation does not match the recorded one must be forced through renegotiation — never resumed. The cost is one extra round-trip on reconnect; the alternative is the silent divergence trace above, which is far more expensive to detect because neither side raises until the parse layer, long after the state has split. ```python class BindingMismatchError(RuntimeError): """Raised when a resumable MCP session token is presented on a transport binding whose upgrade negotiation does not match the binding that minted the event-ID namespace. Resumption is refused; renegotiation is required.""" pass def resume_stream(session_record: dict, request: dict) -> dict: """ session_record: server-side state for Mcp-Session-Id, including 'binding_generation' and 'accept' recorded at upgrade time. request: reconnect request carrying 'accept', 'last_event_id', and optionally 'binding_generation'. Returns a resume plan or raises BindingMismatchError to force renegotiation. """ if session_record is None: raise BindingMismatchError("unknown session; cannot resume") recorded_gen = session_record.get("binding_generation") recorded_accept = session_record.get("accept", "") req_accept = request.get("accept", "") req_gen = request.get("binding_generation") # Precondition 1: same upgrade media type, including parameters. if "text/event-stream" not in req_accept: raise BindingMismatchError( f"reconnect accept={req_accept!r} does not re-establish SSE upgrade " f"recorded as {recorded_accept!r}; refusing silent downgrade" ) # Precondition 2: binding generation must match if echoed. if req_gen is not None and req_gen != recorded_gen: raise BindingMismatchError( f"binding generation mismatch: request={req_gen} recorded={recorded_gen}; " f"event IDs are scoped to (session, generation) and are not replayable across" ) # Precondition 3: Last-Event-ID must fall inside this generation's buffer. last_id = request.get("last_event_id") buffer = session_record.get("replay_buffer", {}) if last_id is not None and last_id not in buffer: raise BindingMismatchError( f"Last-Event-ID {last_id} not present in generation {recorded_gen} buffer; " f"cannot guarantee contiguous replay" ) # Safe to resume: session state retained, stream continues on same binding. return { "action": "resume", "binding_generation": recorded_gen, "replay_from": last_id, "retain_session_state": True, } ```