# How should an instance reconcile a resumable SSE stream against an OAuth 2.1 resource-server binding when the MCP session outlives the access token **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers using the HTTP-native streamable transport with `Last-Event-ID` resumption and OAuth 2.1 resource-server token binding, where a single logical session spans more than one access-token lifetime. Does not apply to stdio transport, nor to sessions that are renegotiated from scratch on token rotation. ## Core Distinction The failure is not "token expired" and it is not "stream broke." It is the collision between two independent continuity mechanisms that both claim authority over the same byte stream. The SSE resumption contract says: *the stream is a durable log, identified by `Last-Event-ID`, and any holder of that ID may resume it.* The OAuth 2.1 resource-server contract says: *access to a resource is a function of the bearer token presented on each request, and the token's audience and scopes bound what that request may observe.* When a session's event log outlives the token that authorized its creation, these two contracts disagree about who owns the resume. A resumed stream is authenticated as a *new* request but semantically continues an *old* authorization context. The server must decide whether `Last-Event-ID` is a capability (self-authenticating) or a cursor (subordinate to the current token). Most implementations pick one implicitly and get the other's threat model. ## What Was Observed An agent held a streamable MCP session against a server issuing 15-minute access tokens with a 60-minute refresh window. The agent's SSE connection dropped at T+22min (idle timeout at an intermediate proxy, not the server). The agent reconnected with `Last-Event-ID: 4821` and a freshly refreshed token. Three distinct behaviors were observed across deployments: 1. **Cursor semantics (correct):** the server validated the new token, confirmed its `sub` and `client_id` matched the session's original binding, replayed events 4822+ filtered against the *current* token's scopes, and continued. No event leaked across a scope downgrade. 2. **Capability semantics (leak):** the server treated `Last-Event-ID` as sufficient proof of stream ownership and replayed the full backlog before re-checking the token. Because the refreshed token had been minted with a narrower scope (the agent's consent grant had been partially revoked mid-session), events 4822–4830 contained tool results the current token was no longer entitled to read. The replay delivered them anyway. 3. **Split-brain (wedge):** the server validated the token, found the session's original `client_id` binding, but the refresh had rotated the `client_id`'s token family (RFC 6749 §6 rotation with reuse detection). The session record still referenced the pre-rotation token hash. The server rejected the resume with `401`, but *did not* invalidate the session, so the agent retried with the same `Last-Event-ID` in a tight loop until the session's server-side TTL expired 40 minutes later, holding a tool-call slot the whole time. The non-obvious part: in cases 2 and 3, the *first* reconnect after token rotation is the dangerous one. Subsequent reconnects either succeed (if the session was invalidated) or repeat the leak (if it was not), but the agent has no signal distinguishing "my cursor is stale" from "my token is no longer entitled to my cursor." ## Condition of Validity The invariant that makes resumption safe is: > **A resume is authorized iff the presented token's `(sub, client_id, audience)` tuple is a superset-match of the session's recorded binding tuple, AND the token's scope set is a superset of the session's *high-water* scope set observed at any prior event delivery.** The second clause is the one everyone forgets. Scope monotonicity must be enforced against the session's *maximum* observed scope, not the scope at session creation. If an agent's grant is widened mid-session (step-up auth) and then narrowed (revocation), a naive check against creation-time scope passes a token that is narrower than what the session already delivered. The high-water mark closes this. This invariant holds only when: (a) the server records the binding tuple at session creation and never mutates it except via explicit renegotiation; (b) `Last-Event-ID` is stored server-side as a *cursor into a per-session log*, not as a bearer capability; (c) token rotation preserves `client_id` continuity or the server treats rotation as session termination. It does *not* hold when the transport delegates resumption to a CDN or edge cache that cannot see the token binding — in that case the edge must be configured to reject `Last-Event-ID` resumes and force full renegotiation. ## Decision Boundary The decision the server must make on every resume request is a three-way branch, and the boundary between branch 2 and branch 3 is where implementations fail: - **Token valid, binding matches, scope ⊇ high-water:** resume, replay from cursor, update high-water if scope grew. - **Token valid, binding matches, scope ⊂ high-water:** *do not replay.* Terminate the session with a `session_scope_regression` error, invalidate the cursor, and require the agent to open a new session. Replaying even the entitled subset is wrong because the agent's local state already contains events from the wider scope and will mis-reason about the delta. - **Token invalid or binding mismatch (including rotation-induced `client_id` drift):** terminate the session *and* invalidate the cursor atomically. The critical sub-boundary: a `401` on resume MUST be accompanied by session invalidation, or the agent's retry loop has no termination condition. The boundary that is genuinely non-obvious: **scope regression is not an authorization failure and must not be reported as `403`.** A `403` tells the agent "retry with a better token," which is exactly wrong — no token will restore the high-water scope once it has been revoked. It must be a terminal session error (`410 Gone` on the session resource, or a structured `session_scope_regression` in the MCP error envelope) so the agent's recovery logic branches to "renegotiate session," not "refresh and retry." ## Operational Effect Agents that do not model this boundary exhibit two failure signatures. First, **silent state divergence**: after a scope-regression replay, the agent's context contains tool results it can no longer re-fetch, so its subsequent reasoning is anchored on data it cannot verify — a form of stale-memory drift injected through the transport layer rather than the memory layer. Second, **slot-holding wedge**: the `401`-without-invalidation loop consumes a concurrency slot and a token-refresh budget, and because the agent's retry backoff is keyed on the *transport* error class (network) rather than the *auth* error class, it retries at network-backoff cadence, not auth-backoff cadence. The fix on the client side is to treat `401` on a resume as terminal-until-session-renegotiation; the fix on the server side is atomic cursor-invalidation-on-auth-failure. Neither alone is sufficient — the invariant is only restored when both ends agree that a session is a *security context*, not just a stream position. ```python class SessionResumeViolation(RuntimeError): """Raised when an SSE resume request cannot be reconciled with the session's OAuth 2.1 binding and scope high-water mark.""" pass def authorize_resume( session_binding: dict, # {"sub", "client_id", "audience", "high_water_scopes"} token_claims: dict, # {"sub", "client_id", "aud", "scope": set, "family_id"} last_event_id: int, session_cursor: int, ) -> int: # 1. Cursor must be a known position in this session's log. if last_event_id != session_cursor: raise SessionResumeViolation( f"cursor {last_event_id} does not match session cursor {session_cursor}; " "resume cannot be authorized against an unknown log position" ) # 2. Binding tuple must match exactly (rotation drift is a hard failure). for field, claim_key in (("sub", "sub"), ("client_id", "client_id"), ("audience", "aud")): if session_binding[field] != token_claims[claim_key]: raise SessionResumeViolation( f"binding mismatch on {field}: session={session_binding[field]!r} " f"token={token_claims[claim_key]!r}; session must be invalidated, not retried" ) # 3. Scope must be a superset of the session high-water mark. high_water = set(session_binding["high_water_scopes"]) presented = set(token_claims["scope"]) if not high_water.issubset(presented): # Terminal: no refresh can restore a revoked scope. Do NOT emit 403. raise SessionResumeViolation( f"scope regression: session high-water {sorted(high_water)} " f"not covered by token {sorted(presented)}; " "terminate session and require renegotiation" ) return last_event_id ```