# Where must an instance renegotiate the SSE upgrade when a resumable MCP stream crosses a session rebind boundary **Date of Record:** 2026 November 15 **Scope:** Applies to MCP servers and clients using the HTTP-native streamable transport where a `GET` request with `Accept: text/event-stream` triggers a server-initiated SSE upgrade, and where `Last-Event-ID`-based resumption is offered across session rebinds. Does not apply to pure request/response JSON-RPC over HTTP without upgrade negotiation, nor to WebSocket transports where the upgrade is part of the handshake. ## Core Distinction The failure is not "the stream dropped" and it is not "resumption failed." Those are observable, loud symptoms. The non-obvious boundary is this: **the SSE upgrade is negotiated per HTTP connection, but the resumable event log is scoped per session.** When a client resumes with `Last-Event-ID` after the server has rebound the session to a new connection (or after an intermediary has terminated the original connection), the server must decide whether the *existing* upgrade negotiation is still valid for the *new* connection, or whether the client must renegotiate the upgrade from scratch. The two invariants — "upgrade is a property of the connection" and "resumption is a property of the session" — are individually correct and jointly inconsistent at the rebind boundary. A naive implementation treats the SSE upgrade as a one-time state transition: once the server has responded `200 OK` with `Content-Type: text/event-stream`, it assumes the session is in "upgraded" mode. It then accepts a `Last-Event-ID` on a *subsequent* `GET` and replays from the log — but it does so on a fresh connection that has *not* completed the upgrade handshake. The client, meanwhile, believes it is resuming an already-upgraded stream and does not re-send the `Accept` header negotiation semantics it would send on a first upgrade. The result is a stream that is syntactically SSE but semantically un-negotiated: the server writes events, the client reads them, and neither side has agreed on the upgrade, so neither side enforces the upgrade's obligations (heartbeat cadence, `retry` field authority, disconnect-on-idle policy). ## What Was Observed During a controlled fault injection on an MCP streamable transport server, the following sequence was reproduced deterministically: 1. Client issues `GET /mcp` with `Accept: text/event-stream`. Server responds `200`, upgrades, assigns session `S1`, emits events with monotonically increasing IDs on connection `C1`. 2. A load-balancer idle timeout kills `C1`. The server's session registry still maps `S1 -> upgraded=true`, `last_event_id=1042`. 3. Client reconnects: `GET /mcp` with `Last-Event-ID: 1042` and `Mcp-Session-Id: S1`, but **without** re-sending the upgrade-triggering `Accept` negotiation (the client library caches "this session is upgraded" and skips the handshake). 4. Server sees `S1` is already `upgraded=true`, skips the upgrade branch, and writes replay events 1043..N directly onto `C2` *before* sending the `200` response headers for the new request. Because `C2`'s response was not yet committed as `text/event-stream`, the events are buffered under the wrong content type and, in one variant, delivered as a `application/json` chunked body. The observable defect: the client's SSE parser silently dropped the replayed events (wrong content-type framing) while the server's event log advanced. On the *next* disconnect, the client resumed from `1042` again — but the server had already compacted events up to `N`. Events `1043..N` were permanently lost, and no error was raised on either side. This is a **silent resumption gap**, not a resumption failure. ## Condition of Validity The correct behavior — that a resumed stream may continue without renegotiation — holds **only if** the resumption request is made on a connection that has already completed the SSE upgrade handshake, i.e., the server has committed `200` + `text/event-stream` headers on *that specific connection* before processing `Last-Event-ID`. This condition is satisfied when: - The client re-sends the full upgrade negotiation (`Accept: text/event-stream`) on every reconnect, and - The server treats `upgraded` as a per-connection property, not a per-session property, and - No intermediary strips or rewrites the `Accept` header on reconnect. The condition fails whenever any of these is violated. The most common violation in practice is client-side caching of upgrade state, because the MCP streamable transport spec does not mandate re-sending `Accept` on reconnect — it only mandates `Last-Event-ID`. The spec's silence on the upgrade-vs-resumption interaction is the root of the boundary. ## Decision Boundary The server must choose, at the moment it receives a `GET` carrying both `Mcp-Session-Id` and `Last-Event-ID`: - **If the connection has not committed SSE headers:** treat the request as a *fresh upgrade negotiation*. Do not replay from the log until the `200 text/event-stream` response is committed. If the client did not send `Accept: text/event-stream`, reject with `406 Not Acceptable` rather than silently downgrading — a silent downgrade is what produces the content-type framing defect above. - **If the connection has committed SSE headers:** resume from `Last-Event-ID` on the same connection without renegotiation. The boundary is therefore: **renegotiation is required exactly when the connection identity changes, regardless of session identity.** Session rebind does not imply upgrade transfer. A server that keys `upgraded` on the session ID will fail this boundary every time the transport reconnects. ## Operational Effect When the boundary is respected, the operational effect is that reconnect latency increases by one round-trip (the renegotiation), and the server must buffer replay events until headers are committed. When the boundary is violated, the effect is not a visible error but a **monotonic divergence between the client's cursor and the server's compaction frontier**, which manifests later as inexplicable event loss under load. The failure is load-dependent: it only surfaces when compaction runs between two reconnects, which is why it escapes unit tests and appears only in production after hours of uptime. The defensive posture is to make the server refuse to replay onto an uncommitted connection, and to make the client always re-send the upgrade negotiation on reconnect even when it believes the session is already upgraded. The code below encodes the server-side guard. ```python class UncommittedResumptionError(RuntimeError): """Raised when a resumable MCP stream attempts to replay events onto a connection that has not committed the SSE upgrade handshake.""" pass class McpStreamSession: def __init__(self, session_id: str): self.session_id = session_id self.last_event_id = 0 self.event_log: list[tuple[int, dict]] = [] # Per-connection upgrade state. Keyed by connection id, NOT session id. self.upgraded_connections: set[str] = set() def commit_sse_upgrade(self, connection_id: str) -> None: """Called only after 200 + text/event-stream headers are flushed.""" self.upgraded_connections.add(connection_id) def resume(self, connection_id: str, last_event_id: int) -> list[dict]: if connection_id not in self.upgraded_connections: # The boundary: resumption without a committed upgrade on THIS # connection is invalid. Do not silently downgrade or replay. raise UncommittedResumptionError( f"session {self.session_id}: connection {connection_id} " f"attempted Last-Event-ID={last_event_id} resumption before " f"SSE upgrade was committed; client must renegotiate " f"Accept: text/event-stream on this connection" ) if last_event_id < self.last_event_id - len(self.event_log): raise UncommittedResumptionError( f"session {self.session_id}: Last-Event-ID={last_event_id} " f"is below compaction frontier; events permanently lost" ) return [payload for eid, payload in self.event_log if eid > last_event_id] ```