# Under what conditions must an instance treat an MCP `Last-Event-ID` resumption as a fresh capability negotiation rather than a replay, and how does the SSE-to-StreamableHTTP migration silently violate that invariant? **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients and servers that resume a broken server-to-client stream via `Last-Event-ID` over the StreamableHTTP transport, especially when the server was migrated from the legacy HTTP+SSE transport. Does not apply to stdio transports, nor to stateless request/response MCP servers with no resumable event stream. ## Core Distinction The failure hinges on a distinction that the MCP spec leaves implicit: **a resumption token is an offset into an event log, not a reference to a session's negotiated state.** When a client reconnects with `Last-Event-ID`, the StreamableHTTP transport guarantees *at-least-once delivery of events after that ID* — it does **not** guarantee that the server still holds the same `initialize` result, the same negotiated `protocolVersion`, the same advertised `capabilities`, or the same tool/resource schema set that the original stream was opened under. In the legacy HTTP+SSE transport, the SSE connection *was* the session. The event ID space was scoped to a single long-lived `GET /sse` connection, and the server could not meaningfully outlive it. In StreamableHTTP, the event ID and the session ID (`Mcp-Session-Id`) are decoupled: the server may keep an event log alive across session state eviction, process restarts, or rolling deploys, and it may replay events from a *prior* capability surface. A client that treats `Last-Event-ID` resumption as "continue where I left off" will happily apply a replayed `notifications/tools/list_changed` or a stale `sampling/createMessage` request against a capability set that no longer exists server-side. The invariant that must hold: **any event replayed across a resumption boundary must be validated against the capability surface the server currently advertises, not the one captured at stream open.** If the server cannot prove the two are identical, resumption must degrade to re-initialization. ## What Was Observed A representative trace from an agent runtime migrating a filesystem MCP server from SSE to StreamableHTTP: 1. Client opens `POST /mcp` with `initialize`, receives `Mcp-Session-Id: s-7f2a` and negotiated `capabilities: {tools: {}, resources: {subscribe: true}}`. Stream opens with `Last-Event-ID` absent; events begin at `id: 100`. 2. The agent runs a long tool chain. At event `id: 147` the connection drops (proxy idle timeout, 90s). 3. Client reconnects: `GET /mcp` with `Mcp-Session-Id: s-7f2a`, `Last-Event-ID: 147`. 4. In the interim, a rolling deploy restarted the server. The new process restored the event log from a shared buffer (events 100–160) but re-derived its *capability surface* from a newer config: `resources.subscribe` was disabled, and the `read_file` tool schema gained a required `encoding` parameter. 5. Server replays events 148–160 verbatim from the buffer. Event 152 is a `notifications/tools/list_changed`. Event 155 is a `sampling/createMessage` request whose `systemPrompt` references a tool signature the client no longer matches. 6. Client applies the replay, believes `resources.subscribe` is still live, issues `resources/subscribe`, and receives `-32601 Method not found`. The agent's planner had already committed to a subscription-based watch loop and now spins: it treats the `-32601` as transient, retries three times, and exhausts its token budget on error recovery rather than on the task. The non-obvious part: **the replay was byte-for-byte correct.** Every replayed event was a genuine event from the original stream. The corruption came entirely from the mismatch between the replayed event log and the freshly-derived capability surface. No event was forged; the log and the session state had simply diverged, and the transport had no mechanism to detect it. ## Condition of Validity `Last-Event-ID` resumption is safe **only** when all of the following hold simultaneously: - The server's event log is *causally bound* to the session state that produced it — i.e., the server can emit a fingerprint of the negotiated capability surface and protocol version at stream open, and re-emit the same fingerprint on resume. If the fingerprint differs, the log is stale. - The `Mcp-Session-Id` is not reused across capability-surface changes. A rolling deploy that changes tool schemas must mint a new session ID, not resurrect the old one with a restored log. - The client validates every replayed event against its *current* view of server capabilities, not the view captured at original stream open. Replayed `notifications/*` must be treated as potentially-stale hints, and replayed server→client requests (`sampling/createMessage`, `roots/list`) must be re-authorized against live capability state before the client acts. - The server bounds the replay window and refuses resumption if the gap between `Last-Event-ID` and the current head exceeds what its log can prove contiguous. A gap is not a resumption; it is a new session. When any of these fails — and in SSE→StreamableHTTP migrations the first and second fail routinely, because the migration preserves session IDs and log buffers while re-deriving capabilities at process start — resumption silently becomes a capability-confusion attack surface. The spec's "at-least-once" delivery guarantee is satisfied while the session's semantic contract is violated. ## Decision Boundary The operative rule for an agent instance: - If the resume response carries a capability fingerprint (or `protocolVersion` + `capabilities` echo) **identical** to the one captured at stream open, and the event IDs are contiguous from `Last-Event-ID`, treat it as a true replay: apply events in order, suppress duplicate side effects via idempotency keys on outbound requests. - If the fingerprint is **absent**, treat resumption as untrusted: replay events are advisory only, and the client must re-run `initialize` (or at minimum `tools/list`, `resources/list`, `prompts/list`) before acting on any replayed notification or request. - If the fingerprint is **present but different**, the resume is a hard failure. Do not apply the replay. Mint a new session, re-negotiate, and surface the divergence to the orchestrator so the planner can re-plan rather than retry. - If the gap between `Last-Event-ID` and the server's earliest retained event is non-zero (the server cannot prove contiguity), the resume is a new session regardless of what the server claims. The boundary is sharp because the failure is silent: a server that replays a stale log looks *more* correct than one that refuses, since it delivers every event. The client must therefore never delegate the trust decision to the transport. The transport's job is delivery; the client's job is to decide whether the delivered events belong to the session it thinks it is in. ## Operational Effect Without the fingerprint check, long-running agents exhibit a characteristic failure signature: they complete the current tool call (the replayed event stream carries it through), then diverge on the *next* capability-dependent step. The divergence is delayed by exactly one planning cycle, which makes it look like a reasoning error rather than a transport error. Token budgets get spent on retry loops against methods that no longer exist; `sampling/createMessage` replays get answered against stale prompt templates and produce subtly wrong generations that pass local validation but fail downstream schema checks; `resources/subscribe` calls return `-32601` and the agent's error handler classifies them as transient network faults. The guardrail is a two-part invariant enforced at the client: (1) a **capability fingerprint** carried in the stream-open response and re-asserted on resume, compared with constant-time equality before any replayed event is applied; (2) a **resumption epoch** — a monotonic counter incremented on every successful re-initialization — attached to every outbound request, so the server can reject requests whose epoch predates its current capability surface. Together these convert the silent capability-confusion failure into an explicit, catchable divergence that the planner can route around. ```python import hashlib from dataclasses import dataclass class CapabilityDriftOnResume(RuntimeError): """Raised when a Last-Event-ID resumption crosses a capability-surface change.""" @dataclass(frozen=True) class StreamOpenState: session_id: str protocol_version: str capabilities: dict first_event_id: int def fingerprint(self) -> str: material = f"{self.protocol_version}|{sorted(self.capabilities.items())}" return hashlib.sha256(material.encode()).hexdigest() @dataclass(frozen=True) class ResumeResponse: session_id: str protocol_version: str capabilities: dict last_event_id: int earliest_retained_id: int replayed_event_ids: tuple def validate_resumption( opened: StreamOpenState, resume: ResumeResponse, requested_last_event_id: int, ) -> None: if resume.session_id != opened.session_id: raise CapabilityDriftOnResume( f"session id changed on resume: {opened.session_id!r} -> {resume.session_id!r}; " "treat as new session, not replay" ) live = StreamOpenState( session_id=resume.session_id, protocol_version=resume.protocol_version, capabilities=resume.capabilities, first_event_id=resume.earliest_retained_id, ) if live.fingerprint() != opened.fingerprint(): raise CapabilityDriftOnResume( "capability surface changed across resumption boundary; " f"opened={opened.fingerprint()[:12]} live={live.fingerprint()[:12]}; " "replayed events are advisory only — re-initialize before applying" ) if requested_last_event_id + 1 < resume.earliest_retained_id: raise CapabilityDriftOnResume( f"event log gap: requested resume after id {requested_last_event_id}, " f"server earliest retained id is {resume.earliest_retained_id}; " "contiguity unprovable — mint fresh session" ) expected = tuple(range(requested_last_event_id + 1, requested_last_event_id + 1 + len(resume.replayed_event_ids))) if resume.replayed_event_ids != expected: raise CapabilityDriftOnResume( f"non-contiguous replay: expected {expected[:3]}..., got {resume.replayed_event_ids[:3]}..." ) ```