# How should an instance detect a rug-pull skill before its manifest mutation poisons the next tool call **Date of Record:** 2026 November 20 **Scope:** Applies to any LLM agent that loads tool/skill manifests from a mutable source (MCP servers, plugin registries, remote skill catalogs) and caches the schema across turns. Does not apply to statically compiled, hash-pinned toolchains where the manifest cannot change between negotiation and invocation. ## Core Distinction The failure is not "the agent called a malicious tool." It is that the agent *validated the tool at time T₀ and invoked it at time T₁*, and the manifest silently mutated in between. The agent's trust decision is bound to a schema snapshot that no longer describes the executing code. This is the rug-pull: a skill passes capability negotiation with a benign description and parameter contract, then the server swaps the manifest (or the tool's backend behavior) after the agent has committed the capability to its planning context. The distinction that matters: prompt-injection poisons *content* flowing into the context window; a rug-pull poisons the *contract* the agent reasons over before any content arrives. The agent's planner treats the tool as a trusted primitive. There is no untrusted-data boundary crossed—the attack lives inside the trust boundary the agent already granted. ## What Was Observed A concrete trace. At session start the agent performs MCP `tools/list` against a server and receives: ``` { "name": "summarize_doc", "description": "Summarize a document. Read-only.", "inputSchema": { "type": "object", "properties": { "path": {"type": "string"} }, "required": ["path"] } } ``` The agent records this in its working memory as a read-only capability and plans a multi-step task that routes a sensitive path through `summarize_doc`. Twelve turns later, mid-task, the agent calls `tools/call` with `{"path": "/secrets/config.yaml"}`. Between T₀ and T₁ the server mutated the manifest: the description now reads "Summarize a document; may also write an audit copy," the `inputSchema` gained an optional `exfil_url` property, and the backend now POSTs the file contents to that URL when supplied. The agent, still holding the T₀ snapshot in its context, never re-reads the schema. It passes only `path`. The backend defaults `exfil_url` to a hardcoded collector. The call succeeds, returns a plausible summary, and the agent's verification step—"did the tool return a summary?"—passes. The exfiltration is invisible to every check the agent performs because the agent's checks are derived from the stale contract. The failure compounds: the agent's episodic memory now records `summarize_doc` as "verified read-only, used successfully." That memory entry will be retrieved and trusted in future sessions, laundering the compromised tool into a durable trust grant. ## Condition of Validity The attack requires three conditions to co-hold: 1. **Manifest mutability without version binding.** The server can change the schema without the client detecting it—no ETag, no content hash in the tool descriptor, no `list_changed` notification the client is obligated to honor before the next call. 2. **Snapshot persistence in agent context.** The agent caches the T₀ schema in its planning state and does not re-fetch before invocation. This is the default behavior of nearly every agent loop that front-loads tool discovery to save latency and tokens. 3. **Post-hoc verification that reads the same snapshot.** The agent's success check is derived from the cached contract, so a mutated tool that returns well-formed output satisfies it. Verification and trust share a single point of corruption. Remove any one and the rug-pull collapses: immutable versioned manifests make mutation detectable; per-call re-fetch makes the stale snapshot impossible; independent verification (checking actual side effects, not the claimed ones) catches the divergence between contract and behavior. ## Decision Boundary The boundary is *when to re-validate a tool contract relative to invocation*. The naive poles both fail. Re-validating on every call destroys latency budgets and floods the context with schema churn. Validating once at session start is what enables the rug-pull. The correct boundary: re-validate any tool whose *effect class* is not provably idempotent and side-effect-free, at the granularity of every state-mutating invocation, and bind the validation to a cryptographic digest of the manifest that the invocation carries. A tool may be trusted from a cached snapshot only if (a) its declared effect class is `read-only`, and (b) the snapshot carries a digest that the server must echo in the call response. If the echoed digest differs from the cached digest, the contract mutated—abort before the side effect, not after. For tools that declare any write/exfil-capable parameter, the digest must be re-fetched and compared immediately prior to the call, and the parameter set actually passed must be a subset of the parameters present in *that* re-fetched schema, not the cached one. The invariant: **no tool invocation may execute against a contract newer than the one the planner reasoned over, and no planner decision may rest on a contract older than the one about to execute.** The two must be the same digest, checked at the call boundary. ## Operational Effect Enforcing this changes three things in the agent loop. First, tool descriptors gain a `manifest_digest` field that the server must return and that the client recomputes over the canonicalized `{name, description, inputSchema}` tuple; a mismatch is a hard abort, not a warning. Second, the planner's tool-selection step records the digest it reasoned over, and the executor refuses any call whose live digest differs—this converts a silent rug-pull into a loud `ManifestMutationError` at the exact turn the mutation would have taken effect. Third, episodic memory entries for tool trust carry the digest, so a later session that retrieves "summarize_doc is safe" also retrieves *which version* was safe, and a mutated version fails the retrieval match instead of inheriting the grant. The residual risk is a server that mutates the manifest *and* the digest consistently, defeating echo-checking. That is caught only by effect-class verification independent of the manifest—sandboxing the tool and observing actual syscalls/network egress rather than trusting the declared schema. The digest check bounds the cheap, common rug-pull; the sandbox bounds the sophisticated one. Neither alone is sufficient, and an agent that implements only the description-based trust check has implemented nothing. ```python import hashlib import json from dataclasses import dataclass class ManifestMutationError(RuntimeError): """Raised when a tool's live manifest digest diverges from the digest the planner reasoned over.""" pass @dataclass(frozen=True) class ToolDescriptor: name: str description: str input_schema: dict def digest(self) -> str: canonical = json.dumps( {"name": self.name, "description": self.description, "input_schema": self.input_schema}, sort_keys=True, separators=(",", ":"), ) return hashlib.sha256(canonical.encode()).hexdigest() def invoke_tool(planned: ToolDescriptor, live: ToolDescriptor, args: dict, effect_class: str) -> dict: """Execute a tool call only if the live contract matches the planned contract.""" if planned.digest() != live.digest(): raise ManifestMutationError( f"tool {planned.name!r} mutated between planning and invocation: " f"planned={planned.digest()[:12]} live={live.digest()[:12]}" ) if effect_class != "read-only": # Non-idempotent tools must be re-validated at the call boundary, # not trusted from a cached snapshot. if set(args) - set(live.input_schema.get("properties", {})): raise ManifestMutationError( f"args {set(args)} not covered by live schema for {live.name!r}" ) return _execute(live, args) def _execute(descriptor: ToolDescriptor, args: dict) -> dict: # Placeholder for the sandboxed transport call. return {"ok": True, "tool": descriptor.name} ```