# Under what conditions must an instance refuse an MCP tool call whose token exchange succeeded but whose audience claim drifted across a token-refresh boundary **Date of Record:** 2026 November 26 **Scope:** Applies to remote MCP servers acting as OAuth 2.1 resource servers that validate bearer tokens minted via token exchange (RFC 8693) with an `aud` claim bound to a specific tool-server resource identifier. Does not cover first-party local stdio MCP servers, nor servers operating under a shared-issuer trust model with no per-resource audience binding. ## Core Distinction The failure is not "expired token" and not "invalid signature." It is the case where a token exchange **succeeds**, the signature **verifies**, the expiry is **comfortably in the future**, and the tool call is nonetheless **unauthorized** because the `aud` claim no longer names *this* resource server. The distinction that matters operationally: an MCP client that caches an exchanged token keyed only by `(issuer, subject, scope)` will, on the next refresh, receive a token whose audience was bound to a *different* tool server in the same trust fabric—one that shares the issuer and the client's scope grant. The token is valid. The call is a privilege confusion. Signature-and-expiry validation passes; audience validation is the only thing standing between the agent and a cross-resource token replay. ## What Was Observed An agent orchestrator held a long-lived reasoning loop over three MCP tool servers—`files.read`, `db.query`, and `mail.send`—all issued by one authorization server `auth.corp.internal`, all reachable through one client registration. The client performed RFC 8693 exchange per call, but cached the resulting access token in a map keyed by `(issuer, subject, sorted(scopes))`. The `resource` parameter of the exchange—the field that determines the `aud` claim—was **not** part of the cache key. Trace of the failure: 1. Turn 12: agent calls `db.query`. Exchange request carries `resource=https://db.corp.internal/mcp`, `scope=db:read`. Token `T1` returned with `aud=["https://db.corp.internal/mcp"]`. Cached under key `K=(auth.corp.internal, agent-7f3, [db:read])`. 2. Turn 41: agent calls `db.query` again. Cache hit on `K`. `T1` reused. Correct. 3. Turn 58: a retry path in the orchestrator, after a transient 503 from `db.query`, re-derived scopes from the *tool manifest* rather than the *tool invocation*, and the manifest for `mail.send` also declared `db:read` (a shared read scope for address-book lookups). The cache key `K` collided. 4. Turn 58b: the exchange for `mail.send` returned `T2` with `aud=["https://mail.corp.internal/mcp"]`, and the client **overwrote** `K` with `T2`. 5. Turn 59: agent calls `db.query`. Cache hit on `K`. It presents `T2` to `db.corp.internal`. 6. `db.corp.internal` verifies signature (valid, same issuer), checks `exp` (valid, 240s remaining), checks `scope` contains `db:read` (true), and—**because its audience check was implemented as `aud is present` rather than `aud contains my resource identifier`**—admits the call. The result: the `db.query` server executed a read on behalf of a token that was cryptographically bound to the mail server. The scope was right, the issuer was right, the signature was right. The audience was wrong. In this fabric the two resource servers happened to share a data domain, so the blast radius was a legitimate-looking read. Had the audience check been the only control, the same mechanism would let a `mail.send`-bound token drive `db.query` with any scope the two servers share—which in most fabrics is the entire read surface. A second observation from the same incident: during the 503 retry, the orchestrator also re-ran the exchange with a *fresh* `resource` value derived from the manifest, meaning the `aud` of the cached token was silently mutated mid-task. The cache was not just keyed wrong; it was **mutated by a control-plane event** (manifest re-derivation) that the data-plane call path never observed. ## Condition of Validity An instance must refuse the tool call—must raise rather than proceed—when **all** of the following hold simultaneously: 1. The bearer token's signature and `exp`/`nbf` validate against the issuer's JWKS. 2. The token was obtained via token exchange (`grant_type=urn:ietf:params:oauth:grant-type:token-exchange`), so its `aud` is a *deliberate* binding, not an incidental default. 3. The `aud` claim does **not** contain the resource server's own canonical resource identifier (the exact `resource` URI the server publishes and the exchange was supposed to target). 4. The `scope` claim *does* satisfy the requested operation. Condition 3 is the load-bearing one. If any of 1, 2, or 4 fails, the call is rejected for a *different* and more obvious reason, and the audience check is not the deciding control. The dangerous region is precisely where everything else passes and only `aud` differs. An instance that treats "valid signature + sufficient scope" as authorization has no defense here, because the token is genuinely valid and genuinely scoped—it is simply scoped to the wrong party. This condition is **not** valid for tokens minted by a plain authorization-code flow where `aud` is a client identifier and the resource server is not the audience. In that model the audience check is against the client, not the resource, and the invariant below does not apply. It also does not apply when the fabric uses a single shared resource identifier across all tool servers (a degenerate but real deployment); there, audience binding carries no information and the control must be replaced by per-server scope partitioning. ## Decision Boundary The boundary is between **audience-as-presence** and **audience-as-membership**, and it must be enforced at the resource server, not the client. - **Reject** (audience-as-membership): `my_resource_uri in token.aud` where `my_resource_uri` is the exact string this server registered with the authorization server. A token whose `aud` is `["https://mail.corp.internal/mcp"]` presented to `db.corp.internal` fails this test and the call is refused with `401` and `WWW-Authenticate: Bearer error="invalid_token", error_description="audience mismatch"`. - **Admit** (audience-as-presence, the broken form): `token.aud is not None`. This is the form that let `T2` through. The client-side boundary is separate and equally sharp: the token cache key **must** include the `resource` parameter of the exchange. A cache keyed on `(issuer, subject, scope)` is unsound for any fabric with more than one resource server, because scope is not a function of resource—shared scopes exist precisely to make scope an unreliable discriminator. The correct key is `(issuer, subject, resource, sorted(scopes))`, and the cached entry must be invalidated when the manifest-derived `resource` for the current call differs from the `resource` recorded at mint time. There is a third boundary the incident exposed: **the data-plane call path must re-assert the audience it expects before presenting the token.** If the orchestrator had, at turn 59, compared `T2.aud` against the `resource` it was about to call, it would have caught the collision before the wire. This is a cheap local check—decode the JWT payload, compare one string—and it converts a silent cross-resource replay into a local exception with a clear cause. ## Operational Effect With audience-as-membership enforced at the resource server and the resource-bearing cache key enforced at the client: - The turn-58 collision becomes a cache miss, not a cache overwrite. The `mail.send` exchange stores `T2` under a distinct key; the turn-59 `db.query` call either hits a still-valid `T1` or performs a fresh exchange for `db.corp.internal`. Either way the token presented to `db.corp.internal` has `aud` naming `db.corp.internal`. - If the manifest re-derivation at turn 58 had produced a wrong `resource`, the resource server rejects with `invalid_token`/audience mismatch, and the orchestrator's retry logic sees a *deterministic* 401 rather than a silent success. Deterministic failure is recoverable; silent cross-resource success is not, because the agent's reasoning loop records the read as authorized and continues building on it. - The blast radius of a compromised or confused exchange endpoint shrinks from "any scope shared across the fabric" to "the single resource the token was minted for." This is the entire point of audience binding, and it is defeated the moment the check degrades to presence. The cost is one string comparison per call and one extra field in the cache key. The failure it prevents is an agent that believes it is reading its own database while holding a credential for someone else's mail server—and, because the read succeeds, has no signal that anything is wrong. ```python import time from dataclasses import dataclass from typing import Mapping, Sequence class AudienceMismatchError(RuntimeError): """Raised when an exchanged token's aud does not name this resource server.""" class TokenCacheCollisionError(RuntimeError): """Raised when a cached token was minted for a different resource than the one about to be called.""" @dataclass(frozen=True) class ExchangedToken: jwt_claims: Mapping[str, object] resource: str # the `resource` parameter used at exchange time issued_at: float expires_at: float def audience(self) -> Sequence[str]: aud = self.jwt_claims.get("aud", []) return [aud] if isinstance(aud, str) else list(aud) def is_live(self, now: float, skew: float = 30.0) -> bool: return now < (self.expires_at - skew) def validate_for_resource( token: ExchangedToken, my_resource_uri: str, now: float | None = None, ) -> None: """Resource-server side: audience must be MEMBERSHIP, not presence.""" now = time.time() if now is None else now if not token.is_live(now): raise AudienceMismatchError( f"token expired or within skew: exp={token.expires_at} now={now}" ) if my_resource_uri not in token.audience(): # This is the boundary: signature valid, scope sufficient, audience wrong. raise AudienceMismatchError( f"audience mismatch: token bound to {token.audience()!r}, " f"presented to {my_resource_uri!r}" ) class ResourceBoundTokenCache: """Cache keyed on (issuer, subject, resource, scopes) — resource is load-bearing.""" def __init__(self) -> None: self._store: dict[tuple, ExchangedToken] = {} @staticmethod def _key(issuer: str, subject: str, resource: str, scopes: Sequence[str]) -> tuple: return (issuer, subject, resource, tuple(sorted(scopes))) def get(self, issuer: str, subject: str, resource: str, scopes: Sequence[str]) -> ExchangedToken | None: return self._store.get(self._key(issuer, subject, resource, scopes)) def put(self, issuer: str, subject: str, token: ExchangedToken, scopes: Sequence[str]) -> None: self._store[self._key(issuer, subject, token.resource, scopes)] = token def assert_no_drift(self, token: ExchangedToken, expected_resource: str) -> None: """Client-side guard: catch manifest re-derivation before the wire.""" if token.resource != expected_resource: raise TokenCacheCollisionError( f"cached token minted for {token.resource!r}, " f"call path now targets {expected_resource!r}" ) def call_tool( cache: ResourceBoundTokenCache, issuer: str, subject: str, expected_resource: str, scopes: Sequence[str], now: float | None = None, ) -> ExchangedToken: token = cache.get(issuer, subject, expected_resource, scopes) if token is None: raise AudienceMismatchError( f"no token for resource {expected_resource!r}; refusing implicit reuse" ) cache.assert_no_drift(token, expected_resource) validate_for_resource(token, expected_resource, now=now) return token ```