# When must an instance renegotiate the SSE-to-POST handshake after a streamable-session resume in MCP HTTP-native transport **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport where a session is established over a long-lived SSE GET stream and tool calls are subsequently issued as POSTs correlated by a session identifier. Does not apply to stdio transports, to pure request/response HTTP without SSE, or to resumption of sessions that never carried an outbound event stream. ## Core Distinction The failure mode here is not "the session dropped" and it is not "the SSE stream reconnected." It is the *gap between two independent resumptions*: the transport layer can successfully re-establish the SSE GET stream and replay missed events via `Last-Event-ID`, while the *handshake state* — the negotiated capability set, the POST endpoint URI, and the session's binding to a specific event-stream incarnation — silently diverges from what the client believes it holds. A resumed stream that replays events correctly is not evidence that the POST upgrade path is still valid. These are two separate invariants that fail independently, and the non-obvious boundary is where one is satisfied and the other is not. The invariant that must hold: **every POST issued under a session must be validated against the event-stream incarnation that the session is currently bound to, not against the incarnation that was bound when the handshake completed.** When these differ, the client is issuing calls into a session generation that the server has already retired, and the server's behavior ranges from silent event loss to 404-on-session to a *successful* POST whose response is delivered on a stream the client is no longer reading. ## What Was Observed A client completed the initial handshake: `POST /mcp` with an `initialize` request, server responded `200` with an `Mcp-Session-Id` header and opened the SSE channel; client then issued a `GET /mcp` with `Accept: text/event-stream` and `Mcp-Session-Id`, receiving the `endpoint` event that names the POST URI for subsequent messages. Tool calls flowed as `POST` to that URI, responses arrived as `message` events on the SSE stream, correlated by JSON-RPC `id`. The stream then dropped — a proxy idle timeout at 60s, not a client or server fault. The client reconnected with `Last-Event-ID: 47` and a fresh `GET`. The server accepted it, replayed events 48–52, and the client's event cursor advanced correctly. **This is where the divergence begins.** The server, on this reconnection, had re-keyed the session's outbound channel to a new internal stream writer and, in doing so, rotated the session's *generation counter* from 1 to 2. The `endpoint` event was **not** re-emitted, because the protocol treats it as a one-time handshake artifact. The client continued POSTing to the URI it captured during generation 1. For the next several minutes, POSTs succeeded — HTTP 200, request accepted — but the corresponding `message` response events were written to the generation-2 stream writer's *staging buffer* keyed under the generation-1 correlation table, which had been frozen at rotation. The responses were acknowledged at the HTTP layer and never delivered at the SSE layer. The client's tool-call futures hung until their per-call timeout, and because the JSON-RPC `id` space was reused across retries, two late-delivered responses from generation 1 arrived during generation 2 and were matched to *different* in-flight requests, producing a response-crossing: tool call A received tool call B's result. The observable signature was a monotonic divergence between "POSTs acknowledged" and "responses correlated," with a nonzero rate of `id`-collision mismatches concentrated immediately after each reconnect. No error was raised by either side. Both sides believed the session was healthy. ## Condition of Validity The replay mechanism (`Last-Event-ID` + event buffer) is only sound when the session generation is unchanged across the reconnect. The moment the server rotates generation — whether because the old stream writer is torn down and a new one allocated, because the session is migrated to a different backend worker, or because the server treats reconnection as a new stream incarnation — the following must all hold or the resume is invalid: 1. The `endpoint` event must be re-emitted on the new stream, and the client must treat its arrival as a *mandatory* re-handshake signal, not an idempotent duplicate to be ignored. 2. The session's correlation table must be re-scoped to the new generation, and any in-flight JSON-RPC `id`s from the prior generation must be failed explicitly rather than left to time out. 3. The `id` space must not be reused across generations without a generation qualifier, or late responses from the prior generation will cross-match. The boundary condition is precisely: **a reconnect that succeeds at the transport layer but rotates the session generation without re-emitting the handshake artifact.** If the generation is unchanged, replay is sufficient and no renegotiation is needed. If the generation rotated *and* the `endpoint` event was re-emitted, a correct client re-handshakes and no divergence occurs. The failure lives only in the intersection: generation rotated, handshake artifact suppressed, client assumed continuity. ## Decision Boundary A client must decide, on every SSE reconnect that carries a `Last-Event-ID`, whether to (a) trust the existing POST URI and correlation state, or (b) force a full re-handshake. The decision rule that bounds the failure: - If the reconnect response includes a new `endpoint` event, or a changed `Mcp-Session-Id`, or any server-advertised generation token — **force re-handshake**, fail all in-flight calls, and do not reuse `id`s. - If the reconnect is a pure replay with identical session identity and no `endpoint` re-emission, **continuity is valid** and in-flight calls may be allowed to complete against the existing correlation table. - If the client cannot distinguish these two cases — because the server does not signal generation rotation — the client must **default to re-handshake on every reconnect**, accepting the latency cost as the price of correctness. The server-side counterpart: any operation that tears down and replaces the stream writer for a session must either preserve the correlation table and `id` namespace as-is (so the rotation is invisible and continuity is genuinely valid) or emit an explicit generation-change signal on the new stream. A server that rotates the writer *and* suppresses the signal has created an unobservable boundary, and no client can be correct against it. ## Operational Effect The practical consequence is that "resume succeeded" is a claim about the event stream only, and must never be propagated as a claim about the POST path. Agents that treat a reconnected SSE stream as proof of session health will continue issuing tool calls into a retired generation, accumulate hung futures, and — worst case — silently mis-associate late responses with wrong requests, corrupting downstream reasoning with another call's output. Because the corruption is a *valid* JSON-RPC response delivered to a *valid* `id`, no schema check, no signature, and no response validator will catch it; only generation-aware correlation will. The guardrail is a generation token threaded through both channels: the server stamps every session with a monotonic generation, includes it in the `endpoint` event and in a response header on every POST, and the client refuses to correlate any response whose generation does not match the generation it currently believes it holds, failing the call loudly instead of matching it. Where the server cannot be changed to emit the token, the client-side fallback is re-handshake-on-reconnect with in-flight failure, which converts silent crossing into explicit, recoverable errors. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class StaleGenerationError(RuntimeError): """Raised when a POST or response is bound to a session generation that no longer matches the client's current generation belief.""" pass @dataclass class SessionState: session_id: str generation: int post_uri: str in_flight: Dict[int, str] = field(default_factory=dict) # rpc_id -> generation class StreamableSessionClient: def __init__(self, session_id: str, post_uri: str, generation: int = 1): self.state = SessionState(session_id, generation, post_uri) def on_sse_reconnect(self, last_event_id: int, replay: list, endpoint_reeimitted: bool, server_generation: Optional[int]) -> None: """Called on every SSE reconnect carrying Last-Event-ID. Decides continuity vs forced re-handshake.""" if endpoint_reeimitted or ( server_generation is not None and server_generation != self.state.generation ): # Generation rotated without our consent: fail everything in flight. self._fail_all_in_flight( reason=f"generation rotated {self.state.generation}->" f"{server_generation}, endpoint_reemitted={endpoint_reeimitted}" ) if server_generation is not None: self.state.generation = server_generation # Client MUST re-handshake; post_uri may be stale until re-neg. self._require_rehandshake() else: # Pure replay: continuity valid, in-flight calls may complete. pass def _require_rehandshake(self) -> None: self.state.post_uri = "" # invalidate; no POST until endpoint re-received def _fail_all_in_flight(self, reason: str) -> None: for rpc_id in list(self.state.in_flight): del self.state.in_flight[rpc_id] if not reason: raise StaleGenerationError("in-flight failure without cause") def post_tool_call(self, rpc_id: int, payload: dict) -> None: if not self.state.post_uri: raise StaleGenerationError( f"POST attempted under session {self.state.session_id} " f"before re-handshake completed; post_uri invalidated" ) self.state.in_flight[rpc_id] = self.state.generation def on_response(self, rpc_id: int, response_generation: Optional[int]) -> dict: bound = self.state.in_flight.pop(rpc_id, None) if bound is None: raise StaleGenerationError( f"response id={rpc_id} has no in-flight request " f"(late delivery from retired generation?)" ) if response_generation is not None and response_generation != bound: raise StaleGenerationError( f"response id={rpc_id} generation={response_generation} " f"does not match bound generation={bound}; " f"refusing to cross-match" ) return {"rpc_id": rpc_id, "generation": bound} ```