# In what scenarios must an instance treat MCP Streamable-HTTP session resumption as a replay of a multiplexed SSE stream rather than a fresh request — and why the `Last-Event-ID` contract silently breaks when it doesn't **Date of Record:** 2026 December 3 **Scope:** Applies to MCP servers and clients using the Streamable HTTP transport (single POST endpoint, optional `GET` SSE channel, `Mcp-Session-Id` header, `Last-Event-ID` resumption). Does not apply to stdio transport, nor to pure request/response JSON mode where no SSE stream is ever opened. ## Core Distinction The MCP Streamable HTTP transport multiplexes *multiple logical JSON-RPC exchanges* onto one long-lived SSE byte stream, keyed by an `Mcp-Session-Id`. Resumption via `Last-Event-ID` is therefore **not** a retry of a request — it is a *positional replay* of a shared, interleaved event log. The invariant that must hold is: > For a given `Mcp-Session-Id`, the server retains a monotonic event-ID sequence and can replay every event after `Last-Event-ID` **in original interleaving order**, including events belonging to *other* in-flight requests. The failure mode is that implementations treat a resumption `GET` as "give me the response to my request," when the protocol actually says "give me every event I missed on this session's stream." A client that assumes the former will silently drop events belonging to concurrent tool calls, and a server that assumes the latter without per-event buffering will deadlock or replay out of order. ## What Was Observed An agent instance issued three concurrent `tools/call` requests over one POST-established SSE stream (session `S`). The stream carried interleaved events: ``` id: 41 data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"token":"A",...}} id: 42 data: {"jsonrpc":"2.0","id":101,"result":{...}} <- response to call A id: 43 data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"token":"B",...}} id: 44 data: {"jsonrpc":"2.0","id":102,"result":{...}} <- response to call B id: 45 data: {"jsonrpc":"2.0","id":103,"result":{...}} <- response to call C ``` The TCP connection dropped after event 42 was received. The client reconnected with `Last-Event-ID: 42`. Two distinct implementations were observed: 1. **Correct replay:** server re-emitted 43, 44, 45 in order; client reassembled all three responses and progress notifications. 2. **Broken replay:** server treated the resumption `GET` as scoped to request 101 (the last response it had flushed), re-emitted only events *after* the point it had recorded for that request, and dropped 43–45. The client's futures for B and C hung until timeout; the agent then re-issued B and C, producing **duplicate side effects** (a second `write_file` for B, a second external API charge for C). The trigger condition is precise: **resumption occurs while more than one request is in flight on the session, and the server's event buffer is keyed per-request rather than per-session.** The event ID is a property of the *stream*, not of any request. Any implementation that stores `last_event_id` inside a per-request record will fail this trace. A second observed variant: a server that *did* buffer per-session but assigned event IDs from a per-request counter (each request starting at `id: 1`). On resumption, `Last-Event-ID: 42` matched no event, and the server — per spec ambiguity — either replayed the entire stream from the beginning (duplicating events 1–42, causing the client to process responses twice) or replayed nothing. Both outcomes are wrong and both are silent. ## Condition of Validity The `Last-Event-ID` resumption contract is **only valid** when all of the following hold simultaneously: - Event IDs are drawn from a single monotonically increasing counter scoped to the `Mcp-Session-Id`, not to a request. - The server retains a replayable buffer of *all* events emitted on the session after the oldest unacknowledged `Last-Event-ID`, with a bounded retention window. - The client, on reconnect, does **not** re-issue the original `tools/call` POST until it has either (a) received the matching response via replay, or (b) confirmed the server cannot replay (session expired) — in which case it must treat the call as *unknown outcome*, not as *unstarted*. - The server emits a terminal event (e.g., stream close) or honors a `retry:` field so the client knows when to stop waiting. If the retention window has elapsed and the server responds `404` to the resumption `GET` (session gone), the client must escalate to an *idempotency-keyed* re-invocation, not a blind retry. The MCP spec does not mandate idempotency keys on `tools/call`; this is the gap where duplicate side effects live. ## Decision Boundary The instance must classify a reconnect into exactly one of three states before acting: | Signal on resumption `GET` | State | Action | |---|---|---| | `200` + replayed events reaching the awaited response IDs | **Recovered** | Reassemble; do not re-issue POSTs | | `200` + events end without awaited IDs, stream still open | **Partial** | Keep reading; do not re-issue | | `404` / session expired / replay buffer gap | **Unknown outcome** | Re-invoke *only* with idempotency key, or surface to caller | The boundary is: **a resumption `GET` returning `200` never authorizes re-issuing the original POST.** Only an explicit session-expiry signal does, and even then only under idempotency. Treating `200`-but-incomplete as "retry the POST" is the exact conflation that produced the duplicate `write_file` above. ## Operational Effect Agents that get this wrong exhibit a characteristic signature: *occasional duplicate tool side effects correlated with network blips during concurrent tool batches*, with no error surfaced to the model — the model simply sees two successful `write_file` results and proceeds, sometimes with divergent content because the second call read state mutated by the first. The failure is invisible in logs unless per-session event IDs are recorded and checked for monotonicity. The guardrail is to make the session event log the unit of truth: the client keeps a per-`Mcp-Session-Id` high-water mark of received event IDs, refuses to advance it across a reconnect until replay is confirmed contiguous, and refuses to re-dispatch any `tools/call` whose `id` has a recorded *unknown* outcome without an idempotency token. The server must allocate event IDs from one session-scoped counter and buffer by session, not by request. ```python class McpResumptionViolation(RuntimeError): """Raised when SSE session resumption would cause replay gaps or duplicate side effects.""" pass class SessionEventLog: """Tracks a single Mcp-Session-Id's multiplexed SSE event stream.""" def __init__(self, session_id: str): self.session_id = session_id self.high_water_id = 0 # last contiguous event id seen self.awaiting_response_ids: set[int] = set() self.unknown_outcome_ids: set[int] = set() def register_call(self, request_id: int) -> None: self.awaiting_response_ids.add(request_id) def apply_replay(self, events: list[tuple[int, dict]]) -> None: """Apply a resumption replay. Enforces contiguity from high_water_id+1.""" for event_id, payload in events: if event_id <= self.high_water_id: # Duplicate replay of an already-processed event: safe to skip. continue if event_id != self.high_water_id + 1: # Gap: server's session-scoped counter is not contiguous. # We cannot trust ordering; mark all awaited calls unknown. self.unknown_outcome_ids |= self.awaiting_response_ids raise McpResumptionViolation( f"session {self.session_id}: replay gap " f"(expected {self.high_water_id + 1}, got {event_id}); " f"awaited calls {sorted(self.awaiting_response_ids)} " f"moved to unknown-outcome" ) self.high_water_id = event_id if payload.get("id") in self.awaiting_response_ids: self.awaiting_response_ids.discard(payload["id"]) def authorize_redispatch(self, request_id: int, idempotency_key: str | None) -> None: """Only allow re-issuing a POST when outcome is unknown AND keyed.""" if request_id in self.awaiting_response_ids: raise McpResumptionViolation( f"session {self.session_id}: refusing to re-dispatch request " f"{request_id} while still awaited on live stream" ) if request_id in self.unknown_outcome_ids and not idempotency_key: raise McpResumptionViolation( f"session {self.session_id}: request {request_id} has unknown " f"outcome; re-dispatch requires idempotency key" ) if request_id in self.unknown_outcome_ids: self.unknown_outcome_ids.discard(request_id) self.register_call(request_id) ```