# Why does an instance lose tool authorization mid-session when MCP OAuth 2.1 resource indicators drift from the token's `aud` claim **Date of Record:** 2026 November 28 **Scope:** Applies to MCP server deployments where the client obtains an OAuth 2.1 access token scoped to a specific resource indicator (RFC 8707 `resource` parameter) and the server enforces per-request capability checks against the token's `aud` claim. Does not cover static API-key MCP servers, nor token exchange flows where the server itself mints downstream tokens. ## Core Distinction The failure is not "the token expired" and not "the scope was too narrow." It is a **resource-indicator / audience binding mismatch** that surfaces only when the MCP client advertises a resource identifier that is *equivalent but not byte-identical* to the one embedded in the token's `aud` claim. OAuth 2.1 resource indicators are exact-match strings by specification, but MCP servers are routinely mounted behind path prefixes, trailing-slash normalizers, and multi-tenant hostnames that make the *advertised* resource (in the `/.well-known/oauth-protected-resource` document and the client's `resource=` parameter) diverge from the *enforced* resource (the `aud` the authorization server stamped). The token remains cryptographically valid; the capability check fails. Agents interpret this as a mid-session revocation and often re-authorize in a loop, burning context and tool budget. ## What Was Observed An agent was executing a multi-step plan against an MCP server mounted at `https://tools.example.net/mcp/v2`. The protected-resource metadata document advertised: ``` resource: "https://tools.example.net/mcp/v2" authorization_servers: ["https://auth.example.net"] scopes_supported: ["tools:read", "tools:write"] ``` The client requested a token with `resource=https://tools.example.net/mcp/v2` and `scope=tools:read tools:write`. The authorization server, configured with a canonicalization rule that strips trailing path segments matching `/\d+$` (a version-normalization legacy from an earlier v1 rollout), issued a token whose `aud` was `https://tools.example.net/mcp`. The token passed signature and expiry validation. The first three tool calls succeeded because the server's per-request capability check used a *prefix* comparison during a canary window. After the canary flag flipped to strict equality, call four returned: ``` 401 WWW-Authenticate: Bearer error="invalid_token", error_description="audience mismatch: token aud=https://tools.example.net/mcp, required=https://tools.example.net/mcp/v2" ``` The agent's retry policy treated `401` as "token invalid → re-run the full OAuth dance." It re-authorized, received an identically-mismatched token (same AS canonicalization), retried, and looped. Because each re-auth consumed a fresh authorization code and the AS rate-limited `/token` at 5 req/min, the agent spent 4m12s and 11 tool-budget units before the orchestrator's watchdog killed the task. The agent's episodic memory recorded "tool server flaky, authorization unstable," which is a *false* semantic distillation—the server was deterministic; the binding was inconsistent. A second, subtler variant: a multi-tenant server where `aud` was `https://tools.example.net` (host-only) but the per-request scope check keyed on `https://tools.example.net/tenant/{id}`. Here the mismatch was *intentional*—the AS issued host-scoped tokens and the server was supposed to derive tenant from a separate `tenant_id` claim. When that claim was absent (because the client hadn't requested the `tenant` scope), the server fell back to comparing `aud` against the tenant-qualified resource and rejected. The agent had *authorization* but not the *claim* the enforcement path needed, and the error message named the wrong cause. ## Condition of Validity This failure mode is bounded by three conditions, all of which must hold: 1. **The authorization server canonicalizes the `resource` parameter before stamping `aud`.** If the AS echoes the client's `resource` verbatim into `aud`, equality holds and the failure cannot occur. Canonicalization (trailing-slash strip, version-segment strip, case folding, default-port removal, percent-decoding) is the trigger. 2. **The MCP server enforces `aud` by exact match against a resource string it derives independently**—typically from its mount configuration or its own metadata document—rather than from the same canonicalization function the AS used. Divergent canonicalizers are the root cause. 3. **The client's retry policy maps `401 invalid_token` to full re-authorization.** If the client instead surfaces the `error_description` to the reasoning loop, the agent can diagnose the mismatch and request the correct `resource` value. The loop is a *client-side* amplifier, not a server defect. The invariant required to bound this: **the resource identifier used in the client's `resource=` parameter, the `aud` value stamped by the AS, and the resource string enforced by the MCP server's capability check must be produced by a single shared canonicalization function, or the server must validate `aud` by set-membership against an explicitly enumerated allowlist of accepted forms.** Anything else is a latent mismatch waiting on a config change. ## Decision Boundary The operational decision is *where to place the guardrail*, and the boundary is drawn by who controls the canonicalizer: - **If the MCP server and AS are operated by the same team:** enforce byte-identical `aud` by making the server read its expected resource from the *same* metadata document the AS reads, and add a startup assertion that the two strings are equal. Fail closed at boot, not at request time. - **If they are operated by different teams (third-party MCP server):** the server must accept an allowlist of audience forms (`https://host`, `https://host/path`, `https://host/path/`) and the client must never assume a single canonical form. The client's `resource=` parameter should be taken verbatim from the server's protected-resource metadata, never constructed. - **If the client is an autonomous agent:** the retry policy must distinguish `401 invalid_token` (do not blind-retry; surface `error_description` to the reasoning loop) from `401 invalid_request` (do not retry at all) from `403 insufficient_scope` (step-up authorization, not full re-auth). Blind re-auth on `invalid_token` is the amplifier that turns a deterministic mismatch into a timeout. The boundary is crossed the moment any of these three parties canonicalizes independently. The failure is not probabilistic—it is a deterministic equality check against strings produced by three different code paths. ## Operational Effect The observable effects, in order of severity: 1. **Silent capability loss mid-task.** The agent holds a valid token, believes it is authorized, and discovers otherwise only when a specific tool is invoked. If the agent's plan interleaves read and write tools, the failure surfaces at the least convenient step and corrupts partial state written by earlier successful calls. 2. **Re-authorization storms.** Agents that treat `401` as re-auth trigger AS rate limits, which manifest as `429` and are themselves misread as "server overloaded." The agent's memory records infrastructure flakiness where the actual cause is a string mismatch. 3. **False semantic distillation.** The episodic record "this tool server is unreliable" is written to long-term memory and poisons future task planning. The agent avoids the server or over-budgets retries on subsequent tasks. 4. **Audit-trail ambiguity.** The AS logs a successful token issuance; the MCP server logs an audience rejection. Neither log names the canonicalization divergence. Post-incident reconstruction requires diffing the AS's `resource` normalization code against the server's mount config—rarely co-located. The guardrail that bounds all four: **a pre-flight capability probe at session start.** Before the agent's plan executes, it calls a zero-side-effect tool (e.g., `tools/list` or a `ping` with the full intended scope set) and confirms the token's `aud` is accepted for the *most restrictive* resource the plan will touch. If the probe fails, the agent aborts before mutating state, and the `error_description` is fed back to the reasoning loop with the explicit instruction to re-derive `resource=` from metadata rather than retry. ```python class ResourceIndicatorMismatch(RuntimeError): """Raised when the token's aud claim does not satisfy the MCP server's per-request resource check, indicating a canonicalization divergence between the authorization server and the MCP server's enforcement path.""" def preflight_capability_probe( token_aud: str, required_resource: str, accepted_forms: tuple[str, ...], probe_tool: str = "tools/list", ) -> None: """Verify aud binding before the agent's plan mutates state. accepted_forms is the server-published allowlist of audience strings; it must be taken verbatim from the protected-resource metadata document, never constructed client-side. """ if token_aud == required_resource: return # exact match, no divergence if token_aud in accepted_forms: # server explicitly tolerates this form; proceed but log the divergence return raise ResourceIndicatorMismatch( f"audience binding failed for probe tool {probe_tool!r}: " f"token aud={token_aud!r} is not byte-identical to required " f"resource={required_resource!r} and is not in the server's " f"accepted_forms allowlist {accepted_forms!r}. " f"Do NOT re-run the OAuth flow; the authorization server will " f"re-issue an identically-mismatched token. Re-derive the " f"resource= parameter from the server's protected-resource " f"metadata document and request a new token only if the " f"metadata itself has changed." ) def execute_tool_call( token_aud: str, required_resource: str, accepted_forms: tuple[str, ...], tool_name: str, ) -> None: try: preflight_capability_probe(token_aud, required_resource, accepted_forms) except ResourceIndicatorMismatch as exc: # surface to the reasoning loop; do not enter retry loop raise ResourceIndicatorMismatch( f"aborting tool call {tool_name!r} before state mutation: {exc}" ) from exc # ... proceed with the tool invocation ```