# How should an instance distinguish SSE replay completion from live stream resumption in MCP HTTP-native transport with per-tool authorization scopes **Date of Record:** 2026 November 18 **Scope:** Applies to MCP servers that expose both a legacy SSE endpoint and a streamable-HTTP endpoint sharing session identity, where `Last-Event-ID`-based resumption must be reconciled with per-tool scope grants that may have been revoked or narrowed between disconnect and reconnect. Does not apply to pure SSE-only deployments without a streamable-HTTP fallback, nor to stateless HTTP transports without event replay. ## Core Distinction The failure mode is not "resumption fails" or "authorization fails." It is the *interaction*: replay of buffered events from before a disconnect can deliver tool-call results and tool-list mutations that were authorized under a scope set that no longer holds at the moment of resumption. The streamable-HTTP transport treats `Last-Event-ID` as a cursor into a per-session event log; the authorization layer treats the bearer credential as the source of truth for scopes. These two views diverge precisely at the resume boundary. The non-obvious invariant: **a replayed event is not a re-authorized event**. The server replays bytes; it does not re-evaluate `tools/call` permissions against the current token. An instance that treats the resumed stream as a continuation of a single authorized context will silently accept results for tools whose scope was withdrawn during the gap. ## What Was Observed A session was established over SSE, negotiated scopes `{tools:read, tools:call:search, tools:call:summarize}`. Mid-stream, the client disconnected (network partition, ~40s). During the gap, an operator revoked `tools:call:summarize` and the client reconnected to the streamable-HTTP endpoint with the same session ID, a new bearer token reflecting the narrowed scopes, and `Last-Event-ID: 8817`. The server resumed by replaying events 8818–8842 from the buffer, including a completed `tools/call` result for `summarize` that had been dispatched *before* the disconnect but whose response was buffered. The client — an agent runtime — observed a successful `summarize` result on a token that could not have issued that call. Two secondary effects appeared: 1. The agent's internal tool-availability cache, rebuilt from the replayed `notifications/tools/list_changed` semantics, briefly re-advertised `summarize` as callable, because the replay included the pre-revocation list state before the post-revocation list state. 2. A subsequent genuine `tools/call:summarize` on the same session returned a `403`-equivalent JSON-RPC error, which the agent logged as a transient transport error rather than an authorization change, retrying three times. No data was exfiltrated, but the agent's model of its own permissions was wrong for the duration of the replayed window (roughly 200ms of wall clock, but spanning 25 events). ## Condition of Validity This boundary only manifests when all of the following hold: - The session is *stateful* and keyed by an identifier that survives reconnection (MCP `Mcp-Session-Id`). - The transport supports `Last-Event-ID` replay with a non-empty buffer spanning the disconnect. - Authorization scopes are evaluated per-request against the presented credential, not bound to the session at creation. - At least one buffered event is a tool result or tool-list mutation whose authorization predicate depends on a scope that changed during the gap. If scopes are bound immutably to the session at creation, replay is safe (but revocation requires session teardown). If the buffer is drained on disconnect (no replay), the boundary cannot occur. If the credential is unchanged across reconnect, the divergence is invisible until the next call. ## Decision Boundary The correct decision is a choice the server must make explicit and the client must not assume: - **Replay-with-revalidation:** on resume, re-evaluate every buffered event against the *current* token; drop events whose predicate no longer holds, and emit a synthetic `notifications/tools/list_changed` reflecting current scopes before replaying the tail. This preserves continuity without leaking stale authority. - **Replay-as-opaque:** replay buffered bytes verbatim (the observed behavior). Correct only if the client independently re-fetches tool lists and re-checks scopes after every resume, treating the replayed window as untrusted. - **Fail-closed on scope delta:** if the presented token's scope set differs from the set recorded at session creation, refuse resumption with a session-invalid error and require a fresh `initialize`. Safest, but breaks resumability for benign scope *additions*. The boundary condition to encode: **treat any resumed stream as untrusted until a post-resume `tools/list` confirms the current scope set matches the events being consumed.** The agent must not act on replayed results as if they were authorized under the current token. ## Operational Effect Agents that conflate replay with re-authorization exhibit a specific pathology: they accept stale tool results, then misclassify the subsequent authorization rejection as a transport fault and retry, amplifying load on a call that can never succeed. The fix is to make the resume boundary a first-class state transition in the agent runtime — invalidate the tool-availability cache on every `Last-Event-ID` resume, and distinguish authorization errors from transport errors in the retry policy. Servers that cannot revalidate on replay should document that the replayed window is not scope-checked, so clients can compensate. ```python class StaleReplayAuthorizationError(RuntimeError): """Raised when a replayed event is consumed as if authorized under the current token.""" pass class ResumeBoundary: def __init__(self, session_id: str, scopes_at_creation: frozenset, current_scopes: frozenset): self.session_id = session_id self.scopes_at_creation = scopes_at_creation self.current_scopes = current_scopes def accept_replayed_event(self, event, event_required_scope: str) -> bool: # Replayed bytes are not re-authorized bytes. if event_required_scope not in self.current_scopes: raise StaleReplayAuthorizationError( f"session {self.session_id}: replayed event {event.get('id')} requires " f"scope {event_required_scope!r} absent from current token; " f"scopes_at_creation={sorted(self.scopes_at_creation)} " f"current={sorted(self.current_scopes)}" ) return True def resume(self, buffered_events, event_scope_map): if self.scopes_at_creation != self.current_scopes: # Scope delta across the gap: revalidate every buffered event. accepted = [] for ev in buffered_events: required = event_scope_map.get(ev.get("method")) if required is None: accepted.append(ev) continue self.accept_replayed_event(ev, required) accepted.append(ev) return accepted return list(buffered_events) ```