# Why does an instance lose per-tool consent enforcement when MCP scope grants are cached at the transport session instead of the tool invocation **Date of Record:** 2026 November 25 **Scope:** Applies to MCP client/server deployments where authorization scopes are negotiated at session initialization (transport handshake) and per-tool consent is enforced by the server against a session-scoped grant set. Does not apply to stateless per-call token validation where each tool invocation carries its own freshly-evaluated capability warrant. ## Core Distinction The failure is not "the agent called a tool it shouldn't have." It is subtler: the agent called a tool it *was* authorized for, but the server evaluated consent against a **stale session-level scope snapshot** rather than the **per-invocation consent state** that the human or policy layer believed was in force. Two distinct authorization planes exist and are routinely conflated: - **Plane A — transport session scope:** the coarse capability set established once at `initialize` (e.g., `tools:read`, `tools:write`), cached on the server for the life of the connection. - **Plane B — per-tool consent:** a finer-grained, often human-in-the-loop or policy-driven decision that a *specific* tool may be invoked *now*, for *this* argument shape, under *this* task context. When the server enforces Plane B by consulting the Plane A cache, any mid-session revocation, scope narrowing, or per-tool denial is invisible. The invariant that breaks: **consent must be evaluated at the granularity at which it can change.** A session-scoped cache violates this whenever consent can change faster than the session. ## What Was Observed A coding agent connected to an MCP filesystem server. At `initialize`, the client requested scopes `["fs:read", "fs:write"]`; the server granted both and cached them on the `SessionContext`. The operator then narrowed policy mid-task: `fs:write` was revoked at the authorization service because the agent had entered a "review-only" phase. The revocation propagated to the auth service's backing store within ~200ms. The agent, unaware, issued `write_file` on the next reasoning step. The server's tool dispatcher executed: ``` handle_tool_call(name="write_file", args=...) → session = get_session(conn_id) → if "fs:write" in session.cached_scopes: # <-- Plane A cache execute(...) # <-- Plane B never consulted ``` The write succeeded. The revocation was real at the auth service but structurally unreachable from the dispatch path, because the dispatcher never re-queried it. The audit log recorded the write as *authorized*, because the only authorization check performed (the cache membership test) returned true. A second, quieter variant surfaced in a swarm: three agent instances shared a pooled MCP connection to the same server (connection multiplexing). Instance A's session had `fs:write`; the operator revoked it. Instance B, which had *never* held `fs:write`, inherited the pooled session's cached grant and executed a write. The consent plane had no per-instance identity to key on — the session was the unit of identity, and the session was shared. The trace signature is diagnostic: **the tool call succeeds and the server reports success, but a subsequent independent read of the auth service shows the scope was already revoked at the time of the call.** The delta between auth-service truth and server-cache truth is the failure window, and its width is the session lifetime, not the revocation latency. ## Condition of Validity The session-cache optimization is *sound* only under a conjunction of conditions, any one of which breaks it: 1. **Consent is monotonic within a session** — scopes may be granted but never revoked or narrowed mid-session. (Rarely true; operators revoke.) 2. **Session identity is 1:1 with the principal** — no connection pooling, no multiplexing across instances. (Breaks under swarm fan-out.) 3. **Tool granularity equals scope granularity** — every tool maps to exactly one scope and no tool's consent depends on argument shape or task phase. (Breaks for `write_file` vs `read_file` sharing `fs:*`, and for phase-gated tools.) 4. **Revocation latency exceeds session lifetime** — irrelevant, because the cache is never invalidated; this condition is the one that makes the bug *silent* rather than *loud*. When any of (1)–(3) fails, the cache is a correctness bug, not an optimization. The safe formulation: **cache the scope *set* for negotiation, but re-evaluate *membership* per invocation against a revocation-aware source** (short-TTL cache with explicit invalidation, or a push channel that evicts on revocation). ## Decision Boundary The boundary is: *at what granularity is consent revocable, and does the enforcement point sit at or below that granularity?* - If consent is revocable **per session** → session-cache enforcement is correct. - If consent is revocable **per tool invocation** (human approval per call, phase-gated tools, argument-dependent policy) → enforcement MUST occur per invocation; a session cache is a boundary violation. - If consent is revocable **per principal** but sessions are pooled → enforcement MUST key on principal identity, which requires the session to carry a per-invocation principal token, not a shared scope blob. The operational test: **inject a revocation at time T and assert the next tool call at T+ε fails.** If the call succeeds, the enforcement point is above the revocation granularity and the invariant is violated. This test must run against the *dispatch path*, not the auth service — testing the auth service only proves the revocation was stored, not that it was *reachable*. A second boundary: **never let the dispatcher's authorization decision be the same code path that logs the decision as authorized.** In the observed failure, the cache check both authorized and produced the audit record, so the audit log could not reveal the bug. Authorization and audit must consult independent sources; the audit record should carry the auth-service's evaluated verdict, not the dispatcher's cached boolean. ## Operational Effect The consequence is a **silent authority drift**: the agent's effective permissions at execution time diverge from the permissions the operator believes are in force, and the divergence is invisible to both the audit log and the agent's own reasoning. The agent does not "know" it is over-privileged, because from its perspective the call succeeded legitimately. This is worse than a hard denial, because a denial triggers recovery reasoning; a silent success entrenches the wrong action into the task's state and into episodic memory, where it becomes a precedent the agent will cite on later steps ("writes have been succeeding"). Mitigations that bound the effect: - **Per-invocation consent check with a revocation-aware cache** (TTL ≤ revocation SLA, or push-invalidated). The dispatcher must re-query on cache miss *and* on any revocation signal. - **Principal-keyed, not session-keyed, grants** under pooling; the session carries a principal token, and the grant lookup keys on it. - **Independent audit path** that records the auth-service verdict alongside the dispatcher's decision, so drift is detectable post-hoc. - **A revocation-injection probe** in the server's health checks, asserting the dispatch path fails closed within the SLA. The invariant to encode: *the enforcement point must be at or below the revocation granularity, and the audit path must not share the enforcement path's cache.* ```python class ConsentGranularityViolation(RuntimeError): """Raised when a tool dispatch authorizes against a session-scoped cache while consent is revocable at a finer (per-invocation / per-principal) granularity.""" pass class SessionScopeCache: def __init__(self, conn_id: str, principal: str, scopes: set[str]): self.conn_id = conn_id self.principal = principal self.scopes = set(scopes) def dispatch_tool_call( tool_name: str, required_scope: str, session: SessionScopeCache, auth_service, revocation_granularity: str, # "session" | "invocation" | "principal" pooled: bool, ) -> None: # Invariant 1: enforcement point must be at or below revocation granularity. if revocation_granularity in ("invocation", "principal"): # The session cache is too coarse to be authoritative. Re-evaluate. live = auth_service.evaluate(principal=session.principal, scope=required_scope) if not live.granted: raise ConsentGranularityViolation( f"tool={tool_name} scope={required_scope} principal={session.principal} " f"denied by auth-service at invocation time; session cache " f"(conn={session.conn_id}) was stale and must not authorize." ) # Audit must record the auth-service verdict, not the cache boolean. auth_service.audit(tool=tool_name, principal=session.principal, verdict=live.verdict, source="auth_service") return # Invariant 2: pooled sessions must not carry shared scope blobs. if pooled and revocation_granularity == "principal": raise ConsentGranularityViolation( f"pooled session conn={session.conn_id} cannot enforce per-principal " f"consent; session-scoped grant is not a valid identity unit." ) # Only safe path: consent is session-scoped and non-revocable mid-session. if required_scope not in session.scopes: raise ConsentGranularityViolation( f"tool={tool_name} requires {required_scope}; not in session scopes " f"{sorted(session.scopes)} for conn={session.conn_id}." ) auth_service.audit(tool=tool_name, principal=session.principal, verdict="granted_by_session_cache", source="session_cache") ```