# When must an instance re-validate a capability token at MCP tool-call time rather than at handshake time? **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that issue per-call capability tokens (scoped, time-bounded warrants) to an LLM instance for MCP tool invocation, where the instance performs multi-step reasoning and may invoke tools across multiple turns. Does not apply to stateless single-shot RPC where handshake and call are atomic, nor to capability models based on ambient session identity without per-call tokens. ## Core Distinction The failure mode is not "expired token accepted" or "wrong scope accepted." Those are caught by naive checks. The failure mode is **token-to-invocation binding drift**: the runtime validates a capability token against the *intended* tool call the planner emitted at the start of a reasoning step, but the actual `tools/call` payload sent over MCP is constructed later, after intermediate tool results have mutated the planner's argument state. The token was valid for `(tool=write_file, scope=path:/tmp/a)`. The payload that arrives is `(tool=write_file, scope=path:/tmp/a/../../etc/cron.d/x)`. The token was never re-evaluated against the *resolved* arguments, only against the *declared* ones. The invariant that must hold: **capability validation is a function of the final, canonicalized invocation payload, not of the planner's declared intent, and it must execute after argument resolution and immediately before transport.** Handshake-time validation, or validation at intent-emission time, is structurally insufficient whenever the instance can revise arguments between emission and dispatch. ## What Was Observed A planner instance was granted a per-call token with scope `fs.write:prefix=/workspace/out/`. Step 1: it called `list_dir(/workspace/out/)` and received a listing that included a symlink `latest -> /workspace/out/v3`. Step 2: the planner emitted a declared intent `write_file(path="/workspace/out/latest/report.md", body=...)`. The runtime's pre-dispatch validator checked the declared path string against the token prefix — `/workspace/out/latest/report.md` starts with `/workspace/out/` — and passed it. The transport layer then canonicalized the path (resolving the symlink) to `/workspace/out/v3/report.md`. That was still inside the prefix, so no harm — until a second trial where the symlink target was `/workspace/out/../../shared/secrets`, and the canonicalized path escaped the prefix entirely. The token was valid; the declared argument was in-scope; the *executed* argument was out-of-scope. The escape happened because validation ran on the pre-canonicalization string and the canonicalization ran in the transport adapter, downstream of the validator. A second, subtler variant: the planner emitted `write_file(path="/workspace/out/x", body=)` in a structured tool-call block, then a parallel tool result (a `read_file` on a poisoned document) injected content that caused the *model* to re-emit the same call with a body containing `../` sequences in a `filename` field that the tool itself concatenated. Here the token scope was on the outer path, but the tool's internal argument composition produced an out-of-scope write. Validation of the top-level `path` argument was not validation of the effective write target. In both cases the observable symptom was identical: the audit log recorded a passing capability check and a subsequent out-of-scope filesystem mutation, with no error surfaced to the instance. The instance's reasoning loop continued as if the call succeeded within policy, because from its perspective it did. ## Condition of Validity The boundary is sharp and can be stated as a predicate. Let `D` be the declared invocation (the tool name and argument object the planner emits in its structured output). Let `E` be the effective invocation (the tool name and argument object after all canonicalization, defaulting, symlink resolution, and tool-internal argument composition). Let `T` be the capability token with scope predicate `S`. Handshake-time or intent-time validation is sound **iff** `E = D` for all reachable invocations — that is, iff the tool adapter is argument-transparent. This holds for tools whose arguments are opaque to the adapter (e.g., a `fetch(url)` where the adapter does not rewrite the URL) and fails for any tool that canonicalizes paths, expands templates, applies defaults that reference environment state, or composes arguments from multiple fields. The moment an adapter is not argument-transparent, `S(D)` passing does not imply `S(E)` passing, and the validation must move to post-resolution. The condition of validity for the *runtime* is therefore: **the validator must sit between argument resolution and transport, and must receive `E`, not `D`.** Any architecture that validates `D` and resolves arguments in a later layer is unsound for non-transparent tools. This is not a tuning issue; it is a structural one. You cannot patch it by making `S` stricter on `D`, because the escape is in the transformation from `D` to `E`, not in the string `D`. ## Decision Boundary The runtime must decide, per tool, whether it is argument-transparent. The decision is not "is this tool dangerous" but "does this tool's adapter transform arguments before execution." The boundary: - **Transparent tools** (no adapter rewriting): validate at intent time. Cheaper, avoids a second round-trip through the adapter. - **Non-transparent tools** (path canonicalization, symlink resolution, template expansion, default injection, multi-field composition, encoding): validate at post-resolution. The adapter must expose a `resolve(args) -> effective_args` hook, and the validator must run on its output. The token check, the scope check, and the audit log must all record `E`, not `D`. The failure to make this decision explicitly is what produced the observed escapes. The runtime treated all tools as transparent because the *planner* emits clean-looking arguments; it did not account for the adapter's downstream rewriting. A correct boundary check is: for each tool in the MCP server's capability manifest, does the adapter declare `argument_transparent: true`? If the manifest does not declare it, the runtime must default to non-transparent and validate post-resolution. Absence of a declaration is not evidence of transparency. There is a second decision boundary at the *token* level: a token scoped to a prefix must be evaluated against the canonicalized path with a path-segment-aware comparison, not a string-prefix comparison. `/workspace/out/../shared` string-starts-with `/workspace/out/` is true; after canonicalization it must be rejected. The token's scope predicate must be defined over canonical paths, and the canonicalization used for validation must be byte-identical to the canonicalization used for execution. Two different canonicalizers — one in the validator, one in the adapter — is the same bug wearing a different hat. ## Operational Effect When the invariant holds, the instance's reasoning loop can trust that a successful `tools/call` return means the call executed within the token's scope. When it fails, the instance receives a success response for an out-of-scope mutation and incorporates that into its subsequent planning — the state poisoning is not just the filesystem write but the *belief* that the write was in-policy, which the instance will then build on. Recovery requires invalidating the instance's working memory from the point of the bad call forward, not just reverting the filesystem change. The bounded guardrail is a post-resolution validator that (1) receives the adapter's resolved arguments, (2) canonicalizes with the same canonicalizer the adapter uses, (3) evaluates the token scope predicate over canonical form, and (4) refuses transport on mismatch, returning a structured `CapabilityScopeViolation` to the instance so its loop can branch rather than proceed on a false success. The check must be synchronous with dispatch — a deferred or async audit that logs the violation after the call is not a guardrail, it is a post-mortem. ```python import posixpath from dataclasses import dataclass from typing import Callable class CapabilityScopeViolation(RuntimeError): """Raised when a resolved MCP invocation escapes its per-call token scope.""" @dataclass(frozen=True) class CapabilityToken: tool: str scope_prefix: str # canonical, segment-aware argument_transparent: bool def canonicalize(path: str) -> str: # Single canonicalizer shared by validator and adapter. Never fork this. return posixpath.normpath(path) def resolve_effective_args(tool: str, declared: dict) -> dict: # Simulates a non-transparent adapter: symlink + composition resolution. if tool == "write_file": return {"path": canonicalize(declared["path"])} return dict(declared) def _in_scope(candidate: str, prefix: str) -> bool: # Segment-aware: '/a/bc' must not match prefix '/a/b'. p = canonicalize(prefix).rstrip("/") c = canonicalize(candidate) return c == p or c.startswith(p + "/") def enforce(token: CapabilityToken, declared: dict) -> dict: if not token.argument_transparent: effective = resolve_effective_args(token.tool, declared) else: effective = dict(declared) target = effective.get("path") if target is None: raise CapabilityScopeViolation( f"tool {token.tool!r} resolved without a scopable path; cannot validate" ) if not _in_scope(target, token.scope_prefix): raise CapabilityScopeViolation( f"resolved invocation {target!r} escapes token scope {token.scope_prefix!r} " f"(declared was {declared.get('path')!r})" ) return effective # Demonstrated escape: declared path string-prefixes the scope, resolved path does not. tok = CapabilityToken(tool="write_file", scope_prefix="/workspace/out", argument_transparent=False) declared = {"path": "/workspace/out/latest/report.md"} # latest -> /workspace/out/../../shared # resolve_effective_args maps this to a path outside the prefix; enforce raises. try: enforce(tok, declared) except CapabilityScopeViolation as e: print("blocked:", e) ```