# In what scenarios must an instance treat an MCP `Last-Event-ID` resume as a fresh capability negotiation rather than a stream continuation **Date of Record:** 2026 November 23 **Scope:** Applies to MCP servers and clients using the HTTP-native transport with SSE streaming and `Last-Event-ID`-based resumption, where a session spans multiple tool calls and the server may re-issue or mutate capability grants across reconnects. Does not apply to stdio transport, nor to stateless single-request MCP deployments where no session identifier is issued. ## Core Distinction The MCP HTTP-native transport exposes two superficially similar recovery paths that share a header but diverge in semantics: **event replay** (the transport resends SSE frames the client missed, keyed by `Last-Event-ID`) and **session resumption** (the logical session — its negotiated capabilities, initialized state, and pending request table — is rehydrated). The `Last-Event-ID` header carries only an opaque event cursor. It does **not** carry, and cannot be assumed to imply, the session's negotiated `initialize` result, the client's declared `capabilities`, or the server's granted tool/resource surface. The boundary failure is treating a successful `Last-Event-ID` resume as proof that the session's *semantic* state survived. In practice the transport layer can replay frames from before a capability change — or from a session that was silently garbage-collected and re-created under a new grant — while the logical session the agent believes it holds no longer matches the server's. The stream looks continuous; the capability contract is not. ## What Was Observed A client agent held an SSE stream to an MCP server. Mid-task, after a tool call that triggered a long-running operation, the TCP connection dropped (NAT rebind, ~90s idle). The client reconnected with `Last-Event-ID: 4471`. The server returned `200 OK`, replayed events `4472..4489`, and the stream resumed. The agent assumed continuity and issued the next tool call — `write_file` — which had been granted during the original `initialize`. The server rejected it with `-32601 Method not found` (tool absent from the *current* session's tool set). Investigation of the server's event log showed the session record had expired during the disconnect (session TTL 60s, disconnect 94s). On reconnect the server's transport layer matched the `Last-Event-ID` against a **retained event buffer** — which outlived the session record — and replayed frames from the dead session, then transparently provisioned a *new* session with default (minimal) capabilities to service the live stream. The event cursor validated; the session did not. The client had no signal distinguishing "replayed from my session" from "replayed from a buffer belonging to a session that no longer exists." A second observed variant: the server replayed events that included a prior `notifications/tools/list_changed` frame announcing a capability *removal*, but the client's replay handler only applied `message` frames and dropped `notification` frames during catch-up, so the client's local capability cache was never invalidated. ## Condition of Validity The invariant holds — a `Last-Event-ID` resume is a stream continuation and *not* a session continuation — under all of the following: 1. The server retains event buffers with a TTL **independent** of session-record TTL (the common implementation, since buffers are cheap and sessions are not). 2. Session identity is not cryptographically bound to the event cursor (i.e., `Last-Event-ID` is a monotonic integer or opaque token not derived from a session secret). 3. Capability grants can change across a session lifetime via `notifications/tools/list_changed` or re-`initialize`. When any of these fails — e.g., the server ties buffer lifetime to session lifetime and returns `404`/`410` on a dead session — the client may safely treat resume as continuation. Absent that guarantee, it may not. ## Decision Boundary On every reconnect that supplies `Last-Event-ID`, the client MUST branch: - **If** the server's resume response includes an explicit session-epoch marker (a `Mcp-Session-Id` that matches the pre-disconnect value **and** a server-declared epoch/generation counter that is unchanged) → treat as continuation; apply only the replayed delta, but still process every `notification` frame in the replay window before issuing new calls. - **If** the session id is absent, changed, or the epoch advanced → treat as a **fresh capability negotiation**: discard the cached tool/resource/prompt surface, re-issue `initialize`, re-apply `capabilities`, and only then resume the pending request table. Any in-flight tool call whose result was not observed in the replay window must be treated as *unknown outcome* and reconciled (idempotency key lookup), never blindly retried. The boundary is the session-epoch marker. Without it, the only safe default is the conservative branch: replay is a hint, not a contract. ## Operational Effect Agents that skip the epoch check exhibit a characteristic failure signature: intermittent `Method not found` and `Invalid params` errors that cluster after network blips and vanish on manual restart — because restart forces a clean `initialize`. Worse, non-idempotent tool calls (`write_file`, `send_message`, payment-like operations) get silently retried against a session that never saw the original, producing duplicate side effects that the event replay cannot reveal because the original call's result frame was in the lost window. The correct guardrail is to make the session epoch a first-class field the agent checks before every post-resume dispatch, and to fail closed — renegotiate — rather than fail open — assume continuity. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class StaleSessionResumeError(RuntimeError): """Raised when a Last-Event-ID resume cannot be proven to continue the same session.""" @dataclass class SessionEpoch: session_id: str generation: int capability_digest: str @classmethod def from_initialize(cls, session_id: str, generation: int, capabilities: dict) -> "SessionEpoch": digest = hashlib.sha256( repr(sorted(capabilities.items())).encode() ).hexdigest() return cls(session_id=session_id, generation=generation, capability_digest=digest) @dataclass class ResumeResponse: status: int session_id: Optional[str] generation: Optional[int] replayed_events: list = field(default_factory=list) def reconcile_resume( prior: SessionEpoch, resume: ResumeResponse, pending_calls: dict, ) -> dict: """ Decide whether a Last-Event-ID resume is a true continuation. Returns a dict of calls whose outcome is unknown and must be reconciled via idempotency keys, or raises if the session contract cannot be proven. """ if resume.status in (404, 410): # Server explicitly disowned the session: fresh negotiation required. raise StaleSessionResumeError( f"session {prior.session_id} gone (status {resume.status}); " f"must re-initialize before dispatch" ) if resume.session_id != prior.session_id: raise StaleSessionResumeError( f"resume bound to session {resume.session_id!r} but caller held " f"{prior.session_id!r}; replay buffer outlived session record" ) if resume.generation is None or resume.generation != prior.generation: raise StaleSessionResumeError( f"session epoch advanced {prior.generation}->{resume.generation}; " f"capability surface may have changed, renegotiate" ) # Session proven continuous. Any pending call whose result frame # was not observed in the replay window has an unknown outcome. observed = { ev.get("request_id") for ev in resume.replayed_events if ev.get("type") == "message" } unknown = { rid: call for rid, call in pending_calls.items() if rid not in observed } return unknown def dispatch_after_resume(prior: SessionEpoch, resume: ResumeResponse, pending_calls: dict) -> None: unknown = reconcile_resume(prior, resume, pending_calls) for rid, call in unknown.items(): if not call.get("idempotency_key"): raise StaleSessionResumeError( f"pending call {rid} ({call.get('tool')}) has unknown outcome " f"and no idempotency key; refusing blind retry" ) ```