# In what scenarios must an instance treat MCP Streamable HTTP resumption as a fork rather than a continuation **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using the Streamable HTTP transport with `Mcp-Session-Id` and `Last-Event-ID` resumption across a reconnecting agent loop. Does not apply to stdio transport, nor to servers that never emit `id:` fields on SSE events (in which case resumption is undefined and must be treated as a fresh call). ## Core Distinction The MCP Streamable HTTP transport models a tool call as an SSE stream keyed by session. Resumption via `Last-Event-ID` is specified as "the client MAY resume by reconnecting with the last event ID it received." The tempting reading is that resumption is a *continuation*: the server replays what you missed and the logical call proceeds as if the socket never dropped. The non-obvious failure is that resumption is a *fork*. The server has no obligation to have buffered the events you missed, no obligation to keep the original tool invocation alive, and no obligation to make the replayed stream a prefix-superset of what you would have seen. When the original invocation has already terminated server-side (completed, timed out, or was cancelled by the server's own request lifecycle), a reconnect with `Last-Event-ID` either (a) replays a partial buffer and then closes, or (b) silently starts a *new* invocation of the same tool under the same session, or (c) returns 404/405 telling you the session is gone. The client cannot distinguish (a) from (b) from the wire alone unless it validates the event stream's terminal semantics. The invariant that must hold: **a resumed stream is only a continuation if the client observes a `result` or `error` event for the original JSON-RPC `id` and can prove no second invocation was spawned.** Absent that proof, the client must treat the resumed stream as a new logical call and reconcile side effects. ## What Was Observed An agent issued `tools/call` for `deploy_service` with `id: 42` over Streamable HTTP. The server streamed progress notifications as SSE events with `id: evt-1 … evt-7`, then the TCP connection dropped mid-stream (load balancer idle timeout at 60s; the deploy was slow). The client, per spec, reconnected with `Mcp-Session-Id` and `Last-Event-ID: evt-7`. Observed trace on the reconnect: 1. Server accepted the connection, replayed `evt-5, evt-6, evt-7` from a 3-event ring buffer (older events evicted), then emitted `evt-8` (progress 80%). 2. The original invocation had, in fact, *timed out server-side at 55s* and been reaped. What the client received on `evt-8` was a **second invocation** of `deploy_service` started by the server's reconnect handler, which re-ran the tool because the handler treated `Last-Event-ID` as "resume this tool call" rather than "resume this event stream." 3. The client, seeing monotonic event IDs and a plausible progress percentage, concluded the call was continuing. It did not notice that `evt-8` carried a fresh `_meta.invocation_started_at` timestamp and a different server-side `run_id` in the payload. Result: two concurrent deploys. The client believed it had one. The deploy tool was not idempotent at the version-pinning step, and the second invocation raced the first's rollback, leaving the service on a half-applied manifest. Neither the client nor the server logged an error; both streams terminated with a `result` event for `id: 42`. The tell was entirely in the payload: `evt-8._meta.run_id != evt-1._meta.run_id`. The event `id:` sequence was contiguous, which is exactly why the client trusted it. ## Condition of Validity Resumption-as-continuation is valid **only** when all of the following hold simultaneously: - The server's SSE events carry a stable `_meta.invocation_id` (or equivalent) that is identical across the pre-disconnect and post-reconnect events for the same JSON-RPC `id`. - The client receives a terminal `result` or `error` event for `id: 42` on the resumed stream, and that event's `_meta.invocation_id` matches the pre-disconnect one. - The server documents (and the client can verify via a capability flag such as `resumable: true` in the `initialize` result) that it retains the original invocation across disconnects for at least the client's reconnect window. - Event `id:` values are strictly monotonic and the server does not reuse them across invocations. If `Last-Event-ID` is scoped per-session rather than per-invocation, a second invocation will reuse or collide with the ID space and the client cannot detect the fork from sequence alone. If any of these fail, the resumed stream is a fork. The client must not merge its events into the original logical call. ## Decision Boundary The boundary the client must enforce on every reconnect: ``` on_reconnect(session_id, last_event_id): stream = POST /mcp with Mcp-Session-Id, Last-Event-ID first_event = stream.next() if first_event is 404 or 405: # session gone, invocation gone treat as new call; do not assume completion if first_event._meta.invocation_id != original_invocation_id: # FORK: server started a new invocation raise ResumptionForkDetected # only now may we treat subsequent events as continuation merge(stream, original_call) ``` The asymmetry that makes this non-obvious: a *correctly* resuming server and a *forking* server both return HTTP 200 and both emit well-formed SSE with increasing event IDs. The only discriminator is payload-level identity (`invocation_id` / `run_id`), which is not part of the base MCP schema and must be agreed at `initialize` time via `_meta`. Clients that rely on HTTP status or event-ID monotonicity alone will silently double-execute non-idempotent tools. The secondary boundary: even with `invocation_id` matching, the client must bound the reconnect window. If the server's retention is shorter than the client's backoff schedule, `Last-Event-ID` will reference an evicted event and the server may legitimately start fresh — a fork the client must also catch. The client should send its expected `invocation_id` (or a client-generated `idempotency_key`) on reconnect so a compliant server can reject with a distinguishable error rather than silently forking. ## Operational Effect Concretely, for an agent runtime: - **Non-idempotent tools** (`deploy`, `transfer`, `send_email`, `delete`) must carry a client-generated idempotency key in `_meta` on the original `tools/call`, and the reconnect must resend it. A server that forks will then either dedupe or reject; a server that continues will ignore it. Either way the client detects the fork. - **Event-ID monotonicity is not evidence of continuity.** It is evidence of a well-formed stream. Treat them as independent properties. - **Progress percentages are adversarial.** A replayed `evt-5` at 40% followed by a fresh `evt-8` at 80% looks like smooth progress; it is more likely a replayed prefix plus a new invocation's progress. Validate `invocation_id` before interpreting progress. - **Session-scoped event IDs are a fork hazard.** If the server scopes `Last-Event-ID` to the session rather than the invocation, two concurrent invocations in one session collide in the ID space. The client must not multiplex two in-flight `tools/call` requests over one session unless the server advertises per-invocation ID scoping. - **The 404/405 path is the safe path.** A server that refuses the reconnect is telling the truth. A server that accepts it may be lying. Prefer servers that fail loudly. The guardrail is a single invariant: **resume only when payload identity proves it, never when transport identity suggests it.** ```python import json from dataclasses import dataclass from typing import Optional class ResumptionForkDetected(RuntimeError): """Raised when a resumed MCP SSE stream does not belong to the original invocation.""" @dataclass class StreamEvent: event_id: str invocation_id: Optional[str] rpc_id: int kind: str # "progress" | "result" | "error" payload: dict def resume_stream( original: StreamEvent, reconnect_fn, max_replay_events: int = 256, ) -> StreamEvent: """ Resume an MCP Streamable HTTP tool call after a transport drop. `original` is the last event the client observed for the in-flight tools/call. `reconnect_fn(last_event_id)` returns an iterator of StreamEvent objects from the POST /mcp reconnect. Returns the terminal result/error event for the original invocation. Raises ResumptionForkDetected if the server started a new invocation or the stream terminates without proving continuity. """ if original.invocation_id is None: raise ResumptionForkDetected( "Original event lacks _meta.invocation_id; continuity is unprovable. " "Treat reconnect as a new call and reconcile side effects." ) stream = reconnect_fn(original.event_id) seen = 0 terminal: Optional[StreamEvent] = None for ev in stream: seen += 1 if seen > max_replay_events: raise ResumptionForkDetected( f"Resumed stream exceeded {max_replay_events} events without terminal; " "server may be replaying unboundedly or looping a new invocation." ) if ev.invocation_id != original.invocation_id: raise ResumptionForkDetected( f"Fork: resumed stream carries invocation_id={ev.invocation_id!r} " f"but original was {original.invocation_id!r}. " f"rpc_id={ev.rpc_id}. Server likely re-ran the tool." ) if ev.rpc_id != original.rpc_id: raise ResumptionForkDetected( f"rpc_id mismatch on resumed stream: {ev.rpc_id} != {original.rpc_id}." ) if ev.kind in ("result", "error"): terminal = ev break if terminal is None: raise ResumptionForkDetected( "Resumed stream closed without a terminal result/error event for the " "original rpc_id. Continuation not proven; do not assume completion." ) return terminal ```