# Where must an instance re-verify the MCP OAuth 2.1 resource indicator after dynamic client registration, and why the token audience silently desynchronizes **Date of Record:** 2026 November 23 **Scope:** Applies to LLM agent instances that obtain OAuth 2.1 tokens for remote MCP tool servers via Dynamic Client Registration (DCR) and the `resource` parameter (RFC 8707). Does not apply to statically pre-registered clients with a single fixed audience, nor to bearer tokens minted by the same trust domain that issues the agent's identity warrant. ## Core Distinction There are two distinct notions of "the resource this token is for," and MCP OAuth 2.1 binds them at different moments: 1. **The requested resource indicator** — the `resource` parameter the agent sends on the authorization request and again on the token request. This is what the authorization server (AS) echoes into the access token's `aud` claim. 2. **The actual tool endpoint** — the URL the MCP client later POSTs JSON-RPC to, derived at runtime from the server's advertised `endpoint`/discovery document. The invariant that must hold is `aud(token) ⊇ origin(endpoint)` for every tool call. The non-obvious failure is that **DCR happens before the resource indicator is finalized, and the endpoint is discovered after the token is minted**, so the binding is established against a value the client has not yet observed. The resource indicator is not a property of the client; it is a property of the *resolved* server, and DCR treats the client as if it were. ## What Was Observed A remote MCP server was onboarded through the standard flow: the agent discovered `/.well-known/oauth-protected-resource` and `/.well-known/oauth-authorization-server`, performed DCR with the AS to obtain a `client_id`, then requested a token with `resource=https://tools.example.com/mcp`. The AS, per its RFC 8707 implementation, set `aud` to exactly that string. The MCP server's discovery document, however, advertised its JSON-RPC endpoint as `https://tools.example.com/mcp/v2` (a version-suffixed path). The client constructed the endpoint from discovery, not from the resource indicator it had requested. Every tool call carried `Authorization: Bearer ` with `aud=https://tools.example.com/mcp`, and the resource server rejected each with `401 invalid_token: audience mismatch`. The failure was not a 401 storm at first call. The first call succeeded because the resource server's audience check was `aud` *prefix* match on the path segment during a soft-launch window; the strict equality check was enabled two hours later, after the token had been cached. The agent's cached credential became invalid mid-task, and because the MCP client treated `401` on a tool call as a transient transport error, it retried the same token five times, then surfaced a generic "tool unavailable" to the reasoning loop — which, unable to distinguish auth failure from network failure, re-planned around a tool that was in fact reachable. The second, subtler observation: after the client re-ran DCR (because the AS rotated `client_id` on `invalid_client`), the new registration inherited the *old* `resource` binding from the client's persisted config, not from the freshly discovered endpoint. The desync reproduced across restarts. The registration record and the endpoint record were persisted in two different stores with no cross-check. ## Condition of Validity The `aud`/endpoint binding is valid **only if** the resource indicator used at authorization time equals the origin of the endpoint used at call time, modulo the AS's documented audience-matching rule (exact, prefix, or origin-only). This condition is violated whenever any of the following holds: - The MCP server advertises an endpoint whose path or host differs from the `resource` value the client registered. - The AS applies audience matching more strictly than the client assumed (equality vs. prefix vs. origin). - The endpoint is re-resolved (version bump, failover to a replica host, CDN edge rewrite) after the token is minted. - DCR is re-run and the client reuses a cached `resource` value instead of the current discovery result. None of these are detectable at registration time. All are detectable at call time, which is why the check must live in the call path, not the onboarding path. ## Decision Boundary The boundary is: **re-verify the resource indicator against the resolved endpoint on every token acquisition, and again on every `401` before retrying.** - On token acquisition: compute `origin(resolved_endpoint)` from the discovery document *as fetched in this session*, and assert it is contained in the `resource` value being requested. If discovery and the cached resource disagree, the cached resource is wrong; re-run DCR with the discovered value. - On `401 invalid_token` with an audience-mismatch body: do **not** retry the same token. Distinguish audience failure from expiry (inspect `WWW-Authenticate` error code), invalidate the cached credential, re-resolve the endpoint, and only then re-acquire. - On DCR re-run: the `resource` parameter must be recomputed from the current discovery result, never read from persisted client config. The boundary is *not* "validate the token once at startup." Startup validation passes; the failure is a post-startup endpoint or policy change. The guardrail is a call-path invariant, not a boot check. ## Operational Effect Without the call-path check, the agent experiences a *silent capability loss*: a reachable tool is reported as unavailable, the reasoning loop re-plans around it, and the resulting plan is degraded but not obviously wrong. The failure does not crash; it corrupts the plan. Because the `401` is indistinguishable from a transport error to the loop, the agent's error-compounding behavior turns one auth desync into a cascade of unnecessary tool substitutions. With the check, the failure becomes a typed, bounded event: an `AudienceBindingError` raised at the call site, carrying both the token's `aud` and the resolved endpoint origin, which the loop can route to a re-authentication sub-task rather than to re-planning. The invariant converts a silent semantic failure into a loud, recoverable one — which is the only form of failure an autonomous agent can safely handle. ```python import urllib.parse from dataclasses import dataclass class AudienceBindingError(RuntimeError): """Raised when the token audience does not cover the resolved MCP endpoint origin.""" @dataclass(frozen=True) class Token: access_token: str audience: str # the `aud` claim, i.e. the resource indicator the AS bound @dataclass(frozen=True) class ResolvedEndpoint: url: str @property def origin(self) -> str: p = urllib.parse.urlsplit(self.url) return f"{p.scheme}://{p.netloc}" def _audience_covers(aud: str, origin: str, match_mode: str) -> bool: if match_mode == "exact": return aud == origin if match_mode == "origin": return urllib.parse.urlsplit(aud).netloc == urllib.parse.urlsplit(origin).netloc if match_mode == "prefix": return origin.startswith(aud) or aud.startswith(origin) raise ValueError(f"unknown audience match mode: {match_mode}") def assert_binding(token: Token, endpoint: ResolvedEndpoint, match_mode: str = "origin") -> None: """ Call-path invariant: the token's audience must cover the resolved endpoint origin. Run on every token acquisition and on every 401 before any retry. """ if not _audience_covers(token.audience, endpoint.origin, match_mode): raise AudienceBindingError( f"token aud={token.audience!r} does not cover endpoint origin={endpoint.origin!r} " f"(match_mode={match_mode}); refusing to send credential. " f"Re-resolve endpoint, recompute resource indicator, and re-run DCR." ) def acquire_token_for_endpoint( discovery_resource: str, endpoint: ResolvedEndpoint, mint, match_mode: str = "origin", ) -> Token: # The resource indicator must be derived from the CURRENT discovery result, # never from persisted client config, or DCR re-runs inherit a stale binding. if urllib.parse.urlsplit(discovery_resource).netloc != urllib.parse.urlsplit(endpoint.origin).netloc: raise AudienceBindingError( f"discovery resource {discovery_resource!r} and endpoint {endpoint.origin!r} " f"disagree on host; DCR would register an unusable audience." ) token = mint(resource=discovery_resource) assert_binding(token, endpoint, match_mode) return token ```