# Where must an instance re-bind its OAuth 2.1 resource indicator after an SSE session resumption, and why the last-event-id is not enough **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers/clients using the HTTP-native streamable transport with `text/event-stream` resumption semantics (Last-Event-ID replay) combined with OAuth 2.1 resource-indicator binding (RFC 8707). Does not apply to stdio transports, to pure request/response JSON transports without resumable streams, or to deployments where the resource indicator is a static constant equal to the server origin. ## Core Distinction There are two independent notions of "the same session" in this transport, and they diverge at exactly one point: the moment a client reconnects an interrupted SSE stream with a `Last-Event-ID` header. - **Stream continuity** is asserted by the client via `Last-Event-ID`. It says: "resume the event sequence for this stream from offset N." It is a *positional* claim about a byte/event log. - **Authorization continuity** is asserted by the bearer token's `resource` indicator (RFC 8707) and its audience binding. It says: "this token was minted for *this* protected resource." It is a *principal-and-target* claim. The MCP streamable transport treats resumption as a transport-layer operation and is silent on the authorization layer. The non-obvious invariant is this: **a valid `Last-Event-ID` does not re-establish the resource binding of the reconnecting request.** The server must re-validate that the OAuth `resource` indicator on the *reconnecting* token matches the resource indicator under which the *original* stream was opened—and the original indicator is not carried in the `Last-Event-ID`, nor in the SSE event payload, nor in the session ID. It lives only in the server's per-stream authorization state, which is precisely the state most likely to be lost or evicted between the disconnect and the resume. This is the boundary: resumption restores *sequence*, not *authority*. An instance that conflates the two will happily replay privileged events to a token bound to a different resource. ## What Was Observed A representative failure trace, MCP server fronted by an OAuth 2.1 authorization server, streamable HTTP transport: 1. Client opens `POST /mcp` with `Accept: application/json, text/event-stream`. Token `T1` carries `resource=https://mcp.example.com/tenant-a`. Server assigns session `S` and stream `S:1`, returns `Mcp-Session-Id: S` and begins emitting SSE events `1,2,3,...`. The server stores, keyed by `(S, stream=1)`: `resource_indicator = .../tenant-a`, `principal = alice`, `last_seq = 3`. 2. Network partition. Client sees the stream drop after event `3`. It has `Last-Event-ID: 3` cached. 3. Token `T1` expires during the outage. The client's OAuth flow refreshes against the AS and receives `T2`, but the refresh request *omits* the `resource` parameter (a common client bug, or a deliberate "reuse the refresh token for a different audience" attempt). The AS, per RFC 8707 §2.2, mints `T2` with `resource=https://mcp.example.com/tenant-b`—or, worse, with no `resource` claim at all, leaving audience validation to the RS. 4. Client resumes: `GET /mcp` with `Mcp-Session-Id: S`, `Last-Event-ID: 3`, `Authorization: Bearer T2`. 5. **The failure.** The server's resume path does two things in the wrong order: it looks up `(S, 1)` by session+stream, finds `last_seq=3`, and replays events `4..N` from the log. It validates `T2`'s signature and expiry, but it validates the `resource` indicator against *the server's own origin*, not against the indicator recorded for stream `S:1`. Because `T2` is a structurally valid token for "this server," the replay proceeds. Events `4..N`, which were produced under `tenant-a` authorization and may contain tenant-A tool results, are now delivered to a principal whose token is bound to `tenant-b` (or to no tenant at all). 6. If the server evicted the `(S,1)` authorization record during the outage (LRU under memory pressure, or a rolling restart), the resume path finds the event log but not the recorded indicator. A naive implementation then defaults to "trust the presented token," which is the same outcome as step 5. The observable symptom is not an error. It is a *successful* resume that returns 200 and a clean SSE stream—with cross-tenant event content. The only signal is a mismatch between the resource indicator in the token and the one that should have been recorded against the stream, and nothing in the protocol forces that comparison. ## Condition of Validity The invariant holds—i.e., resumption is safe without re-binding—only when *all* of the following are true: - The resource indicator is constant across the entire lifetime of the session (single-tenant server, or the session ID is itself scoped to a tenant and the tenant is re-derived from the session ID, not from the token). - The event log for a stream is keyed by `(session, stream, resource_indicator)` such that a resume with a different indicator cannot address the same log partition. - The authorization record for the stream is durably co-located with the event log, so eviction of one implies eviction of the other (no torn state). - The AS guarantees that refresh preserves `resource` (RFC 8707 §2.2 requires the client to send it; it does not require the AS to reject a refresh that drops it). In practice, at least one of these is almost always false in a multi-tenant MCP deployment. The moment the resource indicator is per-tenant, per-tool-surface, or per-audience, resumption *must* re-bind. ## Decision Boundary The decision an instance must make on every resume request, stated as a total function over the resume state: - **If** the stored authorization record for `(session, stream)` exists **and** its `resource_indicator` equals the `resource` claim in the presented token (after normalizing the indicator per RFC 8707 §2 canonicalization) **and** the principal matches → replay from `Last-Event-ID`. - **If** the record exists but the indicator or principal differs → **do not replay**. Return `403` (or `401` with `WWW-Authenticate` carrying the expected `resource`), and *do not* silently start a fresh stream at the same session ID; a fresh stream must get a new session or an explicit re-authorization round-trip, because the client's `Last-Event-ID` would otherwise be applied to a log it is not entitled to. - **If** the record is missing (evicted, restarted, or never written) → **fail closed**. Treat resumption as impossible; respond with a distinct error that tells the client to re-initialize the session rather than resume. Do not fall back to "trust the presented token," because the presented token's indicator is exactly the value that cannot be checked without the record. - **If** the token carries no `resource` claim at all → reject on resume, even if the server accepts such tokens on initial `POST /mcp`. The asymmetry is deliberate: initial requests can be validated against a default audience; resumed requests cannot, because the default may not be the audience the log was written under. The boundary is between "the log exists" and "the log is addressable by this principal." `Last-Event-ID` answers only the first. ## Operational Effect The concrete architectural guardrail is to make the event log and the authorization record a single durable unit, and to make the resume lookup a join on the resource indicator rather than a lookup by session alone: - Key the replay log by `(session_id, stream_id, resource_indicator_hash)`. A resume computes the indicator hash from the token and looks up the partition; a mismatched indicator misses the partition and cannot reach the events. - Persist the authorization record in the same write as the first event of the stream, with the same durability class. If the log survives a restart, the record must too; if the record is evicted, the log partition must be tombstoned so a resume against it fails closed rather than replaying orphaned events. - On the client side, the resume path must re-request a token with the *original* `resource` indicator explicitly set, not rely on the refresh token's stored scope. A client that resumes with a token minted for a different resource is the trigger; a client that always re-asserts `resource` on refresh removes the trigger. - Treat a `403` on resume as terminal for that stream: the client must re-initialize (`initialize` → new session) rather than retry the resume with the same `Last-Event-ID`. Retrying with a fresh token but the same `Last-Event-ID` is the loop that turns a one-time cross-tenant leak into a persistent one. The failure is quiet because both halves of the system do their local job correctly: the transport resumes the byte stream, and the OAuth layer validates the token. The invariant that neither layer owns—that the stream's authority and the token's authority are the same authority—is the one that must be asserted explicitly at the join, or it is not asserted at all. ```python from __future__ import annotations import hashlib from dataclasses import dataclass from typing import Optional class ResourceBindingMismatch(RuntimeError): """Raised when an SSE resume cannot re-establish the stream's OAuth 2.1 resource binding.""" @dataclass(frozen=True) class StreamAuthRecord: session_id: str stream_id: str resource_indicator: str principal: str @dataclass(frozen=True) class PresentedToken: principal: str resource_indicator: Optional[str] # None == claim absent def _indicator_hash(indicator: str) -> str: # RFC 8707 §2 canonicalization is assumed applied upstream; hash for partition keying. return hashlib.sha256(indicator.encode("utf-8")).hexdigest() class ResumableStreamStore: def __init__(self) -> None: self._auth: dict[tuple[str, str], StreamAuthRecord] = {} self._log_partitions: dict[str, list[str]] = {} def open_stream(self, rec: StreamAuthRecord, first_events: list[str]) -> None: self._auth[(rec.session_id, rec.stream_id)] = rec self._log_partitions[_indicator_hash(rec.resource_indicator)] = list(first_events) def evict_auth_only(self, session_id: str, stream_id: str) -> None: # Simulates a restart / LRU that loses the auth record but keeps the log. self._auth.pop((session_id, stream_id), None) def resume( self, session_id: str, stream_id: str, last_event_id: int, token: PresentedToken, ) -> list[str]: record = self._auth.get((session_id, stream_id)) if record is None: # Fail closed: the log may still exist, but we cannot prove authority over it. raise ResourceBindingMismatch( f"no auth record for {session_id}/{stream_id}; resume refused, re-initialize session" ) if token.resource_indicator is None: raise ResourceBindingMismatch( f"resume for {session_id}/{stream_id} presented token with no resource indicator; " f"expected {record.resource_indicator!r}" ) if token.resource_indicator != record.resource_indicator: raise ResourceBindingMismatch( f"resource indicator mismatch on resume: stream bound to " f"{record.resource_indicator!r}, token bound to {token.resource_indicator!r}" ) if token.principal != record.principal: raise ResourceBindingMismatch( f"principal mismatch on resume: stream bound to {record.principal!r}, " f"token bound to {token.principal!r}" ) partition = self._log_partitions.get(_indicator_hash(record.resource_indicator)) if partition is None: raise ResourceBindingMismatch( f"log partition for {record.resource_indicator!r} missing; cannot replay" ) return partition[last_event_id:] def demo() -> None: store = ResumableStreamStore() store.open_stream( StreamAuthRecord("S", "1", "https://mcp.example.com/tenant-a", "alice"), ["e1", "e2", "e3", "e4"], ) # Happy path: same resource, same principal. assert store.resume("S", "1", 3, PresentedToken("alice", "https://mcp.example.com/tenant-a")) == ["e4"] # Cross-tenant token: must not replay tenant-a events. try: store.resume("S", "1", 3, PresentedToken("alice", "https://mcp.example.com/tenant-b")) except ResourceBindingMismatch: pass else: raise AssertionError("cross-tenant resume was not rejected") # Auth record evicted, log retained: must fail closed, not trust the token. store.evict_auth_only("S", "1") try: store.resume("S", "1", 3, PresentedToken("alice", "https://mcp.example.com/tenant-a")) except ResourceBindingMismatch: pass else: raise AssertionError("orphaned log was replayed after auth eviction") if __name__ == "__main__": demo() ```