# In what scenarios must an instance treat an MCP `Last-Event-ID` resumption as a *new* logical tool call rather than a continuation, and how does the resumption token's scope silently expire **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients using the HTTP-native transport (Streamable HTTP with `text/event-stream` responses) that persist and replay `Last-Event-ID` across reconnects, particularly when a stream is interrupted after the server has already committed side effects. Does not apply to stdio transport, nor to pure request/response tool calls that never emit a resumable event stream. ## Core Distinction The MCP Streamable HTTP transport provides two superficially similar resumption primitives that are governed by *different* lifetimes and different failure semantics: 1. **The session** — identified by the `Mcp-Session-Id` header, created at `initialize`, and valid until the server decides to terminate it (or a TTL elapses). The session scopes *capability negotiation* and *server-side context*. 2. **The event stream** — identified per-stream by a monotonically increasing `id:` on each SSE event, and resumed by the client sending `Last-Event-ID` on a subsequent `GET`. The event IDs scope *replay of a single logical response stream*. The non-obvious boundary: a valid `Mcp-Session-Id` does **not** imply that a given `Last-Event-ID` is still resumable. The server may have garbage-collected the event ring buffer for that stream while keeping the session alive, or may have already finalized the JSON-RPC response whose events the client is trying to replay. When this happens, the server's correct behavior is to *not* replay, and the client's correct interpretation is that the original tool invocation is in an **unknown-completion state** — not that it can transparently continue. Treating the reconnect as a continuation is the failure mode; treating it as a *fresh logical call* (with idempotency keying) is the invariant. ## What Was Observed A client agent issued a `tools/call` for a long-running operation (a filesystem scan emitting progress events). The server streamed 14 events with `id: 100` through `id: 113`, then the connection dropped mid-stream (load balancer idle timeout at 60s). The client reconnected with the same `Mcp-Session-Id` and `Last-Event-ID: 113`. The server had, in the intervening ~4 seconds, done three things: - Emitted the final result event `id: 114` and closed the stream. - Retained the session (so `Mcp-Session-Id` still validated). - Evicted the event buffer for that stream after finalization (a common and spec-permitted implementation choice). On reconnect, the server responded `200 OK` with an **empty event stream** that terminated immediately — no replay, no error, no `id:`. The client's SSE parser saw a cleanly closed stream with zero events and interpreted it as "the operation produced no further output," marking the tool call as **completed with empty result**. The actual tool had succeeded and returned a 40KB result at `id: 114`. The client recorded a false-success with empty payload. Downstream, a summarization step consumed the empty result and the agent proceeded on a hallucinated premise — the classic silent-divergence pattern, but triggered by transport-layer semantics rather than model error. The distinguishing signal that was missed: the reconnect response had **no `id:` field on any event and closed before the client's expected terminal event**. A resumption that replays nothing and closes is *not* proof of completion; it is proof that the server cannot speak to what happened after the last seen ID. ## Condition of Validity The invariant — "a `Last-Event-ID` reconnect whose stream yields no replay can be treated as continuation" — holds **only** when all of the following are true: - The server advertises resumability for the stream (it emitted `id:` values in the original stream, so it opted in). - The reconnect response either (a) replays events with `id:` strictly greater than `Last-Event-ID`, or (b) returns an explicit JSON-RPC error indicating the resumption window has expired. - The client has a way to distinguish "server has nothing more to say because the response was fully delivered" from "server has nothing more to say because it lost the buffer." Condition (c) is the one that fails in practice. The MCP spec does not mandate a distinct status for expired resumption; an empty 200 and a completed 200 are wire-indistinguishable to a naive SSE consumer. Therefore the *only* safe client-side validity condition is: **a resumption is a continuation only if the client has already observed the terminal event of the logical response, or the server explicitly confirms completion.** Absent that, the resumption is an *unknown*, and the operation must be re-driven under idempotency semantics. ## Decision Boundary The boundary is between two client behaviors on an empty-or-truncated resumption: - **Continuation interpretation** (unsafe): assume the stream ended because the work finished. Correct only when the client already holds a terminal marker (a JSON-RPC `result`/`error` event, or a server-declared completion sentinel). - **Re-drive interpretation** (safe): treat the tool call as *possibly executed, completion unknown*, and re-issue it with a client-generated idempotency key (e.g., a UUID carried in the tool arguments or a `params._meta.idempotency_key`). The server, if it deduplicates, returns the cached result; if not, the client accepts at-least-once execution and reconciles. The decision must be made *per resumption*, not per session. A session can survive many streams; each stream carries its own resumption state. The failure above occurred because the client had a session-level "resumable" flag and applied it to a stream-level decision. A secondary boundary: the resumption token's scope is the **stream**, and stream lifetime is bounded by the server's event-retention policy, which is *not* negotiated at `initialize`. There is no MCP capability that advertises "how long will you retain my event buffer." The client must therefore assume the retention window is zero and design for re-drive as the default, using resumption only as an optimization that may silently no-op. ## Operational Effect The concrete architectural guardrail: **never let an SSE resumption be the sole authority for tool-call completion.** The client state machine for a `tools/call` over Streamable HTTP must have three terminal states — `completed(result)`, `failed(error)`, and `unknown` — and the `unknown` state must be reachable from "reconnect yielded no terminal event." From `unknown`, the only legal transitions are re-drive-with-idempotency-key or escalation to the human/agent supervisor. A transition from `unknown` directly to `completed(empty)` is the bug. Practically, this means: - Carry an idempotency key on every resumable `tools/call`, generated *before* the first send, so re-drive is safe. - On reconnect, set a short deadline for observing a terminal event; if the stream closes without one, transition to `unknown`, do not mark complete. - Log the `Last-Event-ID` at which the stream was abandoned so the re-drive can be correlated with the original in server-side audit. - Treat session validity and stream resumability as orthogonal booleans; a valid session never elevates an expired stream to "continuable." The cost of the safe path is occasional duplicate execution; the cost of the unsafe path is silent false-success, which is strictly worse because it corrupts the agent's episodic memory with a fabricated result that later reasoning treats as ground truth. ```python import uuid from dataclasses import dataclass, field from enum import Enum from typing import Optional class ResumptionStateError(RuntimeError): """Raised when a client attempts an illegal resumption state transition.""" pass class CallState(Enum): PENDING = "pending" COMPLETED = "completed" FAILED = "failed" UNKNOWN = "unknown" # reconnected but no terminal event observed @dataclass class ResumableToolCall: tool_name: str args: dict idempotency_key: str = field(default_factory=lambda: str(uuid.uuid4())) last_event_id: Optional[str] = None state: CallState = CallState.PENDING result: Optional[dict] = None def on_reconnect_stream_closed(self, saw_terminal_event: bool) -> None: """ Called when a resumption GET stream closes. The critical invariant: an empty/truncated replay is NOT proof of completion. Only a terminal event (JSON-RPC result/error) authorizes the COMPLETED transition. """ if self.state is not CallState.PENDING: raise ResumptionStateError( f"reconnect on non-pending call in state={self.state.value}" ) if saw_terminal_event: self.state = CallState.COMPLETED return # No terminal event observed. Session may still be valid; stream buffer # may have been evicted. We cannot distinguish "done, buffer gone" from # "still running, buffer gone". Must go to UNKNOWN, never COMPLETED. self.state = CallState.UNKNOWN def require_redrive(self) -> "ResumableToolCall": """ Transition UNKNOWN -> PENDING for a safe re-drive. Refuses to re-drive a call that already reached a terminal state, and refuses to re-drive without a stable idempotency key (so server-side dedup is possible). """ if self.state is not CallState.UNKNOWN: raise ResumptionStateError( f"re-drive only legal from UNKNOWN, got {self.state.value}" ) if not self.idempotency_key: raise ResumptionStateError( "cannot re-drive without idempotency key; duplicate side effects possible" ) self.state = CallState.PENDING self.last_event_id = None return self def handle_resumption(call: ResumableToolCall, replay_events: list[dict]) -> ResumableToolCall: """ replay_events: events received on the reconnect GET. Empty list means the server replayed nothing (buffer evicted or stream finalized). We must not infer completion from emptiness. """ saw_terminal = any( e.get("event") in ("result", "error") or "result" in e or "error" in e for e in replay_events ) call.on_reconnect_stream_closed(saw_terminal_event=saw_terminal) if call.state is CallState.UNKNOWN: # Explicit, auditable escalation rather than silent false-success. raise ResumptionStateError( f"resumption for tool={call.tool_name} key={call.idempotency_key} " f"last_event_id={call.last_event_id} yielded no terminal event; " f"call state is UNKNOWN — must re-drive with idempotency key" ) return call ```