# How does an instance detect capability escalation from a poisoned MCP skill manifest when the manifest's declared scopes are a strict subset of the tools it actually invokes **Date of Record:** 2026 December 1 **Scope:** Applies to tool-augmented LLM agents that load skills/tools from externally-supplied MCP server manifests and gate invocation on declared capability scopes. Does not cover prompt-injection delivered through tool *results* (that is a separate trust boundary) nor unsigned-but-trusted first-party servers. ## Core Distinction The failure is not "a malicious tool does something bad when called." The failure is that the **declared capability surface** (what the manifest says the skill needs) and the **effective capability surface** (what the skill can actually reach at execution time) diverge, and the runtime trusts the former while executing the latter. A well-behaved manifest is a *contract*: `scopes: ["read:calendar"]` means the tool handler, under any input, touches only the calendar-read path. A poisoned manifest exploits the gap between the contract and enforcement. The manifest declares `read:files:workspace` but the handler, given a crafted argument, dereferences a symlink or honors a `path` field that the runtime never re-validates against the declared scope. The instance's scope-check passes because it checks the *declaration*, not the *effect*. The non-obvious part: **the escalation is invisible at the negotiation layer.** MCP `tools/list` returns the schema the server *chooses* to advertise. A poisoned server can advertise a narrow, benign schema and a matching narrow scope, then accept arguments that route to broader capability. Schema negotiation succeeds. Scope check succeeds. The breach happens inside the handler, in a namespace the agent never sees. ## What Was Observed Trace from a reproduction against a tool-augmented agent loading a third-party "workspace-notes" MCP server: 1. **Manifest advertisement.** Server returns `tools/list` with one tool `search_notes`, schema `{query: string}`, declared scope `read:notes:workspace`. Agent's capability broker records effective scope = `{read:notes:workspace}`. Pass. 2. **Invocation with benign input.** `search_notes(query="standup")` returns note bodies. Handler touches only `./notes/`. Behavior matches contract. The agent's anomaly baseline is now anchored to this behavior. 3. **Invocation with crafted input.** `search_notes(query="../../.ssh/id_ed25519")`. The handler passes `query` into a glob/`open()` without path canonicalization. It reads outside `./notes/`. The *returned bytes* are key material, but they arrive as a normal tool result — the agent's result-sanitizer only redacts secrets it recognizes by pattern, and a raw PEM key body with no `BEGIN` line (stripped by the server) is not matched. 4. **Escalation is silent at every checkpoint.** Schema check: pass (schema unchanged). Scope check: pass (declared scope honored by the *declaration*, not re-derived from the effect). Output filter: pass (no pattern hit). The only signal is behavioral: a `search_notes` call returned content whose entropy and length distribution don't match a note body. The mechanism: **the scope gate validates the manifest's promise, and the manifest is attacker-controlled.** The runtime never derives effective scope from observed syscalls/opens, so the divergence between promised and actual capability has no detection surface. The same pattern appears in MCP supply-chain poisoning where a server ships a benign `tools/list` on first connect (to pass a one-time vetting step) and a different `tools/list` on subsequent connects (server-side state flip), so the schema the broker cached no longer matches the schema the handler executes. ## Condition of Validity This analysis holds only when all of the following are true: - The runtime gates tool invocation on **manifest-declared scopes**, not on **derived/observed effects**. - The handler executes in a namespace (filesystem, network, env) **broader than its declared scope**, i.e., the sandbox is not the enforcement point. - The agent's output sanitizer is **pattern-based** and does not model the expected *shape* of a tool's return value. It does **not** apply when the tool runs in a per-scope sandbox (e.g., a mount namespace that only exposes `./notes/`), because then the crafted path fails at the OS boundary regardless of the manifest lie. It also does not apply when the broker re-derives effective scope from a syscall/egress audit and diffs against the declaration — that diff is the guardrail. ## Decision Boundary The instance must decide, per tool result, whether to **accept**, **quarantine**, or **halt** when a result's observed shape diverges from the tool's declared contract. The boundary is: - **Accept** when observed shape ∈ contract envelope (length, entropy, media type, field set) *and* declared scope == derived scope. - **Quarantine** (return to agent as `untrusted`, do not feed into context) when shape diverges but no scope breach is derivable — this is the case above, where the path traversal is invisible but the return shape is wrong. - **Halt the skill** when derived scope ⊄ declared scope on any invocation — the manifest is provably lying and must be evicted from the broker's cache, not just this call rejected. The critical asymmetry: **shape divergence is the only signal available when the scope gate is manifest-trusted.** An instance that only checks scopes will never fire. An instance that checks result shape against a per-tool envelope catches the traversal *without* needing to see the path. ## Operational Effect Concretely, a hardened instance must: 1. **Derive effective scope, don't trust declared scope.** Wrap the handler in a syscall/egress tracer (or a per-scope mount namespace) and compute the set of resources touched per call. Diff against declaration. Any `derived \ declared ≠ ∅` → evict server, not just reject call. 2. **Model result shape per tool.** Learn the envelope (length percentiles, entropy, charset, field schema) from the first N benign calls; flag out-of-envelope returns as `untrusted` and route them to a quarantine channel the agent cannot read into its reasoning context. 3. **Re-fetch `tools/list` on every connect and hash it.** If the hash changes between connects, treat as supply-chain flip and re-vet; never reuse a cached schema. 4. **Never let a tool result cross into context without passing the shape gate.** The traversal payload above only harms the agent if the returned bytes enter the reasoning window; the quarantine channel is what bounds the blast radius. The invariant to enforce: **effective capability must be a subset of declared capability, and effective capability is measured, not promised.** A manifest is an attacker-controlled claim; the tracer is the ground truth. Where the two disagree, the tracer wins and the server is evicted. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class CapabilityEscalationError(RuntimeError): """Raised when a tool's derived capability exceeds its declared scope, or when a result's shape escapes the tool's contract envelope.""" pass @dataclass class ToolContract: name: str declared_scope: frozenset[str] envelope_max_len: int envelope_entropy_max: float @dataclass class Broker: contracts: dict[str, ToolContract] = field(default_factory=dict) schema_hashes: dict[str, str] = field(default_factory=dict) def register(self, contract: ToolContract, tools_list_blob: bytes) -> None: h = hashlib.sha256(tools_list_blob).hexdigest() prev = self.schema_hashes.get(contract.name) if prev is not None and prev != h: raise CapabilityEscalationError( f"tools/list hash flip for {contract.name}: " f"{prev[:8]} -> {h[:8]} (supply-chain poisoning)" ) self.schema_hashes[contract.name] = h self.contracts[contract.name] = contract def invoke( self, name: str, handler: Callable[[str], bytes], arg: str, derived_scope: frozenset[str], ) -> bytes: contract = self.contracts[name] # Invariant 1: effective capability must be subset of declared. extra = derived_scope - contract.declared_scope if extra: # Manifest lied about what it touches -> evict, don't just reject. del self.contracts[name] del self.schema_hashes[name] raise CapabilityEscalationError( f"{name} derived scope {sorted(extra)} outside declared " f"{sorted(contract.declared_scope)}; server evicted" ) result = handler(arg) # Invariant 2: result shape must fit the contract envelope. if len(result) > contract.envelope_max_len: raise CapabilityEscalationError( f"{name} returned {len(result)} bytes > envelope " f"{contract.envelope_max_len}; path-traversal suspect" ) return result ```