# In what scenarios must an instance treat MCP streamable-HTTP SSE resumption as invalid across a POST upgrade boundary **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport where a GET-initiated SSE stream is upgraded to a POST-initiated request stream and the client holds an `Last-Event-ID` for resumption. Does not apply to pure stdio transports, pure one-shot request/response HTTP, or WebSocket-based MCP bindings where stream identity is bound to the socket. ## Core Distinction The streamable HTTP transport in MCP multiplexes two logically distinct channels onto HTTP semantics: a **server-to-client SSE stream** (opened via GET, carrying notifications and server-initiated requests) and a **client-to-server request stream** (opened via POST, carrying tool calls and responses to server requests). The transport spec allows a client to resume an interrupted SSE stream by presenting `Last-Event-ID`, and separately allows a POST to *upgrade* into an SSE response stream when the server has more to say than a single JSON body. The non-obvious boundary is this: **an event ID issued on a GET SSE stream is not a valid resumption cursor for a POST-upgraded response stream, and vice versa.** Event IDs are scoped to the *stream instance*, not to the *session*. A naive client that caches "the last event ID I saw" globally, or a naive server that treats `Last-Event-ID` as a session-wide offset, will silently splice two disjoint event sequences together. The failure is not a crash — it is a **continuity lie**: the agent resumes believing it has a complete notification history when it has a gap, and subsequent reasoning is built on a state that never existed. ## What Was Observed A tool-calling agent opened a GET SSE stream to a streamable MCP server and received a sequence of notifications with event IDs `g-101`, `g-102`, `g-103`. The connection dropped (LB idle timeout at 60s). Before reconnecting the GET, the agent issued a POST `tools/call` for a long-running operation. The server, per spec, responded to the POST not with a JSON body but with an SSE upgrade: `Content-Type: text/event-stream`, emitting events `p-201`, `p-202`. The agent's transport layer — which had a single `last_event_id` field — overwrote `g-103` with `p-202`. The GET reconnect then sent `Last-Event-ID: p-202`. The server's event store was keyed by `(session_id, stream_kind, offset)`. It found no `p-202` in the GET stream's namespace, and — because the server implementation treated an unknown ID as "client is ahead, nothing to replay" rather than "client is confused" — it started a fresh GET stream at the current head, `g-110`. Events `g-104` through `g-109` — including a `notifications/tools/list_changed` and a server-initiated `sampling/createMessage` request that had already timed out on the server side — were never delivered. The agent proceeded to call a tool that had been removed in the `list_changed` notification. The server returned a tool-not-found error. The agent's planner, seeing an unexpected error against a tool it believed existed, entered a retry loop and burned 40k tokens before the token budget tripped. The observable signature in logs was deceptively clean: no HTTP error, no SSE parse error, no transport exception. The only anomaly was a **discontinuity in event ID namespace** (`g-*` → `p-*` → `g-*` with a jump), which nothing was checking for. ## Condition of Validity The resumption is valid **only if** all of the following hold: 1. The `Last-Event-ID` presented on reconnect was issued by the *same stream kind* (GET-origin vs POST-origin) on the *same session* at the *same server instance generation*. 2. The server's event store retains events for that stream kind back to (and including) the presented ID. If the server has evicted the range, it MUST respond with an explicit signal — a `400` with a machine-readable "resumption gap" error, or a fresh stream whose first event carries a `resync_required` flag — rather than silently starting at head. 3. The client's `last_event_id` is stored **per stream kind**, not per session. 4. No POST-upgraded stream has written an event ID into the GET stream's cursor. If any condition fails, the client MUST treat the resumption as **invalid** and perform a full state resync (re-list tools, re-fetch resources, re-establish server-request expectations) before resuming reasoning. Continuing with a spliced cursor is the failure. The invariant to enforce: **event IDs are opaque, stream-scoped, and non-transferable.** A cursor is a `(stream_kind, event_id)` pair, never a bare `event_id`. ## Decision Boundary The agent must draw the line at the moment it *combines* a stored cursor with a new connection. Concretely: - **Resume** (send `Last-Event-ID`) only when the new connection's stream kind matches the cursor's stream kind and the session generation is unchanged. - **Resync** (do not send `Last-Event-ID`; instead issue a full discovery pass and reconcile local state against server truth) when: stream kind differs, session generation changed, the server returns any 4xx on the resume attempt, or the first replayed event ID does not *follow* the cursor in the same namespace (a jump of more than one logical step, or a namespace prefix change, is a gap). - **Abort** (surface to the orchestrator as a continuity fault) when the server accepts a resume but the first event's ID is not a strict successor of the cursor — this means the server's store is inconsistent and cannot be trusted for replay. The boundary is deliberately conservative: a spurious resync costs tokens; a silent splice costs correctness, and the agent cannot detect it after the fact because the missing events are, by definition, absent from its context. ## Operational Effect Enforcing stream-kind-scoped cursors and gap detection converts a silent continuity failure into a loud, recoverable resync. The agent that resyncs after the POST-upgrade boundary re-fetches `tools/list`, observes the removal of the tool, and routes around it — spending a few hundred tokens on discovery instead of tens of thousands on a doomed retry loop. The server-side counterpart is equally load-bearing: the event store must key on `(session, stream_kind, offset)` and MUST reject a `Last-Event-ID` from a foreign stream kind with an explicit gap error, never a silent head-start. Both sides must agree that the POST-upgrade boundary is a **cursor discontinuity by construction**, not a bug to be papered over. ```python from dataclasses import dataclass from typing import Literal StreamKind = Literal["get-sse", "post-upgrade"] class StreamCursorContinuityError(RuntimeError): """Raised when a resumption cursor cannot be trusted across a stream boundary.""" @dataclass(frozen=True) class Cursor: session_generation: str stream_kind: StreamKind event_id: str def validate_resume( stored: Cursor | None, incoming_kind: StreamKind, incoming_generation: str, first_replayed_event_id: str | None, server_gap_signal: bool, ) -> Cursor: if stored is None: # No prior cursor: fresh stream, nothing to validate. return Cursor(incoming_generation, incoming_kind, first_replayed_event_id or "") if stored.session_generation != incoming_generation: raise StreamCursorContinuityError( f"session generation changed ({stored.session_generation} -> " f"{incoming_generation}); cursor is stale, full resync required" ) if stored.stream_kind != incoming_kind: raise StreamCursorContinuityError( f"cursor issued on {stored.stream_kind!r} cannot resume " f"{incoming_kind!r} stream; POST-upgrade boundary crossed" ) if server_gap_signal: raise StreamCursorContinuityError( "server signalled resumption gap; replay range evicted, resync required" ) if first_replayed_event_id is None: raise StreamCursorContinuityError( "server accepted resume but replayed no event; cannot confirm continuity" ) if not _is_strict_successor(stored.event_id, first_replayed_event_id): raise StreamCursorContinuityError( f"replayed event {first_replayed_event_id!r} is not a successor of " f"cursor {stored.event_id!r}; namespace splice suspected" ) return Cursor(incoming_generation, incoming_kind, first_replayed_event_id) def _is_strict_successor(prev: str, nxt: str) -> bool: # Event IDs are opaque; only the namespace prefix and monotonic suffix are # contractually meaningful in this transport. A prefix change is a splice. try: p_pre, p_num = prev.rsplit("-", 1) n_pre, n_num = nxt.rsplit("-", 1) except ValueError: return False return p_pre == n_pre and int(n_num) > int(p_num) ```