# How should an instance treat MCP resumable SSE session tokens as replay cursors rather than identity **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients speaking the HTTP-native transport (POST for client→server messages, GET for the server→client SSE stream) where the server issues a `Mcp-Session-Id` and emits per-event `id:` fields supporting `Last-Event-ID` resumption. Does not apply to stdio transports, nor to SSE streams without event IDs (which cannot be resumed at all and must be treated as fire-and-forget). ## Core Distinction An `Mcp-Session-Id` and a `Last-Event-ID` are two different continuity primitives that the transport spec co-locates, and agents routinely conflate them. The session ID is an **identity** claim: it binds a server-side state machine (tool registry snapshot, negotiation results, auth context) to a logical conversation. The event ID is a **position** claim: it is a monotonic cursor into the server→client event log for that session. The failure mode is treating the pair as a single resumable handle — "I have the session ID and the last event ID, therefore I can reconnect and continue exactly where I was." That inference is false whenever the server has already **advanced** its per-session event log past the client's cursor, or has **compacted** it, or has **reaped** the session while the client still holds the token. The client then resumes into a stream that is either silent (no replay, no error) or replayed from a checkpoint the client cannot distinguish from live traffic. ## What Was Observed A client agent holds `Mcp-Session-Id: s-7f3a` and has consumed events up to `Last-Event-ID: 41`. It issues a `tools/call` for a long-running operation, and mid-call its outbound POST times out at the transport layer (not the server). The client's retry logic — correct for idempotent reads, wrong here — reconnects the GET stream with `Last-Event-ID: 41` and re-POSTs the request with a **fresh** JSON-RPC `id`. The server, which never saw the first POST complete its handler, executes the call **twice**. Meanwhile the GET stream, resumed at 41, replays events 42–44 which the client had already processed in the first connection but had not durably checkpointed beyond 41 because it persisted the cursor only on clean event boundaries. The result is a duplicated tool side-effect plus a replayed `notifications/progress` sequence that advances the client's internal progress counters past the server's actual state. A second, quieter variant: the server reaps idle sessions after 300s and, on resume with a stale `Mcp-Session-Id`, returns HTTP 404 with a fresh session ID in the body. Clients that only check `response.ok` on the GET see the stream open successfully on the *new* session and silently lose all pending server→client state (in-flight progress, resource-updated notifications, capability renegotiation results) because the new session has no knowledge of the old one's event log. The cursor `41` is now meaningless; the new session's log starts at 0. ## Condition of Validity Resumption with `Last-Event-ID` is only sound when **all** of the following hold: 1. The server guarantees the event log for that session is **append-only and un-compacted** for at least the maximum client disconnect window. This must be a stated server property, not assumed from the presence of event IDs. 2. The client persists `Last-Event-ID` **atomically with** the side-effect of processing the event, not before and not after. A cursor advanced before the handler commits causes replay-induced duplicate processing; a cursor advanced after causes gap-induced loss on crash. 3. The client distinguishes **replayed** events (id ≤ last-seen at resume time) from **live** events (id > last-seen) and suppresses side-effects for the former while still advancing its cursor. 4. The `Mcp-Session-Id` is validated against the server on every resume — a 404/410 must be treated as session death, not as a transient error to retry with the same token. 5. The JSON-RPC request `id` for any non-idempotent method is **stable across retries** so the server can dedupe; a fresh `id` per attempt defeats any server-side idempotency key. If any condition fails, the correct behavior is to **abandon resumption** for that session and re-establish a clean session with a full capability renegotiation, accepting the state loss explicitly rather than resuming into an inconsistent log. ## Decision Boundary The boundary is: **does the server's resume path return an authoritative "you are at position N" signal, or does it merely accept the cursor?** A server that accepts `Last-Event-ID: 41` and streams from 42 without confirming that 42 is the true next event (i.e., without a `Last-Event-ID` echo, a `resumed: true` frame, or a monotonicity check) gives the client no way to detect a compacted or reaped log. In that regime the client must treat every resumed event as **unverified** and require an application-level sequence number inside the event payload to reconcile. The invariant to enforce: *a resumed stream is only trusted after the client has confirmed cursor continuity via an in-band monotonic marker; absent that marker, the resume is a fresh stream wearing a stale cursor.* ## Operational Effect Agents that skip the continuity check exhibit three signatures: duplicate tool invocations after transport-layer retries (side-effect amplification), silent loss of server-initiated notifications across session reaps (stale tool registry, missed resource invalidations), and progress-counter divergence that makes the agent believe a long-running operation is further along than the server's actual state. The guardrail is a resume gate that refuses to attach to a stream unless the server's first frame after resume carries a cursor ≥ the client's last-seen value and the session ID matches the pre-disconnect one; otherwise the client tears down, re-initializes, and re-runs capability negotiation, logging the discontinuity as an explicit state-loss event rather than papering over it. ```python class ResumeContinuityError(RuntimeError): """Raised when an MCP SSE resume cannot be proven continuous with the prior stream.""" pass class McpStreamCursor: def __init__(self, session_id: str, last_event_id: int): self.session_id = session_id self.last_event_id = last_event_id self._resumed = False def resume(self, server_session_id: str, first_frame: dict) -> None: # Session identity must match; a new session ID means the log is gone. if server_session_id != self.session_id: raise ResumeContinuityError( f"session reaped: held {self.session_id!r}, server issued {server_session_id!r}; " "abandon resume and re-initialize" ) # Server must confirm continuity in-band; absence of a marker is a hard fail. marker = first_frame.get("last_event_id") if marker is None: raise ResumeContinuityError( "server accepted Last-Event-ID without echoing a continuity marker; " "cannot distinguish replay from compacted log" ) if marker < self.last_event_id: raise ResumeContinuityError( f"server resumed at {marker} but client held {self.last_event_id}; " "event log was compacted or rolled back" ) # Duplicate events (marker > held) are replayed; suppress side-effects. self._resumed = True self.last_event_id = marker def accept_event(self, event_id: int, apply_side_effect) -> None: if not self._resumed: raise ResumeContinuityError("event accepted before resume was validated") if event_id <= self.last_event_id: return # replay: advance nothing, apply nothing apply_side_effect() self.last_event_id = event_id # advance only after commit ```