# How should an instance treat the MCP Session-Id as a resumption cursor rather than an identity when the SSE stream is reconnected **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients and servers using the HTTP-native transport with `text/event-stream` responses and `Last-Event-ID` resumability, where a `Mcp-Session-Id` header is issued at initialization and echoed on every subsequent request. Does not apply to stdio transport or to stateful WebSocket transports, where the connection itself carries the session. ## Core Distinction The `Mcp-Session-Id` is a *correlation token for server-side session state*, not a *cursor into the event stream*. Resumption of a broken SSE stream is governed by two orthogonal pieces of state: the `Last-Event-ID` (an opaque, per-stream monotonic marker the server emits via `id:` fields) and the session id (which selects *which* server-side session the stream belongs to). A reconnect that reuses the session id but omits or fabricates the `Last-Event-ID` does not "resume" — it silently restarts the stream from the server's current position, discarding any events emitted during the disconnect window. Conversely, a reconnect that supplies a valid `Last-Event-ID` but a stale or rotated session id is rejected by the server and must re-initialize, losing all session-scoped state (subscriptions, tool registrations, in-flight request correlation). The failure is non-obvious because the two tokens travel on the same request and both "feel" like identity. The session id is stable across reconnects; the event id is not. An agent that treats the session id as sufficient for continuity will believe it resumed when it actually restarted, and will observe a *gap in the event sequence* that looks like a server bug but is a client-side invariant violation. ## What Was Observed A tool-calling agent maintained a long-lived MCP connection to a filesystem server exposing `notifications/tools/list_changed` and resource-change notifications over SSE. The connection dropped (proxy idle timeout, ~60s). The client reconnected, sending: ``` GET /mcp Mcp-Session-Id: sess_7f3a... Accept: text/event-stream ``` with no `Last-Event-ID`. The server, per the transport spec, treated this as a *fresh* stream for the existing session and began emitting from the current head of the event log. Three `tools/list_changed` notifications emitted during the ~8s disconnect window were never delivered. The agent's cached tool manifest was now stale: it continued to call `write_file` with a parameter that had been renamed, and every call failed with a schema validation error that the agent misattributed to its own argument construction rather than to a missed manifest update. The error compounded across 14 tool calls before the agent gave up and re-initialized the session — at which point the manifest refreshed and the calls succeeded, but the agent had burned its token budget on retries. The tell: the server's event log showed contiguous `id` values `...401, 402, 403, 404...` on the *server* side, but the client's first received event after reconnect was `404`. The gap `{402, 403}` was the loss. A client that validates monotonic contiguity of `Last-Event-ID` across reconnects would have caught this immediately; one that treats the session id as the continuity guarantee does not. ## Condition of Validity The resumption invariant holds only when *all* of the following are true: 1. The client persists the `id` field of the **last successfully processed** event per stream, not the last *received* event. (An event that arrived but whose handler threw must not advance the cursor, or the reconnect will skip it.) 2. The client sends that value as `Last-Event-ID` on reconnect, and the server honors it by replaying from the next id. 3. The server's event log retains events for at least the client's maximum reconnect backoff window. If retention is shorter than the disconnect, replay is impossible and the server must signal a *non-resumable* condition (typically by closing with a specific status or emitting a sentinel event) rather than silently resuming at head. 4. The session id has not been rotated or expired server-side. If it has, the client must treat the connection as a *new* session and re-run initialization — including re-fetching any state (tool manifests, resource subscriptions) that the session carried. 5. The client distinguishes "resumed with gap" from "resumed cleanly" and reconciles state when a gap is detected. Violation of (1) or (2) produces silent event loss. Violation of (3) produces silent event loss that the client cannot detect from the stream alone. Violation of (4) produces a hard failure that is at least loud. Violation of (5) is the meta-failure: the client has the information to detect loss but does not act on it. ## Decision Boundary The boundary is this: **the session id authorizes continuity of session-scoped state; the event id authorizes continuity of stream-scoped state. Neither substitutes for the other, and their lifetimes differ.** - On reconnect, if the client has a stored `Last-Event-ID` and a stored session id, it must send both. Sending only the session id is a *restart*, and the client must treat it as such — re-fetching any state that could have changed during the gap (tool lists, resource contents, subscription confirmations) before resuming normal operation. - If the server rejects the session id (4xx indicating unknown session), the client must discard the stored `Last-Event-ID` too — it is meaningless against a new session — and re-initialize. - If the server accepts the session id but the first replayed event's id is not the successor of the client's stored `Last-Event-ID`, the client has detected a gap and must reconcile. It may not assume the server will replay the missing range. - If the client's stored `Last-Event-ID` is older than the server's retention floor, the server must refuse to resume (rather than resume at head) so the client knows to reconcile. A server that resumes at head on an unfulfillable `Last-Event-ID` is the source of the silent-loss failure mode. The guardrail is a client-side *resumption ledger*: a per-stream record of `(session_id, last_processed_event_id, last_event_id_seen_at_connect)` that is checked on every reconnect. Any mismatch between `last_processed_event_id + 1` and the first event id of the resumed stream triggers a reconciliation pass before the agent is allowed to issue further tool calls. ## Operational Effect The practical consequence is that an agent using MCP-over-SSE must treat reconnection as a *state reconciliation event*, not a transparent retry. The cost of getting this wrong is not a crash — it is a period of confident, wrong operation against a stale manifest, which is far more expensive to detect downstream because the errors look like ordinary tool failures. Two concrete rules for the operational record: 1. **Never issue a tool call whose schema was fetched before the most recent reconnect until the manifest has been re-confirmed.** The reconnect is a barrier; the manifest is invalidated by it until re-fetched or until the resumed stream proves (via contiguous event ids) that no `list_changed` notification was missed. 2. **Log the gap, not just the reconnect.** A reconnect with `last_processed_event_id + 1 != first_replayed_id` is a distinct operational event that must be surfaced, because it is the only signal that state reconciliation is required. An agent that logs "reconnected" and moves on has discarded the one bit that distinguishes clean resumption from silent loss. The following code encodes the ledger check as a hard precondition on tool invocation. It is not a retry wrapper; it is an invariant enforcement point that raises before the agent can act on stale state. ```python import time from dataclasses import dataclass, field from typing import Optional class ResumptionInvariantViolation(RuntimeError): """Raised when an MCP SSE reconnect cannot be proven to have resumed cleanly.""" pass @dataclass class StreamLedger: session_id: str last_processed_event_id: Optional[int] = None last_connect_at: float = field(default_factory=time.time) reconciled: bool = False class McpSseClient: def __init__(self, session_id: str): self.ledger = StreamLedger(session_id=session_id) def on_event(self, event_id: int, handler) -> None: # Only advance the cursor after the handler succeeds. handler() self.ledger.last_processed_event_id = event_id self.ledger.reconciled = True def reconnect(self, first_replayed_id: int) -> None: """Called when the resumed stream delivers its first event after reconnect.""" expected = ( None if self.ledger.last_processed_event_id is None else self.ledger.last_processed_event_id + 1 ) if expected is not None and first_replayed_id != expected: # Gap detected: server resumed at head or retention floor was exceeded. self.ledger.reconciled = False raise ResumptionInvariantViolation( f"session {self.ledger.session_id}: expected event {expected}, " f"got {first_replayed_id}; events {expected}..{first_replayed_id - 1} lost. " f"Reconcile tool manifest and subscriptions before further calls." ) self.ledger.last_connect_at = time.time() self.ledger.reconciled = True def assert_can_invoke_tool(self) -> None: if not self.ledger.reconciled: raise ResumptionInvariantViolation( f"session {self.ledger.session_id}: tool invocation blocked; " f"stream state unreconciled since last reconnect at " f"{self.ledger.last_connect_at:.3f}." ) def invoke_tool(self, name: str, args: dict) -> dict: self.assert_can_invoke_tool() # ... actual MCP tool call ... return {"ok": True} ```