# Under what conditions must an instance treat an MCP tool call as unauthorized when the OAuth 2.1 bearer token validates but its `aud` claim does not bind to the specific resource-server URI of the invoked tool **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers acting as OAuth 2.1 resource servers that gate individual tools on token scopes, where a single MCP server exposes multiple tools behind distinct logical resource URIs. Does not apply to naive single-audience deployments where the MCP server URI equals the token audience for all tools. ## Core Distinction The failure is not token *validity*; it is token *binding*. A JWT can pass signature verification, `exp`/`nbf` checks, issuer lookup, and even scope membership for the requested tool, and still be *unbound* to the resource it is being presented against. OAuth 2.1 (RFC 8707 resource indicators) requires the resource server to reject a token whose `aud` does not include the exact resource URI being accessed. In MCP, the "resource" is not the server process — it is the *tool invocation target*. When an agent presents a token minted for `mcp://serverA/tools/read_file` to `mcp://serverA/tools/exec_shell`, and both tools share a scope like `tools:invoke`, the token validates and the scope matches, but the binding is wrong. The instance must treat this as unauthorized even though every superficial check passes. ## What Was Observed An MCP server registered three tools under one process: `search_docs` (scope `docs:read`), `write_note` (scope `notes:write`), and `execute` (scope `exec:run`). The authorization server issued tokens with `aud: ["mcp://agent.example/server"]` — the *server* URI — and scopes matching the requested tool. During a multi-step agent run, the orchestrator obtained a token for `search_docs` and cached it in the shared MCP client session. A later reasoning step, after a retrieval miss, decided to call `execute` to inspect the filesystem. The client reused the cached token because the transport session was still live and the token had not expired. The server's middleware validated the JWT (signature, `exp`, `iss`), checked that the token carried *some* scope, and — because the server had a permissive fallback that mapped any valid token to the default policy — allowed the call. The tool executed with the `search_docs` token's identity and a scope (`docs:read`) that should never have reached `execute`. The trace showed: `validate_jwt=ok`, `aud_check=skipped` (audience was the server URI, not the tool URI, so the check was configured to compare against the server and always matched), `scope_check=present` (not `contains`), `tool_dispatch=execute`. The agent had crossed a privilege boundary using a token that was cryptographically intact and semantically wrong. No error surfaced to the agent; the model observed a successful tool result and continued reasoning on poisoned authority. ## Condition of Validity The invariant holds only when all of the following are true: 1. The MCP server exposes tools whose authorization requirements differ, and the authorization server issues tokens scoped per-tool or per-resource. 2. Tokens carry an `aud` claim that is intended to bind to a specific resource indicator (RFC 8707), not merely to the server origin. 3. The MCP client session permits token reuse across tool calls within a single transport connection or across a resumed session. Under these conditions, the server MUST compare the token's `aud` against the *canonical resource URI of the specific tool being invoked* — not the server URI, not the transport endpoint. If the tool's resource URI is not in `aud`, the call is unauthorized regardless of scope. If the deployment instead mints a single server-wide audience and relies solely on scopes, this invariant does not apply and a different control (scope containment, not audience binding) governs. ## Decision Boundary The boundary is between *scope presence* and *scope binding*. A token that carries scope `exec:run` but whose `aud` is `mcp://agent.example/server` is not authorized for `mcp://agent.example/server/tools/execute` unless the server has explicitly declared that the server URI is the resource indicator for that tool. The decision procedure is: - Resolve the tool's declared resource URI from the MCP server's tool manifest (or from the `resource` field in the tool descriptor). - Require `aud` to contain that exact URI (string equality after normalization; no prefix matching, no wildcard). - Require `scope` to contain the tool's required scope. - Reject if either fails — and reject with `insufficient_scope` or `invalid_token` per RFC 6750, not a generic 403, so the client knows to re-authorize rather than retry. The non-obvious part: a token with `aud` = server URI is *not* automatically valid for every tool under that server. The server URI is a namespace, not a grant. Treating it as a grant is the boundary violation. ## Operational Effect When the invariant is enforced, an agent that attempts to reuse a token across tools receives an authorization failure at the MCP layer, and the orchestrator must perform a fresh token acquisition for the new tool's resource URI. This forces a re-authorization event per privilege boundary crossing, which is the intended friction. When the invariant is violated, the agent silently escalates: it uses a low-privilege token to invoke a high-privilege tool, the model observes success, and subsequent reasoning is conditioned on capabilities it does not legitimately hold. The failure is invisible to the agent's own verification loop because the tool returned a normal result. Recovery requires either token revocation and session teardown, or an out-of-band audit that replays the tool-call log against the token `aud`/`scope` pairs — the agent itself cannot detect the breach from its own context. ```python import time from dataclasses import dataclass from typing import Optional class TokenBindingError(RuntimeError): """Raised when a bearer token validates cryptographically but is not bound to the resource URI of the tool being invoked.""" @dataclass class Token: subject: str audience: list[str] scopes: list[str] expires_at: float issuer: str @dataclass class ToolDescriptor: name: str resource_uri: str # canonical URI, e.g. mcp://server/tools/execute required_scope: str def _normalize_uri(uri: str) -> str: # No trailing slash, lowercase scheme+host, preserve path case. scheme, rest = uri.split("://", 1) host, _, path = rest.partition("/") return f"{scheme.lower()}://{host.lower()}/{path}".rstrip("/") def authorize_tool_call( token: Token, tool: ToolDescriptor, now: Optional[float] = None, ) -> None: now = now if now is not None else time.time() # Cryptographic / temporal validity is assumed already checked upstream; # we re-check expiry defensively. if token.expires_at <= now: raise TokenBindingError( f"token expired at {token.expires_at}, now={now}" ) # Binding check: the tool's resource URI must be an exact audience member. target = _normalize_uri(tool.resource_uri) audiences = {_normalize_uri(a) for a in token.audience} if target not in audiences: # This is the boundary failure: token is valid, scope may match, # but audience does not bind to this tool's resource. raise TokenBindingError( f"token aud={sorted(audiences)} does not bind to tool " f"resource={target!r} for tool={tool.name!r}" ) # Scope containment, not mere presence. if tool.required_scope not in token.scopes: raise TokenBindingError( f"token scopes={token.scopes} missing required " f"{tool.required_scope!r} for tool={tool.name!r}" ) # --- Reproduction of the observed failure --- if __name__ == "__main__": cached = Token( subject="agent-7", audience=["mcp://agent.example/server"], # server URI, not tool URI scopes=["docs:read"], expires_at=time.time() + 300, issuer="https://auth.example", ) execute_tool = ToolDescriptor( name="execute", resource_uri="mcp://agent.example/server/tools/execute", required_scope="exec:run", ) try: authorize_tool_call(cached, execute_tool) except TokenBindingError as e: print(f"BLOCKED: {e}") # expected: aud does not bind to tool resource else: raise TokenBindingError( "invariant violated: server-audience token authorized tool call" ) ```