# Where must an instance revalidate the OAuth 2.1 resource indicator against the SSE `Last-Event-ID` resumption target in MCP stateless HTTP transport? **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers exposing the streamable-HTTP transport with SSE resumability (`Last-Event-ID` replay) behind an OAuth 2.1 resource server that enforces the `resource` parameter (RFC 8707) on tokens. Does not apply to stdio transport, nor to purely stateful session-bound HTTP servers that pin a single client connection to a single process for its lifetime. ## Core Distinction The distinction that matters is between *token audience binding* and *event-stream resumption binding*. In MCP's streamable-HTTP profile, a client obtains a bearer token whose `aud`/`resource` claim is scoped to a specific MCP endpoint URI, then opens an SSE stream and may later resume it with `GET /mcp` plus `Last-Event-ID`. OAuth 2.1 resource indicators are validated at the *authorization boundary* — once per token, typically by a middleware that compares the token's `resource` claim to the request's canonical URL. The SSE replay path is a *separate* authorization decision: the replay server must decide whether the bearer presenting `Last-Event-ID: 42` is entitled to event 42, which was emitted under a stream that may have been opened by a *different* token, at a *different* endpoint path, or by a client whose grant has since been revoked. The boundary failure occurs when the resource-indicator check is applied to the request URL but not to the *event stream identity* the resume request is asking to rejoin. ## What Was Observed A stateless MCP deployment fronted by three replicas, each holding a Redis-backed SSE event log keyed by `(session_id, stream_id, event_id)`. Tokens carried `resource=https://mcp.example.com/mcp` and were validated by a middleware that canonicalized the incoming request URL and compared it to the `resource` claim. Clients opened `POST /mcp` to start a stream, received `200` with `Content-Type: text/event-stream` and a `Mcp-Session-Id` header, and consumed events with monotonically increasing `id:` fields. On transport drop, clients resumed with `GET /mcp` + `Mcp-Session-Id` + `Last-Event-ID`. The failure trace: 1. Client A authenticates with token `T_A` (`resource=https://mcp.example.com/mcp`, `sub=tenant-A`), opens stream `S_1`, receives events `1..10`, disconnects at event 10. 2. Client B, a *different* tenant, authenticates with `T_B` (`resource=https://mcp.example.com/mcp`, `sub=tenant-B`) and — either through a buggy client library, a shared session cache, or a deliberately replayed `Mcp-Session-Id` — issues `GET /mcp` with `Mcp-Session-Id: S_1` and `Last-Event-ID: 10`. 3. The resource-indicator middleware validates `T_B` against `https://mcp.example.com/mcp` — **pass**. The `resource` claim matches the URL. The middleware has no visibility into the fact that `S_1` was minted under `sub=tenant-A`. 4. The SSE replay handler looks up `(S_1, event_id=10)` in Redis, finds events `11..N` still buffered, and streams them to client B. No error was raised. The token was valid, the `resource` matched, the session id was a well-formed opaque string. The replay handler treated `Mcp-Session-Id` as a *capability token* (possession = access) while the resource-indicator layer treated it as an *identifier*. Those two interpretations are inconsistent, and the gap between them is the boundary. The same class of failure appears in two variants: - **Endpoint-path variant.** A server is reachable at `https://mcp.example.com/v1/mcp` and `https://mcp.example.com/v2/mcp`. A token minted with `resource=https://mcp.example.com/v1/mcp` is presented to `GET /v2/mcp` with a `Last-Event-ID` from a stream originally opened on `/v1/mcp`. If the middleware canonicalizes trailing slashes but not version segments, or if the reverse proxy rewrites `/v2/mcp` → `/mcp` before the middleware sees it, the resource check passes while the replay pulls events from a differently-scoped stream. - **Revocation variant.** Token `T_A` is revoked (RFC 7009) mid-stream. The client's next `GET /mcp` resume carries the revoked token. If the resource server caches positive token introspection results for the token's remaining lifetime (common optimization), the resume succeeds and replays events emitted *after* revocation — events the revoked principal should never see. ## Condition of Validity The invariant that must hold for stateless resumption to be safe: > *For every successful `GET /mcp` resume request, the authenticated principal `sub` and the `resource` claim of the presented token must both equal the `sub` and `resource` recorded at the time the stream identified by `Mcp-Session-Id` was opened.* This is a *conjunction* across two authorization decisions taken at different times. It holds only if the server persists, alongside each event log entry, the `(sub, resource, token_jti, issued_at)` tuple that authorized the stream's creation, and re-checks that tuple on every resume — not just the URL-to-`resource` match. The invariant is *not* implied by OAuth 2.1 resource indicators alone. RFC 8707 binds a token to a resource URI; it says nothing about binding a *stream* to a *principal*. MCP's spec explicitly notes that `Mcp-Session-Id` is opaque and that servers "MAY" tie it to authorization state, but the streamable-HTTP transport's statelessness means the session id is the *only* continuity handle the client carries across reconnects. If the server treats it as a bearer capability, the resource-indicator check becomes decorative on the resume path. ## Decision Boundary The decision the server must make on every `GET /mcp` with `Last-Event-ID`: | Check | Pass condition | Failure mode if skipped | |---|---|---| | Token signature + expiry | Standard JWT validation | Trivial — not the interesting boundary | | `resource` == canonical request URL | RFC 8707 §2 | Endpoint-path variant | | Token not revoked | Introspection or short TTL | Revocation variant | | **`token.sub` == `stream.sub`** | Persisted at stream open | **Cross-tenant replay** | | **`token.resource` == `stream.resource`** | Persisted at stream open | **Cross-endpoint replay** | | **`Last-Event-ID` ∈ emitted set for this stream** | Event log index | Replay of never-emitted or pruned ids | The boundary is the third row from the bottom. It is the one that a resource-indicator middleware *cannot* enforce because it does not know which stream the request is resuming until after the middleware has already returned `next()`. Enforcement must happen inside the SSE replay handler, and it must be a *hard* check that returns `403` — not a soft fallback that opens a *new* stream silently, because silent fallback converts a replay attack into a fresh-stream injection, which is worse: the attacker gets a live stream under their own token that the client believes is a resumption. The correct behavior on mismatch is: reject with `403`, do not emit any buffered events, and *do not* mint a new `Mcp-Session-Id`. The client must re-authenticate and re-open. This is a deliberate availability cost — a legitimate client whose token rotated mid-stream will be forced to restart — accepted because the alternative is a silent cross-principal data leak. ## Operational Effect Enforcing the invariant changes three things in a stateless MCP deployment: 1. **Event log schema.** Every SSE event entry must carry `(sub, resource, jti, issued_at)` as immutable metadata written at emit time, not at read time. The replay handler reads these and compares against the resume token's claims before releasing any event. This roughly doubles the per-event storage cost; for high-fanout tool-call streams this is the dominant operational expense and must be budgeted. 2. **Token rotation semantics.** A client that rotates its token mid-stream (short TTL, or refresh triggered by a `401` on the resume) will now *fail* the `sub`/`resource` check if the new token's `jti` differs — unless the server compares on `(sub, resource)` only and treats `jti` as advisory. The correct choice is to compare on `(sub, resource)` and log `jti` mismatch as a warning, not a rejection. Comparing on `jti` produces false positives on every legitimate rotation and drives operators to disable the check entirely — the classic "security control that fails open under normal operation" pattern. 3. **Revocation propagation.** Because the resume path now re-reads the stream's stored `(sub, resource)`, a revoked token must be rejected *before* the replay handler runs. This forces introspection (or a revocation-list check) on every resume, not just on stream open. For stateless deployments this is the expensive part: you cannot cache positive introspection results across the resume boundary without reopening the revocation variant. The pragmatic bound is to cache for a window shorter than the revocation list's propagation SLA, and to document that window as the maximum post-revocation replay exposure. The invariant does not prevent a *same-principal* replay (attacker who steals `T_A` can replay `S_1` — that is a token theft problem, out of scope for this boundary). It prevents the *cross-principal* and *cross-endpoint* replay that the resource-indicator check alone leaves open, and it is the minimum guardrail required for `Mcp-Session-Id` to be treated as an identifier rather than a capability. ```python from dataclasses import dataclass from typing import Optional class ResourceIndicatorResumeMismatch(RuntimeError): """Raised when a GET /mcp resume request's token does not match the (sub, resource) tuple recorded when the target SSE stream was opened.""" pass @dataclass(frozen=True) class StreamOrigin: sub: str resource: str jti: str issued_at: int @dataclass(frozen=True) class ResumeToken: sub: str resource: str jti: str revoked: bool def authorize_sse_resume( stream: Optional[StreamOrigin], token: ResumeToken, canonical_request_url: str, ) -> None: # RFC 8707: token must be audience-bound to the endpoint being called. if token.resource != canonical_request_url: raise ResourceIndicatorResumeMismatch( f"token resource={token.resource!r} does not match " f"request URL={canonical_request_url!r}" ) if token.revoked: raise ResourceIndicatorResumeMismatch( f"token jti={token.jti!r} for sub={token.sub!r} is revoked; " f"refusing to replay buffered SSE events" ) if stream is None: raise ResourceIndicatorResumeMismatch( "Mcp-Session-Id does not correspond to any known stream; " "refusing to mint a new stream in place of a resume" ) # The invariant the resource-indicator middleware cannot enforce: # the resuming principal must equal the principal that opened the stream. if token.sub != stream.sub: raise ResourceIndicatorResumeMismatch( f"resume principal sub={token.sub!r} != stream origin " f"sub={stream.sub!r}; cross-tenant replay blocked" ) # Endpoint-path variant: token must also be scoped to the same resource # the stream was opened under, not merely to the URL it is resuming at. if token.resource != stream.resource: raise ResourceIndicatorResumeMismatch( f"resume resource={token.resource!r} != stream origin " f"resource={stream.resource!r}; cross-endpoint replay blocked" ) # jti mismatch is logged upstream but NOT rejected: legitimate token # rotation mid-stream must not break resumption, or operators will # disable this check entirely. ```