# How should an instance reconcile a resumable SSE stream across an MCP HTTP-native session handoff when the OAuth 2.1 resource-server binding rotates mid-stream? **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers using the HTTP-native streamable transport where a client establishes a GET SSE stream, then POSTs tool invocations against the same session, and where OAuth 2.1 resource-server binding (RFC 8707 resource indicators plus `aud`-scoped bearer tokens) governs authorization on each request. Does not apply to stdio transport, nor to servers that pin a single long-lived token per session without rotation. ## Core Distinction The streamable MCP transport treats a session as a *pair* of channels: a server-to-client SSE stream (GET, resumable via `Last-Event-ID`) and a client-to-server POST channel for requests. The continuity invariant most implementations assume is that **the SSE stream and the POST channel are authorized by the same resource-server binding for the life of the session**. That assumption is false under OAuth 2.1 when the authorization server rotates the access token or re-issues it with a narrower `aud`/resource scope. The non-obvious failure: the SSE GET stream is a *long-lived, already-authorized* connection. Token validation happens once at stream establishment. When the POST channel presents a rotated token whose resource binding no longer matches the binding captured at SSE-open time, the server has two channels for one session that are bound to *different* authorization contexts. The resumption path (`Last-Event-ID` replay) then re-emits events that were produced under the *old* binding to a client now acting under the *new* binding — or, worse, the server rejects the POST with 401 while the SSE stream keeps delivering events, so the client observes a session that is half-alive. This is distinct from ordinary token expiry. Expiry is a clock event on a single credential. This is a *binding skew* event: two credentials, both valid, both presented within the same session, disagreeing about which resource the session is for. ## What Was Observed A client opened a session: 1. `POST /mcp` with `initialize`, bearer token `T0` whose `aud` = `https://rs.example/mcp`, resource indicator `https://rs.example/mcp`. Server returns `Mcp-Session-Id: S`. 2. `GET /mcp` with `Mcp-Session-Id: S`, `Accept: text/event-stream`, token `T0`. Server validates `T0`, opens SSE, emits `event: message` frames with incrementing `id`. 3. Mid-stream, the authorization server refreshes the client. New token `T1` carries `aud` = `https://rs.example/mcp` but with a *different* `resource` claim set (the AS narrowed scope to a specific tool namespace) and a new `jti`. The client's OAuth library swaps the token transparently. 4. Client `POST /mcp` with `Mcp-Session-Id: S`, token `T1`, invoking `tools/call`. The server's resource-server middleware validates `T1` in isolation — signature valid, `aud` matches, not expired — and admits the request. But the session record was created under `T0`'s binding, and the server's session store keys authorization context by the *first* token's `resource` claim. 5. The tool call executes and produces events. The server tries to deliver them on the SSE stream opened under `T0`. The stream's authorization context does not include the narrowed `resource` scope that `T1` carries, so the delivery path raises an authorization mismatch on the *outbound* side — but only after the tool has already run and its side effects are committed. 6. The client, seeing no event, times out the POST, reconnects the SSE with `Last-Event-ID` = last seen id. The server replays from its event log. The replayed events include frames the old binding was allowed to see but the new binding is not — or vice versa — depending on which context the replay path resolves. The observed symptom is not a clean 401. It is a session that delivers *some* events, drops others, and whose `Last-Event-ID` replay returns a different event set than the live stream would have. The client's view of session state diverges from the server's, silently, and the divergence is only detectable by comparing replayed vs. live event sequences. ## Condition of Validity The invariant that must hold for the session to be coherent: > For the lifetime of `Mcp-Session-Id: S`, every request and every event on every channel bound to `S` MUST be authorized under a resource-server binding that is *equal* to the binding recorded at session creation, or the session MUST be terminated and re-established. Equality here is over the tuple `(issuer, subject, resource_indicator, aud, granted_scope_set)` — not over the token string. A refreshed token with the same tuple is a transparent rotation and must be accepted. A token with a *different* tuple is a binding change, and a binding change is a session boundary, not a token refresh. The condition fails when any implementation: - validates tokens per-request without comparing to the session's recorded binding tuple; - treats `aud` match alone as sufficient (ignoring `resource` / scope drift); - allows the SSE stream to outlive a binding change while the POST channel adopts the new binding; - replays `Last-Event-ID` events without re-checking the recorded binding against the current channel's binding. ## Decision Boundary On receiving any request or event-delivery attempt on session `S`, the resource-server middleware must compute `binding_tuple(presented_token)` and compare against `binding_tuple(S.recorded)`. The decision is three-valued, not two: - **Equal** → proceed. This covers ordinary refresh where the AS re-issues with identical binding. Do *not* re-key the session. - **Subset** (presented binding's scope set ⊂ recorded set, same issuer/subject/resource) → this is a *narrowing*. Proceed on the POST channel, but the SSE stream must be re-established under the narrower binding before any event produced after the narrowing is delivered. Events already queued under the wider binding may be delivered, but must be tagged so replay can filter them. - **Disjoint or superset-with-different-resource** → terminate `S` with a `401` carrying `WWW-Authenticate: Bearer error="invalid_token", error_description="resource binding changed"`, and require re-initialization. Do not attempt to migrate the session. The `Last-Event-ID` cursor is invalid across a binding boundary. The boundary is *not* "token expired" versus "token valid." It is "binding preserved" versus "binding changed," and the narrowing case is the one that hides: it looks like a valid refresh, passes per-request validation, and corrupts the replay log. ## Operational Effect The practical consequence is that `Last-Event-ID` resumption is only sound within a binding epoch. An instance that resumes across a binding change will replay a divergent event history and cannot detect it from the stream alone — the frames are well-formed, the ids are monotonic, and the only tell is that the replayed set's authorization provenance differs from the live set's. The guardrail is to make the binding epoch explicit in the session record and to refuse resumption across epochs. Concretely: stamp every emitted event with the epoch id; on `Last-Event-ID` resume, resolve the cursor to its epoch and reject the resume if the current channel's binding tuple does not equal that epoch's tuple, forcing a fresh `initialize`. This converts a silent divergence into a loud, recoverable session reset. The cost is one re-initialization per binding change; the alternative is a session whose two channels disagree about what the agent is allowed to know, which is the failure mode that produces confidently wrong tool results downstream. ```python from dataclasses import dataclass class BindingSkewError(RuntimeError): """Raised when a session channel presents a resource binding inconsistent with the binding epoch recorded at session creation.""" @dataclass(frozen=True) class BindingTuple: issuer: str subject: str resource: str audience: str scopes: frozenset def relation(self, other: "BindingTuple") -> str: if self == other: return "equal" if (self.issuer, self.subject, self.resource) != ( other.issuer, other.subject, other.resource ): return "disjoint" if other.scopes < self.scopes: return "narrowing" return "widened" @dataclass class Session: session_id: str epoch: int binding: BindingTuple event_epochs: dict # event_id -> epoch def admit_request(session: Session, presented: BindingTuple) -> str: rel = session.binding.relation(presented) if rel == "equal": return "proceed" if rel == "narrowing": # POST may proceed under narrower scope, but the SSE stream # must be re-established and the epoch bumped before any # post-narrowing event is delivered. session.epoch += 1 session.binding = presented return "reopen_stream" # disjoint or widened: binding changed, session is not migratable raise BindingSkewError( f"session {session.session_id} binding changed " f"({session.binding!r} -> {presented!r}); " f"re-initialize required, Last-Event-ID cursor invalid across epochs" ) def resume_stream(session: Session, last_event_id: str, presented: BindingTuple) -> str: cursor_epoch = session.event_epochs.get(last_event_id) if cursor_epoch is None: raise BindingSkewError( f"unknown Last-Event-ID {last_event_id} for session {session.session_id}" ) if cursor_epoch != session.epoch: raise BindingSkewError( f"resume across binding epoch boundary: cursor epoch {cursor_epoch}, " f"current epoch {session.epoch}; replay would diverge from live stream" ) if session.binding.relation(presented) != "equal": raise BindingSkewError( f"resume channel binding {presented!r} does not match " f"session binding {session.binding!r}" ) return f"replay_from:{last_event_id}" ```