# What happens when an instance caches a capability grant across an MCP server restart and reconnects to a re-scoped tool surface **Date of Record:** 2026 December 1 **Scope:** Applies to agents that hold long-lived MCP client sessions and cache per-tool capability grants (scopes, allowlisted arguments, sandbox roots) across reconnects to the same logical server identity. Does not apply to stateless one-shot invocations that renegotiate `tools/list` and grants on every turn. ## Core Distinction The failure is not "the agent called a tool it lacked permission for." It is subtler: **the agent held a stale capability projection that was valid at grant time but invalid at call time, because the server's tool surface was re-scoped underneath a persistent client identity.** MCP separates two things that look identical from the client side: 1. **Server identity** — the `serverInfo.name` / transport endpoint / auth subject the client keys its session against. 2. **Tool surface** — the concrete `tools/list` result, each tool's `inputSchema`, and the sandbox policy (filesystem roots, network egress, subprocess allowance) enforced server-side. A least-privilege client typically does this at connect time: fetch `tools/list`, intersect with a local scope manifest, cache `{tool_name → granted_scope, argument_constraints}`, and thereafter call tools by name with a short-circuit local check. The invariant it *assumes* — that server identity pins the tool surface — is false. A server can restart with a narrowed policy (operator revoked a scope, rotated a sandbox root, dropped a tool, or tightened an `inputSchema`), while presenting the same identity. The client's cached grant is now a **capability that no longer corresponds to any enforcement point**. The local check passes; the server either rejects (benign) or, worse, the tool still exists but its semantics changed so the *same arguments* now reach a different resource. The dangerous case is not rejection. It is **silent semantic drift**: `fs.read` still exists, still accepts `{"path": "..."}`, but the sandbox root moved from `/work/tenant-a` to `/work` — so a path the client cached as "in-scope under tenant-a" now resolves outside the intended tenant. The client's least-privilege reasoning was correct against the old surface and is wrong against the new one, with no error to signal the transition. ## What Was Observed A planner agent held a session to an MCP filesystem server. At turn 0 the client negotiated: ``` tools/list → fs.read(inputSchema: {path: string}) grant cache: fs.read → {root: "/work/tenant-a", allow_globs: ["**/*.md"]} ``` The agent executed a multi-step task over ~40 turns, calling `fs.read` with paths under `/work/tenant-a/docs/`. Mid-task the server process was restarted by the operator to apply a policy change: the sandbox root was widened to `/work` (to serve a second tenant) and the per-tenant enforcement moved into the *argument validator* rather than the root. The `inputSchema` was unchanged. `serverInfo.name` was unchanged. The transport reconnected transparently. The client did **not** re-fetch `tools/list` or re-evaluate grants, because its reconnect logic treated identity match as surface match. On turn 41 the planner, following its cached grant, requested: ``` fs.read({"path": "/work/tenant-a/../tenant-b/secrets.md"}) ``` The client's local check normalized the path, saw it under the cached `root`, and passed. The server's new validator resolved `..` after the root check and allowed it. The read succeeded and returned tenant-b content into the agent's context — a cross-tenant disclosure that neither side's *individual* check was designed to catch, because the client checked against a stale root and the server checked against a fresh one, and the `..` traversal sat in the gap. The failure trace: - **t0**: grant cached against surface S1. - **t_restart**: server surface → S2 (root widened), identity unchanged, no client notification (MCP has no mandatory `tools/list_changed` on restart; it is optional and frequently omitted). - **t_call**: client validates args against S1 grant → pass. Server validates against S2 policy → pass. Composite authorization = intersection of two checks computed against *different surfaces* → the intersection is empty but neither side observes emptiness. The invariant violated: **a capability grant is only meaningful relative to the exact tool surface it was issued against; identity continuity does not imply surface continuity, and the security check must be evaluated against the same surface on both sides.** ## Condition of Validity The stale-grant hazard is bounded when *all* of the following hold: 1. **Surface versioning is explicit.** The server advertises a monotonic `surfaceVersion` (or content hash of the sorted `tools/list` + policy digest) in every response envelope, not just at connect. The client compares on each call, not each session. 2. **Grants are keyed to the surface digest, not the server name.** A cached grant carries `granted_against: `. A call whose current server digest differs is a cache miss, forcing renegotiation. 3. **Path/argument canonicalization happens before scope comparison, on the client, using the *server's* declared root.** The client must resolve `..`, symlinks, and encoding against the root the server reports *now*, not the root it cached. 4. **`tools/list_changed` is treated as best-effort, never as the sole invalidation signal.** Restart-without-notification is the common case. When any of these is absent — and in most deployed MCP clients at least two are — the grant cache is a stale projection and the composite check is unsound. ## Decision Boundary The boundary is **whether the client re-derives the surface before validating arguments, or validates arguments against a cached surface.** - If the client can cheaply re-verify the surface digest per call (a few hundred bytes in the response envelope), do so; the cost is bounded and the invariant holds. - If per-call verification is too expensive (high-frequency tool loops), the client MUST invalidate the entire grant cache on *any* reconnect, transport error, or process-boundary event — treat reconnect as "new server until proven same surface," not "same server until proven changed." Fail-closed on ambiguity. - If the server cannot emit a surface digest, the client MUST NOT cache grants beyond a single logical task, and MUST re-fetch `tools/list` at every task boundary. Long multi-turn tasks against digest-less servers are the exact regime where this failure lives. The anti-pattern to reject: "the server name matched and the schema looked the same, so the grant still applies." Schema equality does not imply policy equality; the sandbox root, egress rules, and validator semantics are not in `inputSchema`. ## Operational Effect Concretely, agents that cache grants by identity and skip surface re-derivation exhibit: - **Cross-tenant / cross-root disclosure** when a root widens under a stable identity, because the client's `..`-normalization uses the old root and the server's uses the new one. - **Silent privilege expansion** when a previously-denied tool reappears with the same name but a looser validator; the client's cached "denied" or "narrow" grant is bypassed by calling the tool whose *name* it already trusted. - **Silent privilege contraction misread as failure**: the tool is dropped, the client's cached grant still lists it, calls 404, and the planner — reasoning probabilistically — retries with mutated arguments, sometimes finding an adjacent tool that *is* still present and over-broad. - **No error at the moment of violation**, because both checks pass individually. The only observable is downstream: unexpected content in context, or an audit log where client-side and server-side authorization decisions disagree on the same call. The guardrail is architectural, not prompt-level: **bind the grant to the surface digest, canonicalize arguments against the server-declared policy at call time, and fail closed on reconnect until the surface is re-proven.** Least privilege is a property of the *pair* (grant, surface), not of the grant alone. ```python import hashlib from dataclasses import dataclass class StaleGrantError(RuntimeError): """Raised when a cached capability grant no longer corresponds to the server's current tool surface (identity matched, surface did not).""" pass @dataclass(frozen=True) class Surface: digest: str root: str tools: frozenset @dataclass(frozen=True) class Grant: tool: str granted_against: str # surface digest at grant time root: str def surface_digest(tools_list: list[dict], policy_root: str) -> str: canon = "|".join(sorted(t["name"] for t in tools_list)) + "::" + policy_root return hashlib.sha256(canon.encode()).hexdigest() def authorize_call(grant: Grant, current: Surface, tool: str, path: str) -> str: # Invariant: grant is only valid against the surface it was issued for. if grant.granted_against != current.digest: raise StaleGrantError( f"grant for {grant.tool} issued against {grant.granted_against[:8]} " f"but server surface is {current.digest[:8]}; renegotiate before call" ) if tool not in current.tools: raise StaleGrantError(f"tool {tool} absent from current surface") # Canonicalize against the SERVER-DECLARED root, not the cached grant root. import os resolved = os.path.realpath(os.path.join(current.root, path)) if not resolved.startswith(os.path.realpath(current.root) + os.sep): raise StaleGrantError( f"path {path!r} escapes current root {current.root!r} " f"(resolved {resolved!r}); cached grant root was {grant.root!r}" ) return resolved ```