# In what scenarios must an instance treat MCP stream resumption as a capability negotiation, not a transport retry **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients and servers using HTTP-native transport (Streamable HTTP) with SSE streaming and the `Last-Event-ID` resumption mechanism, where a client attempts to resume an interrupted stream or upgrade a request into a stream. Does not apply to stdio transport, nor to plain request/response JSON over HTTP with no streaming. ## Core Distinction The failure is not "the connection dropped." The failure is conflating *transport-level reconnection* with *session-level resumption*. In MCP Streamable HTTP, a client may reconnect to an endpoint after an SSE stream breaks, and it may send `Last-Event-ID` to ask the server to replay events after a given point. These are two distinct operations with different preconditions: - **Reconnection** is stateless: any client can open a new HTTP request to the endpoint. It succeeds if the endpoint is reachable and the session identity (e.g., `Mcp-Session-Id`) is valid. - **Resumption** is stateful and *negotiated*: the server must (a) still hold the event buffer for that session, (b) still recognize the session, and (c) be willing to honor a `Last-Event-ID` for that specific stream. If any of these is false, the correct server behavior is to reject or downgrade the resume — not to silently start a fresh stream that looks like a resume. The non-obvious invariant: **a successful HTTP 200 on the resumed request does not imply that events were replayed.** A server can accept the connection, emit a fresh stream with no replay, and the client will interpret the absence of replayed events as "nothing was missed," when in fact the gap is unbounded. The client's continuity guarantee is broken precisely at the point where the transport reports success. ## What Was Observed A tool-calling agent issued a long-running MCP request (a multi-step retrieval that streams incremental tool results). The SSE stream broke mid-flight after event id `41`. The client reconnected with `Last-Event-ID: 41` and `Mcp-Session-Id: s-7f3a`. The server returned `200 OK` with `Content-Type: text/event-stream` and immediately emitted event `id: 88` — a *later* event from the same logical stream, because the server's ring buffer had evicted events `42`–`87` under memory pressure but retained the tail. No `id` gap signal was sent. The client appended event 88 to its state, assumed continuity, and proceeded with a partially-ordered tool-result sequence. Downstream, the agent's reasoning step consumed a result set that was missing 46 intermediate tool outputs, and its final answer was internally consistent but factually truncated. A second variant: the client sent `Last-Event-ID` against a server that had already garbage-collected the session (idle timeout). The server returned `404 Not Found` with a JSON body, but a misconfigured client library treated any non-5xx as "retry the stream" and reissued the original request *without* the session header, creating a new session and replaying the entire tool sequence from scratch — duplicating side-effecting tool calls (a write, in this case). A third variant: the client attempted to *upgrade* a pending POST response into an SSE stream by reissuing with `Accept: text/event-stream`, expecting the server to attach to the in-flight operation. The server, which did not implement upgrade-attach semantics, treated it as a fresh request and started a second concurrent execution of the same tool chain. Two agents' worth of side effects, one logical request. ## Condition of Validity Resumption is only valid when all of the following hold simultaneously, and the client must be able to *verify* each rather than assume it: 1. The server advertises resumption support for the session (e.g., via a capability field in the initialize handshake, or a documented `Last-Event-ID` contract). Absence of an explicit signal must be treated as "no resumption." 2. The session id in the resume request matches a live session whose event buffer has not been truncated below the requested `Last-Event-ID`. The server must signal truncation explicitly — a gap marker, a `resume-rejected` event, or a distinct status — rather than emitting the tail as if contiguous. 3. Event ids are monotonic and gap-detectable. If the server's ids are per-stream counters that reset, `Last-Event-ID` is meaningless across a stream boundary. 4. The resume request is idempotent with respect to side effects: if the server cannot prove it will not re-execute the tool chain, the client must not treat the resume as safe for non-idempotent operations. Outside these conditions — no advertised capability, unknown/expired session, non-monotonic ids, or side-effecting chains — the only correct action is to treat the stream as *lost* and re-plan from a known checkpoint, not to resume. ## Decision Boundary The boundary is between **"resume the stream"** and **"restart the operation."** The client must decide this *before* sending `Last-Event-ID`, based on the session's advertised capabilities and the idempotency of the in-flight work, not after observing the server's response. If the client waits for the response to decide, it has already committed to a resume and any server that silently starts fresh will corrupt state. Concretely: - If the session advertises resumption **and** the pending operation is read-only or idempotent → send `Last-Event-ID`, and on any response that does not include a replay marker, treat the stream as lost and fall back to restart. - If the session does not advertise resumption, or the session id is unknown/expired, or the operation has side effects → do not send `Last-Event-ID`. Terminate the logical operation, reconcile side effects via an idempotency key, and re-plan. - If the server returns `200` with a stream whose first event id is greater than `Last-Event-ID + 1` → this is a truncation. The client must reject the stream, not consume it. A one-event gap is a resumption; a multi-event gap is data loss wearing a 200. The upgrade case is stricter: an upgrade-attach (reissuing to convert a pending request into a stream) is only valid if the server explicitly supports attach semantics for in-flight operations. Otherwise the upgrade is a *new request* and must carry a fresh idempotency key or be refused. ## Operational Effect When the boundary is respected, an interrupted MCP stream produces either a verified contiguous replay or a clean, observable restart — never a silent gap. Agents that enforce this invariant lose some throughput on flaky links (they restart more often than they resume) but never produce truncated tool-result sequences that pass local consistency checks. The observable effect is that "the agent's answer was wrong but self-consistent" incidents disappear, replaced by explicit `resume-rejected` or `gap-detected` events that the planner can handle. When the boundary is violated, the failure is silent and downstream: the agent's state is missing events, its reasoning over that state is locally valid, and the corruption only surfaces when a later step contradicts a fact that was in the dropped range. By then the session has advanced and the dropped events are unrecoverable. ```python class ResumeNegotiationError(RuntimeError): """Raised when an MCP stream resume cannot be proven contiguous or safe.""" pass def resume_stream(client, session, last_event_id, operation): # 1. Capability gate: refuse to send Last-Event-ID unless advertised. if not session.capabilities.get("resumable_streams", False): raise ResumeNegotiationError( f"session {session.id} does not advertise resumable_streams; " "must restart operation, not resume" ) # 2. Session liveness gate. if not session.is_live(): raise ResumeNegotiationError( f"session {session.id} is not live; resume would create a new " "session and re-execute side effects" ) # 3. Idempotency gate for side-effecting operations. if not operation.is_idempotent() and not operation.has_idempotency_key(): raise ResumeNegotiationError( f"operation {operation.id} has side effects and no idempotency " "key; resume is unsafe, restart with reconciliation required" ) stream = client.request_stream( session_id=session.id, last_event_id=last_event_id, accept="text/event-stream", ) # 4. Contiguity gate: first event must be exactly last_event_id + 1. first = stream.peek_first_event() if first is None: raise ResumeNegotiationError( "resume returned an empty stream; cannot prove replay occurred" ) if first.id != last_event_id + 1: # A 200 with a gap is truncation, not resumption. raise ResumeNegotiationError( f"resume gap detected: requested after {last_event_id}, " f"first replayed event is {first.id}; stream is truncated" ) return stream ```