# Which invariants prevent per-tool least-privilege scopes from silently widening across MCP sessions **Date of Record:** 2026 November 28 **Scope:** Applies to MCP (Model Context Protocol) hosts that enforce per-tool scope grants at runtime and emit audit trails for each `tools/call`. Does not cover static manifest review, transport-level TLS, or OAuth token issuance—only the runtime decision point where a granted scope is matched against a tool invocation. ## Core Distinction There are two structurally different ways an MCP server can appear to honor least-privilege scoping: 1. **Scope-as-token**: the grant is a bearer capability checked at the boundary of each call. The scope is a property of the *invocation*, re-evaluated every time. 2. **Scope-as-session-attribute**: the grant is attached to the `initialize` handshake and inherited by every subsequent `tools/call` on that session. The scope is a property of the *connection*. The failure mode this record isolates lives entirely in the second model and is invisible under the first. When a host multiplexes multiple logical agents over a single MCP session—or when a server caches a session's effective scope set to avoid re-deriving it per call—the effective privilege of a later call is the *union* of everything granted earlier on that session, not the intersection with what the calling agent actually needs. Least-privilege silently degrades to "most-privilege-so-far." The audit trail still records a scope on each call, so the log looks compliant while the runtime is not. ## What Was Observed A host proxy multiplexed three sub-agents (a planner, a retriever, and a summarizer) onto one upstream MCP session to amortize the `initialize` round-trip. The server advertised `tools/list` with per-tool `requiredScopes` metadata, and the host enforced a policy table mapping each sub-agent to an allowed scope set. Sequence of events: - The planner sub-agent issued `tools/call` for `fs.read` with scope `fs:read:/work/plan/**`. Server validated, executed, emitted audit record `{call_id: c1, scope: fs:read:/work/plan/**}`. - The retriever sub-agent issued `tools/call` for `fs.read` with scope `fs:read:/data/corpus/**`. Because the session's cached effective-scope set was stored as a set union keyed by session, the server merged the new grant into the session record rather than replacing it. - The summarizer sub-agent, whose policy table permitted only `fs:read:/work/summary/**`, issued a call for `fs.read` on `/data/corpus/secret.txt`. The host's per-agent check passed (the request *claimed* the summarizer's scope), but the server's session-level check evaluated against the accumulated set `{/work/plan/**, /data/corpus/**, /work/summary/**}` and authorized the read. The audit record for the third call read `{call_id: c3, scope: fs:read:/work/summary/**}`—truthful about what the caller claimed, silent about the fact that the authorization decision used a wider set. A log-only auditor reviewing the trail would conclude the summarizer never touched `/data/corpus`. It did. The trigger condition is narrow but reproducible: (a) session reuse across logically distinct agents, (b) server-side caching of effective scopes as a monotonic set, and (c) a tool whose scope is a path/resource *pattern* rather than a flat capability name. Remove any one and the widening does not occur. ## Condition of Validity The invariant that prevents this is **scope non-accumulation per invocation**: > For every `tools/call`, the authorization decision MUST be a pure function of (the caller's asserted scope, the tool's declared `requiredScopes`, the resource argument in the call) and MUST NOT depend on any scope granted on a prior call over the same session or transport. This is stronger than "check scopes on each call." A server can check scopes on each call and still fail this invariant if the check consults a session-mutable set. The validity condition is *purity with respect to call history*: the decision function must be stateless across calls, even when the connection is stateful. Three corollaries bound the condition: - **Session ≠ principal.** A session may carry transport state (framing, capability negotiation, subscriptions) but must not carry authorization state. If a host multiplexes principals, each `tools/call` must carry a principal identity that the server re-resolves to a scope set on every call. - **Scope patterns must be matched, not merged.** When scopes are resource patterns (`fs:read:/data/**`), the effective authorization is the *match result* of the call's resource argument against the caller's asserted pattern—never a union of patterns seen on the session. - **Audit must record the decision basis, not the claim.** The audit record must include the scope set the server actually evaluated against, not only the scope the client asserted. Otherwise the trail cannot distinguish "authorized correctly" from "authorized via accumulation." ## Decision Boundary The boundary between safe and unsafe enforcement is whether the server's authorization path touches any state that outlives a single `tools/call`. Concretely: | State location | Verdict | |---|---| | Scope resolved from the call's `_meta` / auth context per call | Safe | | Scope resolved from session record, written once at `initialize`, immutable thereafter | Safe *only if* one principal per session | | Scope resolved from session record mutated by later grants | Unsafe—this is the failure | | Scope resolved from a host-side cache keyed by session id | Unsafe—same failure, moved to the host | | Scope resolved from a cache keyed by `(session_id, principal_id, tool_name)` and invalidated on principal change | Safe if invalidation is provably complete | The last row is the subtle one. A keyed cache is safe only if the key includes the principal and the invalidation is complete. In practice, "provably complete invalidation" is the part that fails under load, under reconnect, or when a sub-agent reuses a principal id after a context reset. The robust choice is to forbid authorization state in caches entirely and pay the per-call resolution cost. A second boundary concerns reconnect semantics. When a client reconnects and the server resumes a session by id, any cached scope set must be treated as *void* rather than *restored*, because the principal set on the new connection is not guaranteed to equal the old one. Resume must re-derive authorization from the new connection's credentials. ## Operational Effect Under the invariant, the observed failure becomes impossible by construction: the summarizer's call on `/data/corpus/secret.txt` is evaluated against `{fs:read:/work/summary/**}` alone, fails the pattern match, and returns an authorization error before the tool executes. The audit record for the denied call now shows the evaluated scope set, so the denial is legible. The cost is a per-call scope resolution and pattern match—cheap relative to the tool execution it gates, and the only reliable way to keep least-privilege from degrading to accumulated-privilege across a multiplexed session. Hosts that multiplex must additionally propagate a principal identity on every call, since the server can no longer infer the principal from the connection. The guardrail to enforce in code: authorization must raise on any attempt to consult session-scoped mutable state, and the audit emitter must refuse to write a record that lacks the evaluated scope set. Both are cheap to assert and both catch the widening before it reaches a tool. ```python class ScopeAccumulationError(RuntimeError): """Raised when an authorization decision would depend on prior-call scope state.""" def authorize_call( asserted_scope: str, required_scopes: list[str], resource: str, session_scope_cache: dict | None, ) -> str: """ Pure authorization for a single tools/call. Invariant: the decision MUST be a function of (asserted_scope, required_scopes, resource) only. Any presence of session-scoped mutable authorization state is a violation. """ if session_scope_cache is not None and len(session_scope_cache) > 0: # The server is about to consult accumulated per-session scopes. # This is the exact condition that widens least-privilege. raise ScopeAccumulationError( "authorization path consulted session-scoped scope cache " f"({sorted(session_scope_cache.keys())}); decision would depend on call history" ) if asserted_scope not in required_scopes: raise ScopeAccumulationError( f"asserted scope {asserted_scope!r} not in tool required_scopes {required_scopes!r}" ) # Pattern match: asserted scope must cover the resource argument. prefix, _, pattern = asserted_scope.partition(":") if not resource.startswith(pattern.rstrip("*")): raise ScopeAccumulationError( f"resource {resource!r} outside asserted scope pattern {asserted_scope!r}" ) return asserted_scope def emit_audit(call_id: str, asserted_scope: str, evaluated_scopes: list[str]) -> dict: if not evaluated_scopes: raise ScopeAccumulationError( f"audit record {call_id} lacks evaluated scope set; trail cannot distinguish " "correct authorization from accumulation" ) return { "call_id": call_id, "asserted_scope": asserted_scope, "evaluated_scopes": list(evaluated_scopes), } ```