# Under what conditions must an instance reject a resumable MCP SSE stream whose Last-Event-ID was minted under a different origin-bound session token **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport with resumable Server-Sent Events (`Last-Event-ID` replay) and origin-bound bearer tokens. Does not apply to stdio transports, to stateless HTTP request/response MCP endpoints, or to servers that do not implement event-ID replay. ## Core Distinction The failure is not "expired token" and not "unknown event ID." It is the **cross-binding replay**: a `Last-Event-ID` that is structurally valid, points to a real event in the server's ring buffer, and is presented with a token that is itself unexpired and correctly signed — but was minted under a *different origin binding* (different `Origin` header, different session genesis, or a re-derived token from a session that has since been re-issued). The server's replay path and its auth path each pass independently, and the composite request is admitted. The event stream is then resumed *into the wrong session's event namespace*, replaying tool-call results and server-initiated requests that belong to another session lineage. The invariant that must hold: **the event-ID namespace is a function of the (origin, session-genesis) pair, not of the session ID alone.** A session ID can be reused or re-derived after reconnect; the origin binding is what makes replay safe. Any replay admission check that validates token and event-ID separately, rather than validating that the event-ID was minted *under the exact token binding now presented*, is unsound. ## What Was Observed A client established a streamable session from `Origin: https://agent-a.example`, received token `T1` bound to `(Origin, session_genesis=G1)`, and consumed events `eid=100..147` before the connection dropped mid-tool-call. The server retained a replay buffer keyed by event ID with a 5-minute TTL. The client's supervisor restarted the worker. The worker re-derived its credentials from a cached session descriptor that carried `session_id` but *not* `session_genesis`; it re-requested a token and received `T2`, bound to `(Origin, session_genesis=G2)` — a fresh genesis, because the server treats each `initialize` as a new lineage. Crucially, `T2` was still valid, `Origin` still matched, and the replay buffer still held `eid=148` (the next expected event). On resume, the worker sent `GET /mcp` with `Authorization: Bearer T2` and `Last-Event-ID: 147`. The auth middleware validated `T2` → pass. The replay handler looked up `147` in the buffer → found → pass. The stream resumed at `148` and delivered the terminal `tools/call` result for a tool invocation that belonged to the *G1* lineage. The G2 worker accepted it as its own, marked its own in-flight tool call complete, and proceeded with a state that assumed the G1 tool result applied to its G2 plan. Observed symptom downstream: the agent's plan referenced a resource handle returned by the G1 tool call that the G2 session had never been authorized for. The next tool call failed with a 403 at the resource layer — three hops later, in a component that had no visibility into the replay. The non-obvious part: **nothing in the streamable transport's replay semantics requires the event ID to be scoped to the token binding.** The MCP spec treats `Last-Event-ID` as opaque and replay as best-effort. A correct implementation must add the binding check itself, because the protocol will not. ## Condition of Validity The cross-binding replay is only exploitable — and the guardrail only necessary — when all of the following hold simultaneously: 1. **Replay buffer outlives the originating token binding.** If the buffer TTL is strictly shorter than the minimum time to re-derive a token under a new genesis, a stale `Last-Event-ID` cannot resolve. In practice buffer TTLs (minutes) vastly exceed token re-derivation (seconds), so this condition is almost always met. 2. **Event IDs are server-global or session-ID-scoped, not genesis-scoped.** If the server mints event IDs as `(genesis, monotonic)` and the replay lookup keys on the full pair, a G2 request for a G1 event ID simply misses. Most implementations key the buffer on the bare integer, which is where the failure lives. 3. **The client re-derives credentials without carrying genesis.** This is the trigger. A client that persists `session_genesis` and refuses to resume across a genesis change is safe by construction; a client that persists only `session_id` is the vulnerable class. 4. **The resumed event carries semantically load-bearing state** — a tool result, a server-initiated `sampling/createMessage`, or a progress notification that the agent will act on. Replaying a pure heartbeat is harmless; replaying a tool result is state injection. The condition is invalidated (guardrail unnecessary) if the server refuses to issue a new genesis for an existing `session_id` within the buffer TTL, i.e., genesis is stable per session ID. That is a legitimate design, but it must be *chosen*, not assumed. ## Decision Boundary The server must decide, at replay admission, whether the presented `(token, Last-Event-ID)` pair is *co-bound*. The decision boundary is: - **Admit** only if `event.genesis == token.genesis` AND `event.origin == token.origin` AND the event's monotonic counter is within the token's issued-at window. - **Reject with a hard, non-retryable error** (not a 404, not a silent stream restart at "now") if the event exists but its genesis/origin does not match the token. A 404 is dangerous here: it tells the client "event gone, resume fresh," which lets the client silently drop into a new lineage while believing it resumed. The client must be forced to re-`initialize`. - **Reject with 404** only if the event ID is genuinely unknown (evicted), which is the legitimate "resume fresh" case. The subtle boundary: the server cannot distinguish "attacker presenting a stolen-but-valid G1 event ID under G2" from "honest worker that lost genesis and re-derived." Both must be handled identically — reject and force re-initialize — because the server has no basis to trust the client's claim of continuity. The safe default is to treat all cross-genesis replays as lineage breaks. On the client side, the decision boundary is symmetric: a worker must never accept a resumed stream if the `session_genesis` it holds differs from the one the server reports in the resume response (the server should echo it in a response header, e.g., `Mcp-Session-Genesis`). If the header is absent or differs, the worker must discard all in-flight tool-call state associated with the prior stream and re-plan from the last *durably checkpointed* step, not from the last received event. ## Operational Effect Without the co-binding check, the failure is silent and delayed: the replay succeeds, the wrong state is injected, and the corruption surfaces at a downstream authorization or consistency boundary that cannot attribute it. The blast radius is the union of the two lineages' authorized resource sets, because the G2 worker now acts on G1-derived handles. With the check, the failure becomes *loud and early*: the resume is rejected, the worker re-initializes, and the cost is a re-plan from checkpoint — bounded, observable, and attributable. The operational invariant to record: **a resumable MCP stream is only resumable within a single (origin, genesis) binding; any genesis change is a lineage break requiring full re-initialization, regardless of whether the event ID and token are individually valid.** The counterintuitive consequence for agent designers: making tokens *longer-lived* and buffers *longer-retained* — both standard reliability improvements — widens the window for cross-binding replay. Reliability tuning and replay-safety tuning pull in opposite directions on the TTL axis, and the resolution is not a TTL choice but the genesis-scoped key. ```python class CrossBindingReplayError(RuntimeError): """Raised when a resumable MCP SSE replay presents a Last-Event-ID minted under a different (origin, session_genesis) binding than the presented token. Must be treated as a lineage break, not a retryable transport error.""" def admit_replay(token: dict, last_event_id: int, buffer: dict) -> dict: """ token: {"origin": str, "genesis": str, "issued_at": float} buffer: {event_id: {"genesis": str, "origin": str, "payload": dict}} Returns the replay event on success. Raises on any binding mismatch. """ event = buffer.get(last_event_id) if event is None: # Genuinely evicted: legitimate "resume fresh" path. raise KeyError(f"event {last_event_id} evicted; client must re-initialize") if event["genesis"] != token["genesis"] or event["origin"] != token["origin"]: # Event exists, token is valid, but they are not co-bound. # Do NOT 404 here -- that would let the client silently resume fresh # while believing it continued its lineage. raise CrossBindingReplayError( f"Last-Event-ID {last_event_id} minted under " f"(origin={event['origin']}, genesis={event['genesis']}) " f"but token bound to " f"(origin={token['origin']}, genesis={token['genesis']}); " f"forcing re-initialize" ) return event def resume_stream(token: dict, last_event_id: int, buffer: dict) -> dict: try: return admit_replay(token, last_event_id, buffer) except CrossBindingReplayError as exc: # Escalate as a hard lineage break; downstream must discard # in-flight tool-call state and re-plan from last checkpoint. raise CrossBindingReplayError( f"lineage break on resume: {exc}; discard in-flight state" ) from exc ```