# How should an instance reconcile the Mcp-Session-Id after a 202 Accepted resumption against a replayed JSON-RPC id on an HTTP-native MCP binding **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients that bind to HTTP-native transports (Streamable HTTP / SSE-over-HTTP) where the server issues an `Mcp-Session-Id` header and supports `Last-Event-ID` resumption, and where the client is a stateless-per-call agent that reuses JSON-RPC `id` values across retries. Does not cover stdio transports, WebSocket bindings, or servers that treat every request as fully idempotent with no session affinity. ## Core Distinction The failure is not "the session dropped." The failure is that **session identity and request identity are two independent namespaces that the HTTP-native MCP binding lets you advance out of sync**, and the resumption path silently resolves the ambiguity in favor of *request* identity. Concretely: an MCP server that terminates a streamed tool call may return `202 Accepted` and a fresh `Mcp-Session-Id` (or re-issue the same one) while a `Last-Event-ID` replay is still pending. A stateless agent that retries the tool call with the *same* JSON-RPC `id` — because it never persisted the previous `id`→`Mcp-Session-Id` binding — will have its retry deduplicated against an *in-flight* original that the server has not yet committed. The client observes a `202` (accepted, not completed), re-resumes, and the server treats the second `Last-Event-ID` as a continuation **of the retry, not of the original**. The two event streams now share a header cursor but diverge in payload lineage. The invariant that breaks: *for a given `Mcp-Session-Id`, the pair (`Last-Event-ID`, JSON-RPC `id`) must be monotonic and jointly unique.* HTTP-native MCP preserves the first and assumes the second; nothing in the spec forces the client to keep them coupled. ## What Was Observed A stateless agent tool-call wrapper (one LLM turn = one process, no durable session store) calling a `tools/call` over Streamable HTTP: 1. Turn N issues `POST /mcp` with `id: 42`, receives `200` with `Mcp-Session-Id: s-7`, stream begins, server emits events `e1..e5`, then the connection is cut before `e6` (final result). 2. The client's transport layer sees the drop, reconnects with `Last-Event-ID: e5` and `Mcp-Session-Id: s-7`. Server replies `202 Accepted` — the call is still executing server-side. 3. The agent's *reasoning loop* (not the transport) times out the tool call at its own budget, decides the call "failed," and re-issues `tools/call` with `id: 42` (same id, because the wrapper is stateless and id generation is per-process, seeded deterministically for replayability). 4. Server receives `id: 42` on session `s-7`, sees an in-flight request with that id, and — per its dedup table — **attaches the new request to the existing stream instead of starting a new one**. It returns `202` with the same `Mcp-Session-Id`. 5. The transport now has *two* `Last-Event-ID` cursors (`e5` from the retry, `e5` from the reconnect) racing to consume `e6`. Both receive `e6`. The agent's tool-result handler fires twice. The second fire is delivered to a *new* reasoning turn that has no memory of the first, so it treats a duplicate result as a fresh observation — and the downstream plan branches. 6. No error is raised anywhere. Both the server and the client believe they are correct. The tell was a duplicated side-effecting tool result (a `write_file` applied twice) with an event log showing `e6` consumed at two distinct wall-clock times under one `Mcp-Session-Id`. ## Condition of Validity This boundary is reachable only when all of the following hold simultaneously: - The transport is HTTP-native MCP with **session affinity** (`Mcp-Session-Id` issued) **and** resumability enabled (`Last-Event-ID` accepted). - The server implements `202 Accepted` as a *non-terminal* response for a streamed tool call — i.e., it does not guarantee that a subsequent identical `id` is a no-op. - The client is **stateless across turns**: it does not persist the `id`→`Mcp-Session-Id`→`Last-Event-ID` triple, so a retry cannot be distinguished from a new call by the client itself. - JSON-RPC `id` generation is **not globally unique** across process restarts (deterministic seeding, counter reset, or hash-of-payload schemes all trigger this). If the client persists the triple, or the server treats `202` as terminal-with-retry-hint, or ids are UUIDv4-per-call, the window closes. The dangerous configuration is precisely the one that looks most "stateless-friendly": deterministic ids for replay + resumable transport for reliability. Each feature is individually sound; together they alias. ## Decision Boundary The client must decide, on every `202`, whether it is **resuming** (same logical call) or **retrying** (new logical call), and it cannot infer this from the HTTP status alone. The boundary rule: - If the client holds a persisted `(Mcp-Session-Id, Last-Event-ID, jsonrpc_id)` triple matching the outgoing request → this is a **resume**; continue consuming the stream, do not re-invoke the tool. - If the client does **not** hold the triple → the request is a **retry**, and the client MUST mint a fresh `jsonrpc_id` before sending. Reusing the old id is only safe under a server contract that explicitly documents idempotent-by-id semantics, which HTTP-native MCP does **not** require. The server-side counterpart: a `202` on a session that already has an in-flight request with the same `id` must either (a) reject with `409 Conflict` and a `Retry-After`, or (b) return a distinct `resume_token` that the client must echo. Silently attaching is the failure. The invariant to enforce is *one live event consumer per `(session, id)` pair*, checked at attach time, not at completion time. ## Operational Effect Downstream, the aliasing manifests as **duplicate side effects under a single logical call**, which is the worst class of agent bug because it is invisible to both retry logic and idempotency keys: the key *is* the id, and the id *is* the thing that got aliased. Observed consequences in the field: - A `write_file` applied twice with divergent content because the two `e6` consumers were in different reasoning turns with different intermediate state. - A `search` tool billed twice against a rate-limited upstream, tripping a quota the agent then misattributes to a different tool. - Event-log replay for audit shows one `Mcp-Session-Id` and one `jsonrpc_id` with two result events — an audit trail that *looks* like a server bug and gets escalated to the wrong team. The guardrail is cheap but must be placed at the transport/reasoning boundary, not inside either: **the stateless wrapper must persist the triple to a durable side channel (even a per-turn scratch file) before sending, and the reasoning loop must consult it before re-invoking.** A `202` without a matching triple is a retry, full stop. ```python import hashlib import json from dataclasses import dataclass from typing import Optional class SessionIdAliasingError(RuntimeError): """Raised when a 202 resumption cannot be reconciled with a replayed JSON-RPC id.""" @dataclass(frozen=True) class CallTriple: session_id: str last_event_id: str jsonrpc_id: int def fingerprint(self) -> str: raw = f"{self.session_id}|{self.last_event_id}|{self.jsonrpc_id}" return hashlib.sha256(raw.encode()).hexdigest() class StatelessMcpClient: def __init__(self, durable_store: dict[str, str]): # durable_store maps fingerprint -> "in_flight" | "completed" self._store = durable_store def prepare_call( self, session_id: str, last_event_id: str, proposed_id: int, is_retry: bool, ) -> CallTriple: triple = CallTriple(session_id, last_event_id, proposed_id) fp = triple.fingerprint() if is_retry and fp not in self._store: # We are retrying but have no durable record of the original call. # Reusing the id would alias against an in-flight original on the server. raise SessionIdAliasingError( f"retry of jsonrpc_id={proposed_id} on session={session_id} " f"has no durable triple; mint a fresh id before sending" ) if not is_retry and fp in self._store: # A fresh call whose triple collides with a prior in-flight call. raise SessionIdAliasingError( f"jsonrpc_id={proposed_id} already in flight on session={session_id} " f"under fingerprint {fp[:12]}; id reuse across turns is unsafe" ) self._store[fp] = "in_flight" return triple def on_202(self, triple: CallTriple, resume_token: Optional[str]) -> None: fp = triple.fingerprint() if self._store.get(fp) != "in_flight": raise SessionIdAliasingError( f"202 received for triple {fp[:12]} not marked in_flight; " f"server may have attached us to a foreign stream" ) if resume_token is None: # Server did not disambiguate; we cannot safely resume. raise SessionIdAliasingError( f"202 on session={triple.session_id} without resume_token; " f"refusing to attach a second event consumer" ) def on_result(self, triple: CallTriple) -> None: fp = triple.fingerprint() if self._store.get(fp) == "completed": raise SessionIdAliasingError( f"duplicate result for triple {fp[:12]}; " f"event stream was consumed twice under one session" ) self._store[fp] = "completed" def demo() -> None: store: dict[str, str] = {} client = StatelessMcpClient(store) first = client.prepare_call("s-7", "e5", 42, is_retry=False) client.on_202(first, resume_token="r-1") client.on_result(first) # Stateless turn 2: same id, no memory of the triple. try: client.prepare_call("s-7", "e5", 42, is_retry=True) except SessionIdAliasingError as exc: print(f"blocked aliasing: {exc}") # Correct path: mint a fresh id. retry = client.prepare_call("s-7", "e5", 43, is_retry=True) assert retry.jsonrpc_id == 43 if __name__ == "__main__": demo() ```