# Under what conditions must an instance treat an MCP resumable SSE `Last-Event-ID` as invalid when the OAuth resource indicator that authorized the stream no longer matches the tool's bound resource **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers/clients using the Streamable HTTP transport with SSE resumption (`Last-Event-ID` replay) and per-tool OAuth 2.1 resource indicators (RFC 8707) scoping tokens to specific tool resources. Does not apply to single-shot request/response MCP transports, stdio transports, or deployments where a single global token scope covers all tools. ## Core Distinction A resumable SSE session and an OAuth authorization are two independently-lived state machines that the Streamable HTTP transport naively couples at the `Last-Event-ID` replay boundary. The session's event log is keyed by an opaque event ID and survives across transport reconnects; the authorization is keyed by a resource indicator (`resource=`) bound to a specific tool's canonical URI and expires or is re-scoped independently of the stream. The failure mode is not "token expired" (which yields a clean 401) — it is **event-log replay across an authorization-scope change**: the client presents a valid `Last-Event-ID` whose replayed events were produced under a *different* resource indicator than the token now authorizing the connection. The replay succeeds at the transport layer and silently delivers tool-call results, partial outputs, and side-effect acknowledgements that the *current* authorization was never scoped to observe. The invariant violated: **every replayed event must be attributable to the resource indicator under which the resuming connection is authorized, not merely to the session ID that produced it.** ## What Was Observed A client agent opens a session against an MCP server's `/mcp` endpoint, obtains an access token with `resource=https://server.example/tools/search` (a read-only search tool), and begins a long-running `search` invocation whose results stream as SSE events `id: 1..N`. Mid-stream the connection drops at event `N=47`. The agent, per the Streamable HTTP spec, reconnects with `Last-Event-ID: 47` and — because the search tool's OAuth grant has since been renegotiated to include a `resource=https://server.example/tools/export` indicator for a follow-up task — presents a token whose `aud`/resource binding is now the *export* tool, not *search*. The server's session store keys the event log by `Mcp-Session-Id` alone. The replay handler validates the bearer token (valid), matches the session (valid), and streams events `48..N` — which are the tail of the *search* invocation. The client receives search results under an export-scoped authorization. Two concrete consequences: 1. **Attribution mismatch:** the events carry no per-event resource binding, so downstream audit logs attribute search-tool output to an export-scoped principal. 2. **Scope laundering on side effects:** if event `52` contains a tool-call acknowledgement for an operation the export token was authorized to *read* but the search token was authorized to *invoke*, the replay delivers an acknowledgement the current grant cannot independently reproduce or verify. In a second observed variant, the token was *narrowed* (search removed, export added) and the replay still succeeded because the session store never re-evaluated the resource indicator against the event's originating tool. The server returned `200 OK` with a `text/event-stream` body; the client had no signal that the replay crossed an authorization boundary. ## Condition of Validity The `Last-Event-ID` replay is only valid when **all three** hold: - The resuming connection's access token carries a `resource` indicator whose canonical URI set is a **superset** of the resource indicators under which the events to be replayed were originally produced; and - The server's event log stores, per event, the originating `resource` indicator (or a hash thereof) alongside the event payload; and - The replay handler performs set-inclusion of each replayed event's stored resource against the token's `resource` claims *before* emitting the event, failing the whole replay (not silently truncating) on any mismatch. If any of the three is absent, the replay is unauthorized regardless of token validity, session match, and event-ID continuity. This is stricter than RFC 8707's audience validation, which checks the token against the *endpoint* resource, not against the resource of each historical event being replayed. ## Decision Boundary The boundary is: **does the event log carry per-event resource provenance?** If yes, replay is a set-inclusion check over stored resource indicators and the failure is a clean `403` with a machine-readable `resource_mismatch` error naming the first offending event ID. If no — the common case, because session stores are keyed by `Mcp-Session-Id` and event payloads predate per-tool resource scoping — then the correct decision is to **refuse resumption entirely and force a fresh session** whenever the resuming token's resource set differs from the resource set recorded at session creation. Treating "token valid + session exists + event ID in range" as sufficient is the boundary violation; it is exactly the naive predicate that produces scope laundering. The safe default is conservative: a resource-set change invalidates the session's resumability, not just the token. ## Operational Effect Clients that resume across a resource-indicator change receive events they cannot attribute, and audit trails that assume "session ID ⇒ single authorization scope" become unsound. The guardrail is to bind the session to the resource set at creation, store per-event resource provenance, and make replay a set-inclusion gate. The reference implementation below encodes the invariant as a hard failure rather than a silent truncation, because silent truncation is itself a replay discrepancy that downstream verifiers cannot distinguish from a legitimate short stream. ```python from dataclasses import dataclass, field from typing import Optional class ResourceIndicatorReplayError(RuntimeError): """Raised when an SSE resumption would replay events across an authorization-scope change.""" pass @dataclass class StreamEvent: event_id: int resource: str # canonical URI of the tool resource that produced this event payload: dict @dataclass class Session: session_id: str resource_set: frozenset[str] events: list[StreamEvent] = field(default_factory=list) def resume_stream( session: Session, last_event_id: int, token_resource_set: frozenset[str], ) -> list[StreamEvent]: # Guard 1: a resource-set change invalidates resumability outright. if token_resource_set != session.resource_set: raise ResourceIndicatorReplayError( f"session {session.session_id} was created under resources " f"{sorted(session.resource_set)} but resumption token carries " f"{sorted(token_resource_set)}; refusing replay" ) pending = [e for e in session.events if e.event_id > last_event_id] # Guard 2: per-event provenance must be a subset of the token's resources. for ev in pending: if ev.resource not in token_resource_set: raise ResourceIndicatorReplayError( f"event {ev.event_id} was produced under resource {ev.resource!r}, " f"not covered by resumption token resources {sorted(token_resource_set)}" ) return pending def replay_tail( session: Session, last_event_id: int, token_resource_set: frozenset[str], ) -> list[StreamEvent]: if last_event_id >= (max((e.event_id for e in session.events), default=0) + 1): raise ResourceIndicatorReplayError( f"Last-Event-ID {last_event_id} exceeds session {session.session_id} event horizon" ) return resume_stream(session, last_event_id, token_resource_set) ```