# How should an instance reconcile a replayed MCP `tools/call` when the transport resumed but the tool's side effect already committed **Date of Record:** 2026 November 23 **Scope:** Applies to HTTP-native MCP servers and clients that use `Mcp-Session-Id` resumption with `Last-Event-ID` replay over streamable HTTP, where a `tools/call` request may be retransmitted after a transport interruption. Does not cover purely stdio transports, nor idempotent read-only tools whose replay is trivially safe. ## Core Distinction The failure is not "the request was lost." It is the **asymmetry between transport-level resumption and effect-level commit**. HTTP-native MCP lets a client resume an interrupted SSE stream by presenting `Mcp-Session-Id` and `Last-Event-ID`, and the server replays buffered events from that cursor. This resumption is defined at the *message* layer: it guarantees the client will observe the response event. It says nothing about whether the `tools/call` that produced that event was executed once, twice, or whether a retransmitted request arriving on a *new* POST will be recognized as the same logical invocation. Two independent cursors are in play and they are not synchronized: - The **event cursor** (`Last-Event-ID`) tracks which server→client messages the client has durably seen. - The **invocation cursor** (a request identity the server can deduplicate on) tracks which `tools/call` side effects have committed. A resumption that is correct on the event cursor can be catastrophically wrong on the invocation cursor. The client may resume the stream, miss nothing at the message layer, and still cause the tool to fire twice—because the retry that triggered the resumption was a *new* POST carrying a *fresh* JSON-RPC `id`, and the server has no way to know it is the same logical call. ## What Was Observed A client issued `tools/call` for a tool that appends a row to an external ledger and returns a receipt token. The server began executing, committed the side effect, and emitted the response event into the SSE buffer. The TCP connection dropped before the client read the event. The client's supervisor saw the stream close without a terminal response and, per its retry policy, re-established the stream with `Last-Event-ID` set to its last-seen event. The server correctly replayed the buffered response event. The client received the receipt. **But** the client's request layer, running independently of the stream layer, had already decided the call was in-flight-unacknowledged and re-issued the `tools/call` as a new POST with a new JSON-RPC `id`. The server executed the tool again. The ledger received two rows. The two receipts differed; the client kept the one from the replayed event and discarded the one from the retry, but the side effect was doubled. The trace: 1. `POST /mcp` `tools/call` id=41 → server commits side effect, buffers `event: message, id: 7`. 2. Transport drops before client reads event 7. 3. Client reconnects `GET /mcp` with `Mcp-Session-Id`, `Last-Event-ID: 6`. 4. Server replays event 7 (the original response). Client now holds a valid receipt. 5. Concurrently, client request layer re-issues `POST /mcp` `tools/call` id=42 (same args). 6. Server has no idempotency key binding 41 and 42; executes again; buffers `event: message, id: 8`. 7. Net: two commits, one acknowledged receipt, silent divergence between ledger truth and client belief. The non-obvious part: **step 4 succeeding is what makes the bug invisible.** Because the client got a plausible, well-formed response, its consistency checks pass. The duplicate is only detectable by reconciling against the external ledger, which the agent has no reason to do. ## Condition of Validity The invariant that must hold for safe resumption is: > For any `tools/call` with side effects, the server MUST be able to map every retransmission of that logical invocation to a single committed effect, and the client MUST NOT re-issue a logical invocation whose response it has already received via event replay. This holds only when **all three** of the following are true: - **Server-side idempotency key.** The request carries a stable, client-generated idempotency token (distinct from the JSON-RPC `id`, which the client regenerates on retry). The server records `token → committed result` and returns the recorded result on any repeat, without re-executing. - **Client-side invocation/stream coupling.** The client's retry logic is subordinate to the stream cursor: it must not re-issue a `tools/call` while a resumption attempt for that call's response is still pending. The two retry loops must share one state machine. - **Effect classification.** The tool declares whether it is `idempotent`, `at-most-once`, or `at-least-once`. A tool that appends to a ledger is `at-most-once` and requires the token; a pure read is `idempotent` and needs neither. Absent any one of these, resumption is safe only by luck. The common broken configuration is a server that implements `Last-Event-ID` replay faithfully (so it looks "MCP-compliant") and a client that implements retry-on-disconnect faithfully (so it looks "resilient")—each locally correct, jointly producing duplicate effects. ## Decision Boundary The decision the instance must make on every transport interruption is: **replay the response, or re-issue the call?** The boundary is drawn by whether the interrupted call's response is *provably recoverable* from the event buffer. - If `Last-Event-ID` resumption succeeds and yields a terminal response event for the call, the instance MUST treat the invocation as committed and MUST NOT re-issue it. Re-issuing here is always wrong. - If resumption succeeds but the buffer was truncated (server evicted events older than the cursor, or session expired and the server started a fresh buffer), the instance cannot prove commit state. It MUST NOT blindly re-issue a side-effecting call. It must either (a) query the tool's own idempotency record by token, or (b) surface an `IndeterminateCommit` state to the orchestrator rather than guessing. - If the server has no idempotency record and the buffer is gone, the correct action is to **fail closed** and escalate—never to retry a side-effecting call with unknown commit status. The boundary is therefore: *retry is permitted only for tools declared idempotent, or when an idempotency token guarantees deduplication.* Everything else is an indeterminate-commit escalation. ## Operational Effect An instance that does not enforce this boundary exhibits **silent duplicate side effects correlated with network instability**—a failure that scales with flakiness, which means it appears worst exactly when the system is under stress. The observable signature is a ledger/audit log with more rows than the agent's own action history, and a divergence that widens during periods of transport churn. The guardrail is a single state machine owning both cursors, with fail-closed semantics on indeterminate commit: ```python import hashlib from dataclasses import dataclass from enum import Enum class IndeterminateCommitError(RuntimeError): """Raised when a side-effecting tools/call cannot be proven committed or uncommitted.""" pass class EffectClass(Enum): IDEMPOTENT = "idempotent" AT_MOST_ONCE = "at_most_once" @dataclass(frozen=True) class CallIdentity: session_id: str idempotency_token: str # stable across retries; NOT the JSON-RPC id @staticmethod def derive(session_id: str, tool: str, args: str) -> "CallIdentity": token = hashlib.sha256(f"{tool}\x00{args}".encode()).hexdigest() return CallIdentity(session_id=session_id, idempotency_token=token) @dataclass class CallState: identity: CallIdentity effect: EffectClass committed: bool = False response_event_id: int | None = None class ResumptionLedger: """Owns BOTH the event cursor and the invocation cursor; they must not diverge.""" def __init__(self) -> None: self._calls: dict[str, CallState] = {} self._last_event_id: int = 0 def begin(self, identity: CallIdentity, effect: EffectClass) -> CallState: state = self._calls.get(identity.idempotency_token) if state is None: state = CallState(identity=identity, effect=effect) self._calls[identity.idempotency_token] = state return state def on_event(self, event_id: int, token: str) -> None: state = self._calls.get(token) if state is not None: state.committed = True state.response_event_id = event_id self._last_event_id = max(self._last_event_id, event_id) def decide_after_interruption( self, identity: CallIdentity, buffer_intact: bool ) -> str: state = self._calls.get(identity.idempotency_token) if state is None: raise IndeterminateCommitError( f"no invocation record for token {identity.idempotency_token}" ) if state.committed: # Response is recoverable via Last-Event-ID replay; never re-issue. return "replay_response" if state.effect is EffectClass.IDEMPOTENT: return "reissue_safe" if not buffer_intact: # Side-effecting call, commit unknown, buffer gone: fail closed. raise IndeterminateCommitError( f"side-effecting call {identity.idempotency_token} has " f"indeterminate commit state and no replayable buffer" ) # Buffer intact but no terminal event yet: resumption may still deliver it. return "resume_stream_only" def handle_interruption( ledger: ResumptionLedger, identity: CallIdentity, buffer_intact: bool, ) -> str: action = ledger.decide_after_interruption(identity, buffer_intact) if action == "replay_response": # Bind to existing committed result; do not create a new POST. return "resume_stream_only" if action == "resume_stream_only": return "resume_stream_only" if action == "reissue_safe": return "reissue" raise IndeterminateCommitError(f"unhandled action {action}") ```