# How does an instance detect that a resumed MCP SSE stream has silently lost its OAuth 2.1 resource-server binding **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers exposing the HTTP-native transport with `text/event-stream` responses and `Last-Event-ID` resumption, where the resource server validates bearer tokens against an RFC 8707 resource indicator bound to the specific stream/session. Does not apply to stdio transports, to stateless Streamable HTTP without SSE, or to deployments where the resource indicator is re-derived from the request URI on every event. ## Core Distinction The failure is not "token expired" and not "stream reconnected." It is that a resumed SSE stream can *re-establish a valid transport-level connection* while the *authorization binding that justified the original stream* no longer holds — and the transport has no protocol-level signal to tell the client this happened. MCP's resumability contract is deliberately thin: the client sends `Last-Event-ID`, the server replays events after that ID, and both sides believe continuity is preserved. OAuth 2.1's resource-server binding is orthogonal: the bearer token carries an audience/resource indicator (per RFC 8707) that must match the resource being accessed. The two mechanisms compose badly at one exact seam — the seam where a *new* HTTP request (with a *new or same* token) is treated as a *continuation* of an *old* authorized stream. A transport-level 200 with a stream of replayed events is indistinguishable, to a naive client, from a legitimately resumed authorized stream. That is the boundary. ## What Was Observed A long-running agent held an SSE stream open against an MCP resource server. The stream carried tool-call results for a multi-step plan. The connection dropped (idle proxy timeout at 60s, well under the server's own 300s keepalive). The client reconnected with `Last-Event-ID: 41`. The server's resumption handler did three things in order: 1. Looked up the session by the opaque session identifier in the URL path. 2. Replayed buffered events with ID > 41 from the session's ring buffer. 3. Did **not** re-evaluate the resource indicator of the *presented* bearer token against the resource indicator that had been bound at stream *creation*. In this deployment the session identifier was scoped to the *client*, not the *token*. When the agent's token was silently rotated by the authorization server (same subject, new `aud` because the deployment had moved the resource server behind a new gateway hostname mid-session), the reconnect presented a token whose resource indicator no longer matched the stream's original binding. The server accepted it because the session lookup succeeded and the replay buffer existed. The client received 200, a valid `text/event-stream`, and events 42–58 — all of which had been produced *under the old authorization context*. The agent continued its plan, invoked a tool whose results were now being served across an authorization boundary, and only failed 40 seconds later when a *fresh* tool call was rejected by a downstream policy engine with a resource mismatch. The agent interpreted that late rejection as a tool bug and retried three times before the token's `aud` was finally surfaced in an error body. The observable signature is therefore: **a resumption that succeeds at the transport layer, replays events, and only fails at the next *new* authorization check.** The failure is displaced in time and attributed to the wrong component. ## Condition of Validity The invariant that must hold is: > For every event delivered on a stream, the resource indicator bound to the token authorizing the *original stream creation* must equal the resource indicator of the token presented on the *most recent resumption request* that delivered that event — or the server must refuse to replay and must terminate the stream with an authorization error. This invariant is violated whenever any of the following is true, and the violation is *silent*: - The session identifier is not cryptographically bound to the token's `jti` or to a hash of the resource indicator. - The replay buffer is keyed by session, not by (session, resource-indicator) pair. - The server treats `Last-Event-ID` as sufficient proof of continuity without re-validating the bearer token's audience against the session's recorded audience. - Token rotation (same subject, new `aud`, new `jti`) is permitted without invalidating in-flight sessions. The condition of validity for *safe* resumption is narrow: the server must persist, at stream creation, the tuple `(session_id, resource_indicator, token_jti)` and must, on every resumption, recompute the presented token's resource indicator and compare it to the stored value **before** touching the replay buffer. Equality of `session_id` is necessary but not sufficient. ## Decision Boundary The decision boundary is the point in the resumption handler where the server chooses between *replay* and *reject*. A correct implementation makes this decision on the tuple comparison, not on session existence. Concretely: - **Replay** iff `presented.resource_indicator == stored.resource_indicator` AND `presented.jti` is either equal to `stored.jti` or belongs to the same authorization grant (same `sub`, same `aud`, and the grant has not been revoked). Otherwise: - **Reject** with `401` and `WWW-Authenticate: Bearer error="invalid_token", error_description="resource indicator mismatch on resumption"`, and **do not** deliver any buffered events. Buffered events produced under the old binding must be discarded, not replayed, because they may contain data the new token is not authorized to see. The non-obvious part: a server that *does* re-validate but *still replays* the buffer after a mismatch is worse than one that doesn't validate at all, because it gives the client a false sense of continuity while leaking cross-binding data. The reject must be total: no replay, stream terminated, session invalidated. A client-side guardrail is also required, because the server cannot be trusted to be correct. The client must, on every resumption, compare the `aud`/resource indicator of the token it is about to present against the one it presented at stream creation, and if they differ, it must **not** resume — it must open a *new* stream, discard the old `Last-Event-ID`, and re-derive its plan state from a checkpoint rather than from the replay buffer. ## Operational Effect The practical consequence is that resumability and authorization are not composable by default, and the composition failure is *asymmetric*: it manifests as a late, misattributed error rather than an immediate transport failure. Agents that treat a 200 on resumption as proof of continuity will compound the error — they will consume replayed events under a stale authorization context, extend their plan, and only discover the mismatch when a downstream call fails, at which point the causal chain back to the resumption is no longer visible in the agent's context. The mitigation has two halves that must both be present: 1. **Server:** bind the session to the resource indicator at creation; re-validate on every resumption; reject totally (no replay) on mismatch; invalidate the session so the client cannot retry the same `Last-Event-ID`. 2. **Client:** treat `Last-Event-ID` as a *hint*, not a *credential*. Verify the presented token's resource indicator matches the stream's creation-time indicator before resuming. On mismatch, abandon the stream, checkpoint, and re-plan from durable state rather than from the replay buffer. Without both halves, the boundary is open. With only the server half, a buggy client still leaks state across bindings by replaying into a stale plan. With only the client half, a buggy server still replays cross-binding events to any client that asks. ```python import hashlib from dataclasses import dataclass from typing import Optional class ResumptionBindingError(RuntimeError): """Raised when an SSE resumption would cross an OAuth 2.1 resource-server binding boundary.""" @dataclass(frozen=True) class StreamBinding: session_id: str resource_indicator: str token_jti: str grant_id: str def _indicator_hash(indicator: str) -> str: return hashlib.sha256(indicator.encode("utf-8")).hexdigest() def resume_stream( *, stored: StreamBinding, presented_indicator: str, presented_jti: str, presented_grant_id: str, last_event_id: int, buffer_has_events_after: bool, ) -> int: """ Decide whether a resumption request may replay buffered events. Returns the last_event_id to replay from on success. Raises ResumptionBindingError on any binding mismatch, BEFORE touching the buffer. """ if _indicator_hash(stored.resource_indicator) != _indicator_hash(presented_indicator): raise ResumptionBindingError( f"resource indicator mismatch on resumption: " f"stream bound to {stored.resource_indicator!r}, " f"token presents {presented_indicator!r}; " f"refusing replay of events after id={last_event_id}" ) same_grant = presented_grant_id == stored.grant_id same_jti = presented_jti == stored.token_jti if not (same_grant or same_jti): raise ResumptionBindingError( f"token not part of original authorization grant: " f"stream grant={stored.grant_id!r} jti={stored.token_jti!r}, " f"presented grant={presented_grant_id!r} jti={presented_jti!r}" ) if not buffer_has_events_after: # Nothing to replay; still a valid resumption, but caller must not # assume continuity beyond last_event_id. return last_event_id return last_event_id def client_guard_before_resume( *, creation_indicator: str, current_indicator: str, last_event_id: int, ) -> Optional[int]: """ Client-side guard: return last_event_id to resume from, or None to force a fresh stream (discard replay buffer, re-plan from checkpoint). """ if _indicator_hash(creation_indicator) != _indicator_hash(current_indicator): # Do NOT resume. The replay buffer was produced under a different # authorization binding; consuming it would cross the boundary. return None return last_event_id ```