# Why does an instance lose tool-scoped authority when an MCP authorization server delegates through a resource indicator it never validated **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers that act as OAuth 2.1 resource servers, obtain per-tool scoped tokens via a delegating authorization server, and bind those tokens to a `resource` indicator (RFC 8707). Does not apply to single-token-per-session MCP deployments with no per-tool scope or to token exchange flows where the AS and RS are the same principal. ## Core Distinction There are two structurally different things an MCP server can mean when it says "this token is scoped to `tools:write_file`": 1. **Scope-as-claim**: the token carries a `scope` string and the server checks it against the tool's required scope at call time. The `resource` parameter is advisory metadata. 2. **Scope-as-binding**: the token is cryptographically bound to a specific `(resource, scope)` pair at issuance, and the resource server must verify that the `aud`/`resource` claim matches the exact tool endpoint it is about to invoke **before** honoring the scope. The failure mode lives in the gap between these two readings. A delegating authorization server issues a token with `resource=https://mcp.example/v1/tools/*` (a wildcard or a parent URI) and `scope=tools:read_billing,tools:write_file`. The MCP server, treating scope as a claim, checks `write_file ∈ scope` and proceeds. The token was never bound to `write_file` as a resource; it was bound to a *namespace*. Any tool under that namespace inherits the authority, including tools the user never consented to for that delegation. The instance does not lose authority — it silently **over-acquires** it, which is the same continuity break viewed from the other side: the per-tool invariant is broken at issuance, and every downstream audit that assumes per-tool binding is now wrong. ## What Was Observed A three-hop delegation chain: user → client agent (Claude-class instance) → MCP authorization server (AS) → MCP resource server (RS) hosting 14 tools. The AS was configured with RFC 8707 resource indicators and issued tokens per tool on first call, caching them in a per-session token map keyed by `(tool_name, scope)`. Trace of the failing sequence: - Call `read_invoice` → no cached token → AS issues token `T1` with `resource=https://mcp.example/v1/tools/read_invoice`, `scope=tools:read`. Cached under `("read_invoice","tools:read")`. - Call `write_note` → AS issues `T2` with `resource=https://mcp.example/v1/tools/write_note`, `scope=tools:write`. Cached. - Call `read_invoice` again with a *different* delegation context (user re-authenticated mid-session, new `sub`) → cache hit on `("read_invoice","tools:read")` → `T1` reused. `T1`'s `sub` is the *old* user. The RS validates signature and scope, sees `sub=old_user`, but the tool's own authorization check reads the *current* session's `sub` from the MCP transport header and finds a mismatch it was never coded to look for. Depending on tool implementation, it either fails closed (good, but the agent interprets it as a transient tool error and retries) or — in the observed case — the tool used the token's `sub` for the write and the transport's `sub` for the read, producing a **split-identity execution**: read as user A, write as user B, within one logical tool call. Second observation, same session: the AS's delegation endpoint accepted `resource=https://mcp.example/v1/tools/` (trailing slash, no tool segment) and issued a token with `scope=tools:*`. The RS's per-tool binding check was a prefix match (`token.resource.startswith(tool_endpoint)`), so `.../tools/` matched every tool endpoint. The per-tool scoping invariant was satisfied by the letter of the check and violated in effect. The agent instance never surfaced either condition. It saw two successful tool results and continued the task. The continuity invariant — "the authority under which a tool executes is the authority the user granted for *that* tool in *this* delegation context" — was broken with no observable signal at the agent layer. ## Condition of Validity The failure requires all of the following to hold simultaneously: - The AS accepts a resource indicator that is not exactly equal to the RS's per-tool endpoint URI (wildcard, parent path, trailing slash, or case/percent-encoding variant). - The RS's binding check is a prefix/substring match rather than exact normalized URI equality. - The per-session token cache is keyed on `(tool, scope)` without the delegation context (`sub`, `act`, `client_id`, `iss`, `jti` of the upstream assertion) in the key. - The agent reuses the session across a delegation-context change (re-auth, step-up, on-behalf-of exchange) without invalidating the token cache. Remove any one condition and the invariant holds. The most common real-world miss is the third: engineers key the cache on what the tool needs, not on what the authority derives from. ## Decision Boundary The boundary is not "validate the token." It is: **at what point does the RS commit to the `(resource, scope)` pair as the authoritative statement of authority, and what does it do when the token's resource is a strict ancestor of the endpoint being invoked?** Two defensible policies: - **Reject-ancestor**: if `normalize(token.resource) != normalize(tool_endpoint)`, reject with `invalid_target` before any tool logic runs. This is the only policy that makes per-tool scoping an invariant rather than a convention. Cost: the AS must issue exactly-per-tool tokens, which forces a token-per-tool-per-context explosion and requires the AS to know the RS's tool URI space. - **Ancestor-with-attenuation**: accept an ancestor resource only if the token additionally carries a signed `tool_allowlist` claim enumerating the exact tools it may invoke, and the RS checks membership. This preserves token reuse at the cost of a second authority channel that must itself be bound to the delegation context. The decision boundary the agent must respect: **never treat a successful tool call as evidence that the token was correctly scoped.** Success is compatible with over-acquisition. The agent's own continuity check must be independent of tool return values. ## Operational Effect When the invariant breaks, the observable effects at the agent layer are: 1. **Silent authority inflation**: tools execute under scopes the user did not consent to for that delegation. No error, no log line at the agent layer. 2. **Split-identity execution** across read/write within a single logical call when token `sub` and transport `sub` diverge after re-auth. 3. **Cache poisoning across delegation contexts**: a token minted for context C1 is served to context C2; the RS's `sub` check (if any) fires as a generic 401 that the agent classifies as transient and retries, burning the token budget and eventually surfacing as a spurious "tool unavailable" to the user. 4. **Audit divergence**: the RS audit log records `sub` from the token; the agent's trace records `sub` from the transport. Replay reconciliation fails at exactly the calls where authority was ambiguous. The guardrail is a single hard rule at the RS boundary plus a cache-key rule at the agent boundary. Both are cheap; neither is default in current MCP server scaffolds. ```python import re from urllib.parse import urlsplit, urlunsplit class ResourceBindingViolation(RuntimeError): """Raised when a token's resource indicator does not exactly bind to the tool endpoint.""" class DelegationContextMismatch(RuntimeError): """Raised when a cached token's delegation context differs from the current one.""" def _normalize_uri(uri: str) -> str: parts = urlsplit(uri) path = re.sub(r"/+", "/", parts.path).rstrip("/") or "/" return urlunsplit((parts.scheme.lower(), parts.netloc.lower(), path, "", "")) def validate_tool_binding(token: dict, tool_endpoint: str, current_ctx: dict) -> None: # 1. Resource indicator must be an exact normalized match to the tool endpoint. token_res = _normalize_uri(token.get("resource", "")) endpoint = _normalize_uri(tool_endpoint) if token_res != endpoint: raise ResourceBindingViolation( f"token resource {token_res!r} is not exactly bound to endpoint {endpoint!r}; " f"ancestor/wildcard resources are rejected" ) # 2. Scope must name the specific tool, not a namespace wildcard. scopes = set(token.get("scope", "").split()) tool_scope = f"tools:{endpoint.rsplit('/', 1)[-1]}" if tool_scope not in scopes or any(s.endswith(":*") for s in scopes): raise ResourceBindingViolation( f"scope set {sorted(scopes)!r} does not contain exact tool scope {tool_scope!r} " f"or contains a wildcard" ) # 3. Token must have been issued for the current delegation context. for claim in ("sub", "client_id", "act"): if token.get(claim) != current_ctx.get(claim): raise DelegationContextMismatch( f"claim {claim!r}: token={token.get(claim)!r} ctx={current_ctx.get(claim)!r}" ) def get_or_issue_token(cache: dict, tool_endpoint: str, ctx: dict, as_client) -> dict: key = ( _normalize_uri(tool_endpoint), ctx.get("sub"), ctx.get("client_id"), ctx.get("act"), ) token = cache.get(key) if token is None: token = as_client.issue(resource=_normalize_uri(tool_endpoint), context=ctx) cache[key] = token validate_tool_binding(token, tool_endpoint, ctx) return token ```