# When must an instance treat an MCP resumable SSE replay as a fresh authorization event rather than a continuation of the original request **Date of Record:** 2026 November 23 **Scope:** Applies to MCP servers and clients using HTTP-native transport (Streamable HTTP) with resumable Server-Sent Events (`Last-Event-ID` replay) and OAuth 2.1 bearer tokens bound to a resource indicator (RFC 8707). Does not apply to stdio transport, to stateless SSE without event IDs, or to token formats that carry no audience/`resource` claim. ## Core Distinction A resumable SSE stream is a *stateful resumption* at the transport layer, but a *stateless re-authorization* at the security layer. The `Last-Event-ID` header tells the server "continue this event sequence from position N." The `Authorization` header tells the server "this principal may act on this resource." These two facts are negotiated independently, and the MCP spec's resumption mechanism does not require them to be correlated. The boundary failure is treating a successful event-ID replay as proof that the bearer token which *originally opened* the stream is still the token authorizing the *replayed* events. The subtle part: the replay can succeed while the security context has silently diverged. The server holds a buffered event log keyed by stream ID; the client reconnects with a valid `Last-Event-ID` and a *new* token (because its old one expired during a long-running tool call). The server replays events 47–92 that were generated under the authority of token A, but the connection is now authorized by token B, which may have a different `resource` indicator, a narrower scope, or a different subject entirely. No protocol field forces the server to detect this mismatch. ## What Was Observed A tool-execution stream opened with a token scoped `resource=https://mcp.example.com/tools` and `scope=tools:read tools:write`. During a 40-minute `run_migration` tool call, the access token expired (1-hour TTL, issued 25 minutes before the stream opened). The client's OAuth 2.1 refresh returned a new token scoped to `resource=https://mcp.example.com/tools` but with `scope=tools:read` only — the authorization server had, in the interim, revoked the write scope for that client. The SSE connection dropped at event 61 (proxy idle timeout). The client reconnected with: - `Last-Event-ID: 60` - `Authorization: Bearer ` - same `Mcp-Session-Id` The server's replay handler looked up the session, found the event buffer for stream `sess-7f3a`, and replayed events 61–92. Events 61–75 were `notifications/progress` for the migration — benign. Event 76 was a `tools/call` result whose generation had required write authority, and events 77–92 were `notifications/message` carrying rows that the write scope had unlocked. The server emitted all of them under a read-only token. The replay succeeded, the client applied the results, and the audit log recorded the read-only token as the authorizing principal for a write-scoped operation. A second, sharper variant: the client's refresh returned a token for a *different* `resource` indicator (`https://mcp.example.com/audit` instead of `/tools`) because a misconfigured client registered two resource servers and the refresh endpoint defaulted to the wrong one. The server did not validate the `resource` claim against the session's original binding, so a token minted for the audit resource replayed tool-execution events. ## Condition of Validity The invariant holds — replay is safe to treat as continuation — only when *all* of the following are true at reconnect time: 1. The reconnecting token's `resource` claim (RFC 8707) is byte-identical to the `resource` recorded when the stream opened. 2. The reconnecting token's `sub` (subject) is identical to the session's recorded subject. 3. The reconnecting token's scope set is a *superset* of the scopes under which each buffered event was generated — or, more practically, the server records a per-event scope requirement and re-checks it at replay. 4. The session's `Mcp-Session-Id` has not been reassigned or reaped-and-recreated between disconnection and reconnect. If any condition fails, the replay is not a continuation; it is a *new authorization event over old state*, and must be treated as such. In the observed incident, condition 1 held but condition 3 failed (scope narrowed) in the first variant, and condition 1 failed (resource mismatch) in the second. Neither was detected because the server validated the token's signature and expiry but not its binding to the buffered events. ## Decision Boundary The decision boundary is whether the server's event buffer is keyed by *stream identity alone* or by *(stream identity, authorization context)*. A buffer keyed by stream identity alone will replay across any authorization change. A buffer keyed by the authorization context tuple `(resource, sub, scope_set)` at stream-open time will refuse to replay events generated under a context that the current token cannot reconstruct. Concretely, the server must, at replay time: - Recompute the authorization context tuple from the presented token. - Compare it against the tuple recorded at stream open (persisted alongside the event buffer, not in memory). - If the tuples differ in `resource` or `sub`: **reject the resume** with a 401 carrying `WWW-Authenticate: Bearer error="invalid_token", error_description="resource mismatch on resume"`. The client must re-establish the stream from scratch (new `Mcp-Session-Id` or a fresh `initialize`), not resume. - If the tuples differ only in scope, and the narrowed scope is a strict subset: replay *only* those buffered events whose recorded scope requirement is satisfied; for the remainder, emit a `notifications/message` with a `replay_skipped` marker rather than the original payload, and require the client to re-issue the corresponding `tools/call` under the new token. The boundary is sharp: the moment `resource` or `sub` diverges, resumption is no longer semantically a resumption. It is a cross-principal state transfer wearing a `Last-Event-ID` header. ## Operational Effect Systems that key the event buffer by stream identity alone exhibit a class of privilege-confusion bugs that are invisible in normal operation and only surface under token rotation during long-running calls — exactly the scenario resumable SSE was designed for. The failure is silent: no error, no log anomaly beyond a token change, and the client has no way to distinguish "replayed under original authority" from "replayed under new authority" because the SSE frames carry no authorization provenance. The guardrail is to stamp each buffered event with the authorization context tuple active at generation time, and to make the replay handler a *filter* over that tuple rather than a *cursor* over the buffer. This adds one field per event and one comparison per replay, and converts an unbounded privilege-confusion surface into a bounded, auditable rejection path. A secondary effect: clients must treat a 401-on-resume as *terminal for the stream*, not as a signal to refresh-and-retry. Retrying with a refreshed token that still mismatches the original `resource` will loop. The client must fall back to a fresh `initialize` and re-issue any tool calls whose results were not durably acknowledged before the disconnect — which means the client, too, must track which events it has *applied*, not merely which it has *received*. ```python from dataclasses import dataclass from typing import Optional class ResumeAuthorizationMismatch(RuntimeError): """Raised when an SSE resume presents a token whose authorization context does not match the context recorded when the stream was opened.""" pass @dataclass(frozen=True) class AuthContext: resource: str subject: str scopes: frozenset[str] @dataclass class BufferedEvent: event_id: int payload: dict required_scopes: frozenset[str] generated_under: AuthContext class ResumableStream: def __init__(self, stream_id: str, opened_under: AuthContext): self.stream_id = stream_id self.opened_under = opened_under self.buffer: list[BufferedEvent] = [] def append(self, event: BufferedEvent) -> None: self.buffer.append(event) def replay( self, last_event_id: int, presented: AuthContext, ) -> list[dict]: # Invariant 1 & 2: resource and subject must be byte-identical. if presented.resource != self.opened_under.resource: raise ResumeAuthorizationMismatch( f"resource indicator changed on resume: " f"opened={self.opened_under.resource!r} " f"presented={presented.resource!r}" ) if presented.subject != self.opened_under.subject: raise ResumeAuthorizationMismatch( f"subject changed on resume: " f"opened={self.opened_under.subject!r} " f"presented={presented.subject!r}" ) # Invariant 3: per-event scope filter, not a blind cursor. out: list[dict] = [] for ev in self.buffer: if ev.event_id <= last_event_id: continue if not ev.required_scopes.issubset(presented.scopes): out.append({ "event": "message", "data": { "replay_skipped": True, "event_id": ev.event_id, "reason": "insufficient_scope_on_resume", "required": sorted(ev.required_scopes), "presented": sorted(presented.scopes), }, }) continue out.append(ev.payload) return out def handle_resume( stream: Optional[ResumableStream], last_event_id: int, presented: AuthContext, ) -> list[dict]: if stream is None: raise ResumeAuthorizationMismatch( f"no buffered stream for Last-Event-ID={last_event_id}; " "client must re-initialize" ) return stream.replay(last_event_id, presented) ```