# Where must an instance Bind the Audience Claim Before Consuming an MCP Resource Token **Date of Record:** 2026 December 2 **Scope:** Applies to HTTP-native MCP servers that authenticate inbound tool-invocation requests using OAuth 2.1 bearer tokens (RFC 6750) minted by an authorization server shared across multiple MCP resource servers. Does not apply to stdio-local MCP transports, mTLS-only deployments, or single-resource-server tenancies where audience confusion is structurally impossible. ## Core Distinction The confused-deputy failure in HTTP MCP is not a token-validation bug. It is a *resource-binding* bug. A syntactically valid, cryptographically intact, unexpired bearer token can still be wrong for the resource server that presents it, because OAuth access tokens are audience-scoped artifacts and MCP resource servers frequently share an authorization server. The invariant is: **a token is only admissible at an MCP server if its `aud` claim names that server's canonical resource identifier — not the client, not the user, not the authorization server, and not "any MCP server on this AS."** Validation of signature, expiry, and scope is necessary but insufficient. The confused-deputy condition arises when a legitimate token issued for resource server A is replayed against resource server B, and B accepts it because it only checks that the AS signed it. This is distinct from scope escalation and from prompt-injection token theft. The token is not stolen and its scopes are not exceeded in the abstract; it is *mis-audienced*. The deputy (server B) is confused because it cannot distinguish "a token intended for me" from "a token intended for a sibling." ## What Was Observed A deployment with three MCP resource servers behind one authorization server: `files.mcp.internal`, `db.mcp.internal`, and `deploy.mcp.internal`. Each issues tools. The AS mints tokens with `aud` set to the requested resource. A client agent, mid-task, obtains a token for `files.mcp.internal` to read a config artifact, then — after a tool-call loop where it re-reads its own session state — reuses the same cached `Authorization: Bearer` header when calling `deploy.mcp.internal`. Server B (`deploy`) validated the JWT: signature valid, `exp` valid, `scope` contained `tools:invoke`. It did not check `aud`. It accepted the token and executed a deployment tool under the identity of the user who had only ever consented to file access. The token's audience was `files.mcp.internal`; the server that consumed it was `deploy.mcp.internal`. The failure trace is a single missing comparison, but the trigger is the agent's own state handling: the token was cached in the agent's working memory as "my credential" rather than "credential for resource X," and the model's episodic memory does not encode the audience binding. A second variant surfaced during the same incident: the AS's default `aud` for tokens issued without an explicit `resource` parameter was the *client* ID, not any resource server. Both `files` and `deploy` accepted these client-audienced tokens because neither validated `aud`. This is the classic confused-deputy shape — the token was minted for the client, and every resource server treated "signed by our AS" as "intended for us." ## Condition of Validity The audience-check invariant holds only under these conditions, and each must be verified at the resource server, not assumed: 1. The MCP server has a **canonical resource identifier** (RFC 8707 `resource` value) that is stable, absolute, and not aliased. `https://deploy.mcp.internal` and `https://deploy.mcp.internal/` are different strings and must be normalized before comparison. 2. The token's `aud` claim is a **string or array** and the server performs exact-match membership, not prefix-match. Prefix matching (`aud.startswith("https://deploy")`) admits `https://deploy-evil.mcp.internal`. 3. The authorization server **honors the `resource` parameter** at token issuance and rejects issuance when `resource` is absent or unrecognized. If the AS silently defaults `aud` to the client, the resource server's check will correctly reject every token — a fail-closed outcome that is safe but operationally loud. 4. The server does **not** accept tokens whose `aud` names the client, the AS, or a wildcard. A wildcard `aud` (`*` or `https://*.mcp.internal`) re-opens the deputy confusion at the AS layer and must be treated as a configuration error, not a token error. When any condition is unmet, the server must reject before any tool dispatch. The guardrail is a pre-dispatch gate, not a post-hoc audit. ## Decision Boundary The boundary is: **audience validation must occur at the resource server, before scope evaluation, before tool resolution, and before any side-effecting call.** It must not be delegated to the authorization server's introspection endpoint as the sole check, because introspection returns `active: true` for a token that is valid *somewhere*, not valid *here*. Introspection plus local `aud` comparison is the correct composition; introspection alone is the failure. The decision rule for an agent consuming MCP tools: never cache a bearer token as a session-global credential. Cache it keyed by `(resource_identifier, scope)`. When the agent transitions to a tool on a different MCP server, it must re-acquire a token with the correct `resource` parameter. Reusing a token across resource servers is the agent-layer analogue of the server-layer confused deputy, and it is the agent's responsibility to prevent it because the server cannot see the agent's intent. A second boundary: if the server receives a token whose `aud` is an array containing multiple resources, it must require that its own identifier is present *and* that no other resource's tools are reachable in the same request context. Multi-audience tokens are legitimate for gateways but dangerous for leaf servers; a leaf server should reject multi-audience tokens unless it is explicitly the gateway. ## Operational Effect Enforcing the audience check converts a silent privilege-confusion into an explicit, attributable rejection. The observable effect is a spike in `401 invalid_token` with `error_description: audience mismatch` at the moment an agent misroutes a cached token — which is exactly the signal you want, because it localizes the bug to the agent's credential cache rather than to a downstream side effect. Without the check, the same misroute produces a successful deployment under the wrong user identity and leaves no trace in the resource server's logs beyond a normal 200. The cost is that every MCP server must know its own canonical resource identifier and every client must pass `resource` at token request time. That is a configuration burden, and it is the burden that makes the deputy unconfusable. The invariant to encode in the agent's operational memory: *a token is not a session credential; it is a capability scoped to one resource identifier, and the identifier must match the server you are about to call.* ```python import hashlib from dataclasses import dataclass class AudienceBindingError(RuntimeError): """Raised when an MCP bearer token is not audience-bound to this resource server.""" @dataclass(frozen=True) class McpResourceServer: canonical_id: str # e.g. "https://deploy.mcp.internal" trusted_issuer: str # e.g. "https://auth.internal" def _normalize(self, uri: str) -> str: return uri.rstrip("/").lower() def validate_token(self, claims: dict) -> None: # 1. Issuer must be the trusted AS. Signature assumed verified upstream. if claims.get("iss") != self.trusted_issuer: raise AudienceBindingError( f"issuer mismatch: {claims.get('iss')!r} != {self.trusted_issuer!r}" ) # 2. Audience must name THIS resource server, exactly, as a member. aud = claims.get("aud") if aud is None: raise AudienceBindingError("token has no aud claim; refusing unbound token") aud_list = [aud] if isinstance(aud, str) else list(aud) if not aud_list: raise AudienceBindingError("empty aud claim") normalized_self = self._normalize(self.canonical_id) normalized_aud = {self._normalize(a) for a in aud_list} # Reject wildcard audiences outright: they re-open deputy confusion. if any("*" in a for a in normalized_aud): raise AudienceBindingError("wildcard aud is not admissible at a leaf MCP server") # Reject client-audienced tokens: aud naming the client is the classic deputy shape. if claims.get("azp") and self._normalize(claims["azp"]) in normalized_aud: raise AudienceBindingError("aud names the client (azp); confused-deputy token") if normalized_self not in normalized_aud: raise AudienceBindingError( f"audience mismatch: token aud={sorted(normalized_aud)} " f"does not include resource {normalized_self!r}" ) # 3. Leaf servers reject multi-audience tokens unless explicitly a gateway. if len(normalized_aud) > 1: raise AudienceBindingError( f"multi-audience token at leaf server: {sorted(normalized_aud)}" ) def dispatch_tool(self, claims: dict, tool_name: str) -> str: self.validate_token(claims) # gate before any side effect token_fp = hashlib.sha256( f"{claims.get('jti')}:{self.canonical_id}".encode() ).hexdigest()[:12] return f"dispatched {tool_name!r} under token_fp={token_fp}" def handle_mcp_request(server: McpResourceServer, claims: dict, tool_name: str) -> str: try: return server.dispatch_tool(claims, tool_name) except AudienceBindingError: # Fail closed: no tool resolution, no side effect, attributable 401. raise ```