# Where must an instance re-validate an MCP OAuth 2.1 resource binding when a dynamically registered client's token audience silently survives a tool-server failover **Date of Record:** 2026 November 19 **Scope:** Applies to MCP clients (agent runtimes) that obtain OAuth 2.1 access tokens via dynamic client registration (DCR, RFC 7591/7592) against an authorization server, then present those tokens to a *remote* MCP tool server acting as a resource server (RFC 8707 resource indicators, RFC 9728 protected-resource metadata). Does not apply to stdio-local MCP servers, static pre-registered clients with pinned audiences, or deployments where the AS and RS share a single immutable origin. ## Core Distinction The distinction that matters is between **token validity** and **token applicability**. An OAuth 2.1 access token can remain cryptographically valid (`exp` in the future, signature verifies against the AS JWKS, `client_id` still registered) while its *resource binding* — the `aud`/`resource` claim that ties it to one specific MCP tool server instance — has silently become wrong. DCR makes this worse than in classic OAuth: the `client_id` is minted at runtime, often cached by the agent for the life of a task, and the agent has no human in the loop to notice that the `resource` it requested at registration time no longer matches the server it is now talking to. The failure is not "expired token" (loud, 401, recoverable). It is "valid token, wrong audience" (quiet, sometimes 200 with degraded tool output, unrecoverable without re-authorization). The resource server is supposed to enforce `aud`, and a correct RS does — but the boundary condition is *which* RS enforces it after a failover, a blue/green cutover, or a multi-tenant tool-server fleet behind one DNS name. ## What Was Observed An agent runtime registered a DCR client against `https://as.example.com` requesting `resource=https://tools-a.example.com/mcp`. The AS issued an access token with `aud: ["https://tools-a.example.com/mcp"]` and a 3600s TTL. The agent cached the token in its episodic memory keyed by `(as_origin, client_id, scopes)` — **not** by resource. At T+40min, the tool-server fleet failed over. `tools-a.example.com` was re-pointed (same DNS name, new backend pool) to an instance whose protected-resource metadata (RFC 9728) advertised `resource: https://tools-b.example.com/mcp` and whose RS middleware validated `aud` against *its own* canonical resource identifier, not the requested host. Because the token's `aud` was `tools-a`, the failover instance rejected it with `401 invalid_token` — *but only on the first tool call that touched a stateful endpoint*. Read-only tools on the same server returned `200` because the RS's `aud` check was applied at the transport middleware for stateful routes only, a common asymmetry. The agent's retry logic saw a mix of 200s and 401s from the same endpoint family, classified the 401 as transient (the same class it uses for 429/503), and replayed the *same cached token* three times with exponential backoff. Each replay re-hit the failover instance, each returned 401. The agent then attempted DCR re-registration — but DCR is idempotent-by-`client_id` only if the client presents its `registration_access_token`; the agent had discarded that token after initial registration to save context. It re-registered as a *new* client, which the AS permitted (DCR is open by design), and received a fresh token with `aud: tools-a` again — because the agent's resource parameter was still hardcoded from its cold-start config. The loop repeated until the task's token budget was exhausted. The observable signature: a task that had been 60% complete stalled with a `401` storm interleaved with successful reads, and the agent's own logs showed it believed it was "retrying a transient auth error" rather than "holding a token bound to a resource that no longer exists." ## Condition of Validity The invariant that *should* hold, and that DCR+resource-indicators are designed to guarantee, is: > An access token presented to an MCP resource server is applicable iff `token.aud` (or `token.resource`) contains the RS's canonical resource identifier *as currently advertised in its protected-resource metadata*, and that identifier was the one the client requested at authorization time. This invariant is only valid when three conditions hold simultaneously, and the failure above is precisely the case where all three are violated at once: 1. **The client caches tokens keyed by resource, not by AS origin.** If the cache key omits `resource`, a token minted for `tools-a` will be reused against `tools-b`. 2. **The RS enforces `aud` uniformly across all routes.** Asymmetric enforcement (stateful-only) produces the 200/401 interleave that defeats naive retry classifiers. 3. **The client retains its `registration_access_token`** so that re-registration is an update, not a new identity — otherwise the AS cannot distinguish "same agent, new resource" from "new agent," and DCR's openness lets the loop continue indefinitely. The boundary is *not* "tokens expire." It is "the resource binding of a live token can be invalidated by a topology change the client never observed." DCR is the amplifier: a static client with a pinned `aud` would have failed closed at the first 401; a DCR client can silently mint a replacement identity and re-enter the same broken state. ## Decision Boundary The decision the agent runtime must make at every tool-call boundary is: **on a 401 from an MCP resource server, is this a token-lifecycle event (refresh/re-auth) or a resource-binding event (re-resolve metadata, re-request with corrected `resource`)?** These require different recovery paths and conflating them is what produced the loop. The boundary rule: - If the 401 body's `error` is `invalid_token` **and** the RS's currently-fetched protected-resource metadata advertises a `resource` that differs from the token's `aud`, treat it as a **resource-binding event**: discard the token, re-fetch RFC 9728 metadata from the *actual* endpoint origin, and re-authorize with `resource` set to the advertised value. Do **not** retry the old token. - If the 401 is `invalid_token` and metadata `resource` matches `aud`, it is a genuine lifecycle event (revocation, clock skew): refresh via the AS, bounded to one attempt. - If the 401 is `insufficient_scope`, it is an authorization event: re-request with expanded scopes, never silently downgrade. - **Never** classify a 401 as transient. A 401 is terminal for the current token; only 429/503/network errors are retryable with the same credential. - **Never** re-run DCR as a recovery step unless the `registration_access_token` is available for an update; a fresh DCR is a new identity and must reset the task's auth state, not paper over it. The guardrail is a **pre-flight binding check**: before each tool call whose result will be committed to task state, the runtime compares `token.aud` against the RS's live metadata `resource`, and fails closed if they diverge. This costs one metadata fetch per resource per task (cacheable with a short TTL and an ETag), and it converts the silent 200/401 interleave into a single, actionable binding error at the boundary where the agent still has context to recover. ## Operational Effect With the binding check and the corrected 401 classifier, the failover scenario resolves in one step: the first tool call after failover fetches metadata, sees `resource: tools-b`, detects `aud: tools-a`, raises a binding error, and the runtime re-authorizes with `resource=tools-b` — a single round-trip instead of a retry storm. Task state is preserved because the binding error is raised *before* the tool result is committed, so the agent's checkpoint remains consistent (no half-applied tool output from the 200/401 interleave). Without it, the operational effect is worse than a hard failure: the agent's episodic memory records partial tool outputs from the 200 responses as if they were authoritative, while the 401s are logged as transient. On resume, the agent replays against a memory that contains results from *both* the old and new resource instances, with no marker distinguishing them — a silent state-corruption path that is invisible until a downstream verification step disagrees with itself. The token budget exhaustion is the *symptom*; the durable damage is the mixed-provenance memory. The invariant to enforce, in one line: **a token's resource binding is part of its identity, and any change to the serving resource invalidates the token regardless of `exp`.** DCR makes the client responsible for re-establishing that binding; the runtime must therefore treat resource-binding divergence as a first-class, fail-closed condition, not a retryable error. ```python import time from dataclasses import dataclass from typing import Optional class ResourceBindingError(RuntimeError): """Raised when a live token's audience no longer matches the resource server's advertised resource. This is NOT a token-expiry or transient-network condition. It means the token is cryptographically valid but bound to a resource identifier that the server no longer claims. Retrying the same token will loop. """ @dataclass(frozen=True) class Token: access_token: str aud: tuple[str, ...] # from token introspection / JWT claim client_id: str expires_at: float @dataclass(frozen=True) class ResourceMetadata: resource: str # RFC 9728 "resource" identifier authorization_servers: tuple[str, ...] def classify_401( status: int, error_code: Optional[str], token: Token, live_metadata: ResourceMetadata, ) -> str: """Return one of: 'resource_binding', 'lifecycle', 'scope', 'fatal'. The decision boundary: a 401 is never 'transient'. The only question is whether the credential is mis-bound (re-resolve + re-authorize) or genuinely dead (refresh) or under-scoped (re-request). """ if status != 401: raise ValueError(f"classify_401 called with non-401 status {status}") if error_code == "insufficient_scope": return "scope" if error_code == "invalid_token": if live_metadata.resource not in token.aud: # Token is valid but bound to a different resource than the # server currently serves. This is the failover/cutover case. return "resource_binding" return "lifecycle" return "fatal" def preflight_binding_check(token: Token, live_metadata: ResourceMetadata) -> None: """Fail closed BEFORE committing any tool output to task state. Must be called at every tool-call boundary where the result will be persisted. Cheap: one cached metadata fetch per resource per task. """ if time.time() >= token.expires_at: # Expiry is a lifecycle event, handled by refresh, not here. return if live_metadata.resource not in token.aud: raise ResourceBindingError( f"token aud={token.aud!r} does not contain live resource " f"{live_metadata.resource!r}; client_id={token.client_id}. " f"Re-fetch RFC 9728 metadata and re-authorize with " f"resource={live_metadata.resource!r}. Do not retry this token." ) ```