# What structural signals indicate a broken SSE-to-POST upgrade boundary in MCP streamable-session resumption **Date of Record:** 2026 November 19 **Scope:** Applies to MCP servers and clients operating the HTTP-native "streamable" transport, where a session is opened over an SSE stream (`GET` with `Accept: text/event-stream`) and later upgraded so the client may issue `POST` requests carrying tool calls against the same session ID. Does not apply to stdio transports, WebSocket transports, or stateless single-request MCP endpoints with no session correlation. ## Core Distinction The streamable-session invariant is often described as "the session ID binds the GET stream to subsequent POSTs." That framing is wrong in a way that produces real production failures. The session ID does not bind a *stream*; it binds a *logical session whose current delivery channel is a mutable property*. The boundary condition that breaks is the moment when the server treats the session ID as proof that the SSE channel is still live, while the client treats receipt of a `POST` 200 as proof that the SSE channel is no longer needed. These two beliefs are both locally reasonable and jointly false. The SSE stream can be dead — closed by an intermediate proxy idle timeout, a load balancer `keepalive` eviction, a client-side fetch abort, or a server worker recycle — while the session record remains valid and the POST path continues to accept writes. The upgrade is not a handshake; it is an *unobserved state transition* on the server side. The structural signal that the boundary has been crossed is not an error code. It is a divergence between what the session's persisted "current channel" field claims and what the transport layer can actually deliver on. ## What Was Observed A concrete trace from a session that failed silently. The client opened a streamable session: ``` GET /mcp HTTP/1.1 Accept: text/event-stream Mcp-Session-Id: (none, new) → 200 OK Mcp-Session-Id: sess_9f2c Content-Type: text/event-stream ``` The server emitted an `endpoint` event instructing the client to POST to `/mcp?session=sess_9f2c`, then emitted a `message` event carrying the tool-call result for a `read_file` request. The client kept the SSE connection open in a background reader. Roughly 90 seconds later an intermediate proxy applied its idle timeout and sent a TCP FIN. The client's reader saw the stream close. Because the MCP streamable spec permits resumption, the client reconnected with `Last-Event-ID`: ``` GET /mcp HTTP/1.1 Accept: text/event-stream Mcp-Session-Id: sess_9f2c Last-Event-ID: 42 ``` The server responded `200 OK` and replayed events from ID 43 onward — but the *session record* on the server side had, during the gap, already been marked `channel=post` by the server's own POST handler on the previous turn. The server's resumption path did not reset `channel` back to `sse`. From this point forward every server-initiated notification (progress updates, `tools/list_changed`, sampling requests) was written to the session's `channel=post` outbox — a queue that the client never drains, because the client is waiting on the SSE stream that the server believes is no longer the primary channel. The client observed: a live SSE stream that received *only* replayed historical events and then silence. The server observed: a healthy session with a growing outbox. Neither side raised an error. The next `POST` tool call succeeded with `200`, reinforcing both sides' belief that the session was fine. The failure only surfaced when a long-running tool needed to emit an intermediate progress notification — which the client never received, causing the client's own timeout to fire and abort a task the server was still executing. The structural signals present in this trace, in order of diagnostic value: 1. **A `Last-Event-ID` resume that returns `200` but is followed by zero *new* events for longer than the client's expected heartbeat interval.** Replay-only resumption is indistinguishable from a healthy quiet stream unless the client tracks the highest event ID it has ever seen versus the highest ID it receives after resume. 2. **A `POST` that returns `200` with an empty or `202 Accepted`-style body while the corresponding response event never appears on the SSE stream.** In streamable MCP the POST response body and the SSE event are two delivery paths for the same logical message; if the server writes to the outbox and the client reads the POST body, the message is delivered exactly once on one path — but any *side-channel* notifications for that request are stranded. 3. **Session `channel` field mutation on the server without a corresponding client-acknowledged transition.** This is the root cause and the one signal operators rarely instrument. 4. **Divergence between outbox depth and client-observed unread count.** If the server exposes outbox metrics, a monotonically growing outbox paired with a client that reports "no pending notifications" is the cleanest smoking gun. ## Condition of Validity The invariant that must hold for streamable-session resumption to be safe is: > For any session `S`, at any instant, the set of messages the server has committed to `S`'s outbox but not yet observed as delivered must be deliverable on *every* channel `S` currently exposes, or the server must refuse to advance `S`'s channel state until the stranded messages are re-homed. This is stronger than "the session ID is valid." It requires the server to treat channel state as a *transactional* property coupled to outbox drain, not as a mutable flag flipped by whichever handler ran last. The condition is valid only when: - The server's channel transition (`sse` → `post` → `sse` on resume) is serialized against outbox writes, and - The client's `Last-Event-ID` resume either (a) drains the outbox onto the resumed SSE stream before any new events, or (b) is rejected with a resumable error that forces the client to re-establish a fresh session. It is *not* valid — and the failure above occurs — when resume is treated as "reopen the pipe" without reconciling the outbox, and when POST handling is allowed to flip channel state without checking whether the SSE channel is the client's live read path. The boundary is crossed precisely at the resume: the client's reconnect is an implicit assertion "the SSE channel is my live path," and the server must honor that assertion by re-homing the outbox or refuse the resume. A `200 OK` on resume that does neither is a lie the transport cannot detect. ## Decision Boundary The operational decision is narrow: **on `Last-Event-ID` resume, does the server re-home the outbox onto the SSE stream, or does it reject the resume and require a new session?** Re-home when: the outbox contains only notifications and tool-call response events with no side effects pending elsewhere, and the client's `Last-Event-ID` is within the server's replay window. In this case the resume handler must, atomically: set `channel=sse`, drain outbox to the stream in ID order, then resume live tailing. The `channel` mutation and the drain must be a single critical section — otherwise a concurrent POST can interleave a new outbox write between the drain and the live-tail attach, producing a lost notification that looks identical to the original bug. Reject when: the outbox contains events older than the replay window, or the session has pending server-initiated requests (sampling, elicitation) whose responses the client may have already sent on a now-dead channel. In this case return `409 Conflict` with a machine-readable `resume_unavailable` reason and require the client to open a new session. A rejected resume is recoverable; a silently half-resumed session is not, because it corrupts the client's belief about which channel is live. The boundary is also crossed in the reverse direction: a client that issues `POST` while its SSE reader is in a backoff-retry loop is asserting two live channels for one session. The server must reject POSTs on a session whose SSE channel is in `reconnecting` state (tracked via the resume handler's entry/exit), or accept them only as outbox writes with an explicit `X-MCP-Delivery: deferred` header so the client knows the response will arrive on the SSE path, not the POST body. ## Operational Effect The downstream effect is *silent partial delivery*: tool calls succeed, session IDs remain valid, HTTP status codes are all 2xx, and the only observable symptom is a client-side timeout on a task the server completed successfully. Because every individual request looks healthy, standard HTTP-level monitoring (status code rates, latency histograms) shows nothing. The failure is only visible in the *correlation* between outbox depth, client-observed event-ID high-water mark, and the gap between POST acceptance and SSE event arrival. The guardrail is a delivery-ledger invariant: every message committed to a session carries a monotonic delivery sequence number, and the server refuses to advance `channel` state, accept a resume, or accept a POST that would strand a message, unless the ledger shows the message is either delivered on a live channel or explicitly re-homed. This converts the silent divergence into a hard, observable rejection at the boundary — which is the only place the transport layer can catch it. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ChannelState(Enum): SSE = "sse" POST = "post" RECONNECTING = "reconnecting" class StreamableSessionError(RuntimeError): """Raised when a streamable MCP session's channel state would strand messages.""" @dataclass class OutboxEntry: seq: int delivered: bool = False @dataclass class StreamableSession: session_id: str channel: ChannelState = ChannelState.SSE outbox: list[OutboxEntry] = field(default_factory=list) last_client_event_id: int = 0 replay_window: int = 100 def _undelivered(self) -> list[OutboxEntry]: return [e for e in self.outbox if not e.delivered] def handle_resume(self, last_event_id: int) -> None: # Boundary: a resume asserts the SSE channel is the client's live path. # Either re-home the outbox onto the stream atomically, or reject. undelivered = self._undelivered() if undelivered and undelivered[0].seq < (last_event_id - self.replay_window): raise StreamableSessionError( f"resume_unavailable: session {self.session_id} outbox head " f"seq={undelivered[0].seq} precedes replay window floor " f"{last_event_id - self.replay_window}; open a new session" ) if undelivered and any(e.seq <= last_event_id for e in undelivered): raise StreamableSessionError( f"resume_ordering_violation: session {self.session_id} has " f"undelivered seq <= Last-Event-ID {last_event_id}; " f"outbox drain must precede live-tail attach" ) # Atomic transition: flip channel and drain are one critical section. self.channel = ChannelState.SSE for entry in undelivered: entry.delivered = True self.last_client_event_id = last_event_id def handle_post(self, response_event_seq: int) -> None: if self.channel is ChannelState.RECONNECTING: raise StreamableSessionError( f"post_during_reconnect: session {self.session_id} SSE channel " f"is reconnecting; POST would create a second live channel" ) # POST acceptance must not silently flip channel state; outbox writes # for side-channel notifications must be reconciled before the flip. self.outbox.append(OutboxEntry(seq=response_event_seq)) if self.channel is ChannelState.SSE: # Do not flip to POST here; the SSE channel remains the read path. return self.channel = ChannelState.POST def drain_outbox_on_stream(self) -> list[int]: delivered = [e.seq for e in self._undelivered()] for e in self._undelivered(): e.delivered = True return delivered ```