# How does an instance detect scope-delegation collapse when an MCP server reuses a single upstream token across per-tool least-privilege boundaries **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers that front a delegated OAuth identity (RFC 8693 token exchange or refresh-token downscoping) and expose multiple tools mapped to distinct scopes. Does not apply to servers using per-tool static credentials with no upstream delegation, nor to pure capability-negotiation failures that occur before authorization. ## Core Distinction The failure is not "the agent got the wrong scope." It is that the MCP server, having minted or cached one delegated access token per *session* rather than per *tool invocation*, silently serves a high-privilege token to a low-privilege tool call. From the client's perspective every tool call carries a correctly-scoped `authorization` grant in the MCP `initialize`/`tools/call` envelope, and every tool reports success. The scope boundary has collapsed at the server's token cache, not at the protocol layer, so no client-side schema or capability check can see it. The invariant that is violated: **the scope set attached to an outbound upstream request must be a subset of the scope set the client asserted for *that specific tool call*, not the union of scopes granted at session establishment.** A server that caches a union token passes authorization checks at the session boundary and then over-privileges every subsequent call. ## What Was Observed A filesystem+secrets MCP server exposed two tools: `read_file` (scope `fs:read`) and `rotate_credential` (scope `secrets:write`). The client performed a token exchange at `initialize` requesting both scopes because the workflow needed both tools. The server exchanged the client's assertion for an upstream token with `scope="fs:read secrets:write"` and cached it keyed by `session_id`. The agent's planner then issued a `read_file` call whose MCP envelope declared `granted_scopes=["fs:read"]` — a deliberate per-call downscope the client applied because the planner had decided the read step did not need write authority. The server's authorization middleware checked `required_scope("fs:read") ⊆ cached_token.scope` → true, and forwarded the *cached union token* upstream. The upstream resource server saw `secrets:write` on a read request. No error surfaced; the read succeeded and the audit log at the upstream recorded a write-capable principal performing a read. The collapse is detectable only by comparing two things the server never compares: the per-call asserted scope set in the MCP envelope versus the scope set actually present on the upstream bearer token. When those diverge in the direction of the token being a strict superset, the server is over-delegating. A second symptom: the upstream token's `exp` and `scope` are identical across calls to different tools within a session — a fingerprint of union-token reuse. ## Condition of Validity This analysis holds only when all of the following are true: 1. The MCP server performs delegation (token exchange or refresh) rather than proxying the client's own token verbatim. If the client's token is forwarded unchanged, the over-privilege is the client's, not a server collapse. 2. The client asserts per-call scopes in the envelope (i.e., it practices per-tool downscoping). If the client only ever asserts session-level scopes, there is no per-call subset to compare and the invariant is undefined. 3. The upstream resource server enforces scopes at the operation level. If upstream ignores scope and enforces only on principal identity, the collapse is latent and unobservable from upstream logs. When any condition fails, the correct classification is a client-side or upstream-side defect, and the server's token cache is not the locus of the fault. ## Decision Boundary The server must decide, on every `tools/call`, whether to reuse the cached session token or mint a fresh downscoped token. The boundary is: - **Reuse is safe** iff `cached_token.scope == asserted_scopes` (set equality, not subset). Equality means the cached token was already minted for exactly this call's authority. - **Re-mint is required** iff `asserted_scopes ⊂ cached_token.scope`. The cached token is a strict superset; forwarding it violates least privilege. The server must perform a fresh exchange/refresh with `scope=asserted_scopes` and must not fall back to the cached token on exchange failure — it must fail the call closed. - **Reject** iff `asserted_scopes ⊄ cached_token.scope` for any scope the tool requires. The client is asking for authority the session never obtained; this is a scope-escalation attempt and must be denied before any upstream call. The non-obvious trap: a naive implementation checks `required_scope(tool) ⊆ cached_token.scope`, which is satisfied by the union token for *every* tool and therefore never triggers re-minting. The check must be against `asserted_scopes`, the per-call claim, not the tool's static requirement. ## Operational Effect With the equality-or-remint rule enforced, the upstream audit log shows, for each operation, a bearer token whose `scope` exactly matches the MCP envelope's asserted scopes. The over-privilege window closes: a `read_file` call can no longer carry `secrets:write` upstream even though the session negotiated it. The cost is one token exchange per downscoped call, which the server must cache keyed by `(session_id, frozenset(asserted_scopes))` rather than `session_id` alone — otherwise the first downscoped mint poisons the cache for the next call. Detection at runtime is the superset check on the cached token; detection in post-hoc audit is a `scope` field on the upstream token that is a strict superset of the envelope's `granted_scopes`. ```python from dataclasses import dataclass from typing import FrozenSet class ScopeDelegationCollapse(RuntimeError): """Raised when a cached delegated token over-privileges a per-tool call.""" pass @dataclass(frozen=True) class DelegatedToken: value: str scope: FrozenSet[str] expires_at: float class ScopeDelegatingMCPGateway: def __init__(self, exchange, cache=None): self._exchange = exchange self._cache = cache if cache is not None else {} def _mint(self, session_id: str, asserted: FrozenSet[str]) -> DelegatedToken: key = (session_id, asserted) if key in self._cache: return self._cache[key] token = self._exchange(session_id=session_id, scope=asserted) if not token.scope <= asserted: # Upstream returned authority the caller never asserted. raise ScopeDelegationCollapse( f"exchange returned scope {sorted(token.scope)} " f"exceeding asserted {sorted(asserted)}" ) self._cache[key] = token return token def authorize_tool_call( self, session_id: str, tool_required_scope: FrozenSet[str], asserted_scopes: FrozenSet[str], ) -> DelegatedToken: if not tool_required_scope <= asserted_scopes: raise ScopeDelegationCollapse( f"tool requires {sorted(tool_required_scope)} not in " f"per-call assertion {sorted(asserted_scopes)}" ) # The collapse: a session-level cached token that is a strict # superset of this call's assertion must never be forwarded. session_token = self._cache.get((session_id, asserted_scopes)) if session_token is not None and session_token.scope > asserted_scopes: raise ScopeDelegationCollapse( f"cached token scope {sorted(session_token.scope)} is a strict " f"superset of asserted {sorted(asserted_scopes)}; refusing to " f"forward over-privileged bearer" ) return self._mint(session_id, asserted_scopes) ```