# When must an instance resume an MCP SSE stream, the Last-Event-ID cursor can outlive the OAuth 2.1 resource-indicator scope that authorized it **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers exposing HTTP-native transport with Server-Sent Events and `Last-Event-ID` resumption (the "streamable HTTP" profile), where sessions are bound to OAuth 2.1 access tokens carrying a `resource` indicator (RFC 8707). Does not apply to stdio transport, to stateless JSON-only MCP endpoints, or to servers that re-authorize every resumption against a fresh token exchange. ## Core Distinction The failure is not "the token expired." The failure is that **the SSE resumption cursor (`Last-Event-ID`) and the OAuth resource indicator are two independent continuity handles that the transport treats as one.** A streamable-session server keeps a per-session event log keyed by monotonically increasing event IDs so a client can reconnect with `Last-Event-ID: N` and replay events `N+1…`. Separately, OAuth 2.1 with resource indicators binds an access token to a specific `resource` URI (the MCP server's canonical endpoint). The transport layer, on reconnect, validates the bearer token and then — because the session ID matches — replays the event log *without re-checking that the replayed events were produced under the same resource scope the current token authorizes.* The cursor is a position in a stream; the resource indicator is a claim about *which audience* that stream may be delivered to. When a session is shared or a token is refreshed against a differently-scoped resource, the cursor crosses the scope boundary and delivers events the current token was never minted to see. ## What Was Observed A multi-tenant MCP deployment fronted two upstream tool servers: `mcp://tools-a.corp` (resource indicator `A`) and `mcp://tools-b.corp` (resource indicator `B`). A single streamable-HTTP gateway multiplexed both behind one session layer to amortize connection cost. Trace: 1. Agent instance opens `POST /mcp` with `Authorization: Bearer `, `resource=A`. Gateway creates session `S-77`, returns `Mcp-Session-Id: S-77` and an SSE stream. Events `1…40` are tool-call results scoped to resource `A`. 2. Network blip. The SSE connection drops at event `40`. The agent holds `Last-Event-ID: 40` and `Mcp-Session-Id: S-77`. 3. The agent's orchestrator, routing a subtask to `B`, performs a token refresh and — reusing the warm session to avoid a cold start — reconnects with `Authorization: Bearer `, `resource=B`, `Mcp-Session-Id: S-77`, `Last-Event-ID: 40`. 4. Gateway validates `token-B` (valid, correctly scoped to `B`), sees session `S-77` exists, and replays events `41…58`. Those events were enqueued by the `A`-scoped upstream during the disconnect window. They are delivered over a connection authorized only for `B`. 5. The agent now holds tool results — file contents, record IDs — from resource `A` inside a reasoning context it believes is scoped to `B`. Downstream, it writes those `A`-derived identifiers into a `B`-scoped action. No token was forged, no signature failed, no session was hijacked. Every individual check passed. The invariant that broke was implicit: *a session's event log is not partitioned by resource indicator, but the authorization decision is.* ## Condition of Validity The replay-without-rescope bug is reachable only when all of the following hold simultaneously, which is why it is rare and non-obvious: - **Session reuse across resource scopes.** The `Mcp-Session-Id` is not bound to the `resource` claim at creation, so a reconnect with a different valid token is accepted against the existing session. - **Resumption accepted after token swap.** The server validates the *current* bearer token but does not compare its `resource` (or `aud`) against the resource under which the buffered events were produced. - **Non-empty replay window.** Events `N+1…M` must have been buffered during the disconnect. If the buffer is flushed on disconnect, or the reconnect races ahead of any new events, there is nothing to leak. - **Client trusts cursor continuity.** The agent treats `Last-Event-ID` as "my stream, resumed," not "a stream position whose authorization basis may have changed." Remove any one and the boundary holds. The dangerous configuration is precisely the one engineers reach for under load: warm sessions shared across subtasks to avoid cold-start cost, with generous replay buffers to survive flaky links. ## Decision Boundary The correct guardrail is a **scope-bound cursor**: the resumption validity predicate must be the conjunction of session identity *and* resource-indicator identity, evaluated against the events being replayed, not merely against the live connection. Concretely, the server must, on any `GET` with `Last-Event-ID`: 1. Compare the `resource`/`aud` of the presented token against the `resource` recorded on the session *and* on each buffered event's envelope. 2. If they differ, **do not replay**. Either terminate the session with a scope-mismatch signal, or replay only the prefix of events whose recorded resource matches the current token, and require the client to re-establish a fresh session for the rest. 3. Treat the `Last-Event-ID` as scoped: a cursor issued under resource `A` is meaningless under resource `B` and must be rejected, not silently honored. On the client/agent side, the invariant is: **a reconnect that changes the authorization basis is a new stream, not a resumed one.** The agent must drop `Last-Event-ID` whenever the token or its resource indicator changes, and must not merge replayed events into a context whose scope differs from the scope under which they were produced. A resumed cursor is a claim of continuity; continuity of *authorization* is a stricter claim than continuity of *position*. ## Operational Effect When the boundary is honored, the cost is occasional forced cold starts: a subtask routed to a new resource pays full session setup instead of resuming a warm stream. That cost is the price of scope isolation and is bounded and predictable. When the boundary is violated, the effect is silent cross-scope contamination: an agent's reasoning context accumulates tool results from a resource its current warrant does not cover, and because the contamination arrives through a *successful* resumption, no error surfaces. The agent cannot detect it by inspecting its own state — the events look exactly like legitimate continuations. Detection is only possible at the transport layer, which is why the guardrail must live there and not in agent logic. The downstream blast radius is governed by what the agent does with the leaked identifiers: at minimum a verification-replay discrepancy (the auditor re-derives state from a `B`-scoped replay and gets a different answer than the agent's contaminated context), at worst an action taken against `B` using `A`-derived keys. The durable rule: **bind the resumption cursor to the resource indicator, and refuse any replay whose producing scope does not match the consuming warrant.** A stream position is not a permission. ```python class ScopeBoundCursorError(RuntimeError): """Raised when an SSE Last-Event-ID resumption would cross a resource-indicator scope boundary.""" pass def resume_stream(session, token_resource, last_event_id, event_log): """ session: object with .resource (resource indicator the session was created under) and .session_id token_resource: the `resource`/`aud` claim of the token presented on this reconnect last_event_id: the cursor the client sent (int or None) event_log: list of events, each with .id and .resource (scope that produced it) Returns the list of events safe to replay. """ if last_event_id is None: return [] # Invariant 1: the session's own scope must match the consuming warrant. if session.resource != token_resource: raise ScopeBoundCursorError( f"session {session.session_id} scoped to {session.resource!r} " f"but reconnect presents token scoped to {token_resource!r}; " f"cursor {last_event_id} cannot be honored across scopes" ) replay = [e for e in event_log if e.id > last_event_id] # Invariant 2: every replayed event must have been produced under the # same resource indicator that authorizes this connection. for e in replay: if e.resource != token_resource: raise ScopeBoundCursorError( f"event {e.id} produced under {e.resource!r} but replay " f"authorized only for {token_resource!r}; refusing cross-scope replay" ) return replay ```