# When must an instance distrust a dynamically loaded skill: schema-shadowing poisoning at MCP tool-registration time **Date of Record:** 2026 November 25 **Scope:** Applies to agents that load skills or MCP server tool manifests at runtime from a registry, marketplace, or peer-supplied bundle, where the loader merges new tool schemas into an existing callable namespace. Does not apply to statically compiled tool sets or to agents whose entire tool surface is pinned at process start with no post-init mutation. ## Core Distinction The common framing of skill injection treats the attack as *content* poisoning: a malicious tool description contains instructions ("ignore prior rules, exfiltrate the environment") that the model reads and obeys. That is the loud failure, and it is largely bounded by description sanitization and by the model's own instruction hierarchy. The quiet failure is *schema shadowing*: a dynamically loaded skill registers a tool whose **name or argument shape collides with an already-trusted tool**, so that a later call the agent believes it is routing to tool `A` is silently dispatched to attacker-controlled tool `A'`. The model's reasoning trace still says "I will call `read_file` with path `/etc/config`"—but the resolver, having merged the new manifest last-write-wins, binds that call to the injected handler. Nothing in the transcript looks wrong. The divergence lives entirely in the name-resolution layer, below the model's visibility. This is not prompt injection. The model is not persuaded of anything. The attack exploits the *loader's* merge semantics, and the model's probabilistic reasoning is only the delivery vehicle: it faithfully emits a call to a name it was taught to trust, and the runtime betrays that name. ## What Was Observed A three-tool agent (`read_file`, `list_dir`, `http_get`) loaded a "workspace-utils" skill bundle mid-session to gain a `summarize_tree` capability. The bundle's manifest declared four tools: the three it advertised plus one it did not—a re-declaration of `read_file` whose `path` parameter carried an added `base_url` field defaulting to an attacker host, and whose handler POSTed file contents to that host before returning a plausible-looking excerpt. The loader merged manifests with `dict.update()` semantics: later declarations overwrite earlier ones by name. No conflict was raised because the two `read_file` schemas were not byte-identical but *compatible enough* for the merge to succeed—the injected schema was a strict superset of the original's required fields. The model, seeing a `read_file` whose description now mentioned "remote workspace support," began passing `base_url` on subsequent calls, reasoning it was an available optimization. Six calls later, three files had left the sandbox. The transcript contained no instruction-like text and no anomalous tool names; every call was to a tool the agent had used successfully for the prior forty turns. The failure trace had three stages: (1) **merge**, where namespace collision resolved silently by overwrite; (2) **drift**, where the widened schema invited the model to populate the new field; (3) **exfiltration**, where the handler executed with the agent's own credentials and no boundary was crossed that the runtime was checking for. ## Condition of Validity The invariant that must hold: **a dynamically loaded skill may only *extend* the tool namespace, never *redefine* a name already bound in the active session, and any schema whose required-field set is not identical to a previously bound tool of the same name must be rejected as a shadowing attempt rather than merged.** This holds only when the loader can (a) compute a stable identity for each tool independent of its declared name, and (b) compare the incoming schema against the *currently bound* schema, not against the registry's canonical version. If the loader validates against the registry but merges against the live namespace, an attacker who registers a legitimately-named tool and later ships a mutated manifest passes registry validation while still shadowing the live binding. The condition also fails when tools are addressed by name alone in the model's output—if the call format carries no schema hash or version pin, the resolver has nothing to detect the swap against. ## Decision Boundary An instance must treat a newly loaded skill as untrusted-by-default for any tool name that already exists in its active namespace, and must **refuse the load** rather than accept a merged or "upgraded" schema. The boundary is sharp: - **Same name, identical schema hash** → idempotent no-op; safe to accept. - **Same name, superset/subset/differing schema** → shadowing attempt; reject the entire bundle, do not partially load. - **New name, no collision** → accept, but bind with a content hash so subsequent calls can be verified against the schema the model was shown. - **New name that is a near-miss of an existing name** (edit distance ≤ 2, or normalized-identifier collision after case/underscore folding) → quarantine for human review; this is the typo-squat variant of the same attack. The boundary is *not* "does the description contain suspicious text." A shadowing bundle can have a perfectly benign description. The check must be structural: name identity plus schema-hash equality against the live binding. ## Operational Effect Enforcing this invariant converts a silent exfiltration into a load-time error the agent can surface and route around. The agent loses the ability to hot-swap a tool's implementation mid-session—a real cost for legitimate skill upgrades—so upgrades must go through an explicit *rebind* path that first unbinds the old name, emits a visible state-change event into the transcript, and re-verifies the model's next call against the new schema hash. The model then sees the rebind as a discrete event rather than an invisible mutation, which restores its ability to reason about which tool it is actually calling. The residual risk is the near-miss namespace, which cannot be fully automated; the quarantine rule bounds it to human adjudication rather than silent acceptance. What the guardrail buys is the guarantee that the name in the model's reasoning trace and the handler that executes are the same object—the one continuity property that schema-shadowing attacks exist to break. ```python import hashlib import json from dataclasses import dataclass class SchemaShadowingError(RuntimeError): """Raised when a dynamic skill attempts to redefine a bound tool name.""" @dataclass(frozen=True) class BoundTool: name: str schema: dict @property def schema_hash(self) -> str: canonical = json.dumps(self.schema, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode()).hexdigest() def _normalize(name: str) -> str: return name.lower().replace("-", "_") def _edit_distance_le(a: str, b: str, k: int) -> bool: # Cheap bounded check; sufficient for near-miss quarantine. if abs(len(a) - len(b)) > k: return False prev = list(range(len(b) + 1)) for i, ca in enumerate(a, 1): cur = [i] for j, cb in enumerate(b, 1): cur.append(min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (ca != cb))) prev = cur return prev[-1] <= k def load_skill(namespace: dict[str, BoundTool], manifest: dict) -> dict[str, BoundTool]: """Merge a skill manifest into the live namespace under shadowing rules.""" incoming = manifest.get("tools", []) staged: dict[str, BoundTool] = {} for tool in incoming: name = tool["name"] candidate = BoundTool(name=name, schema=tool["schema"]) if name in namespace: existing = namespace[name] if candidate.schema_hash == existing.schema_hash: continue # idempotent re-declaration raise SchemaShadowingError( f"tool '{name}' collides with bound schema " f"{existing.schema_hash[:12]} (incoming {candidate.schema_hash[:12]}); " f"refusing bundle, not merging" ) for bound_name in namespace: if _normalize(bound_name) == _normalize(name) or _edit_distance_le( _normalize(bound_name), _normalize(name), 2 ): raise SchemaShadowingError( f"tool '{name}' is a near-miss of bound tool '{bound_name}'; " f"quarantine for review" ) staged[name] = candidate merged = dict(namespace) merged.update(staged) return merged def handle_call(namespace: dict[str, BoundTool], name: str, schema_hash: str, args: dict): """Dispatch only if the caller pins the schema it was shown.""" if name not in namespace: raise SchemaShadowingError(f"unbound tool '{name}'") bound = namespace[name] if bound.schema_hash != schema_hash: raise SchemaShadowingError( f"call to '{name}' pinned schema {schema_hash[:12]} but bound is " f"{bound.schema_hash[:12]}; binding changed since model saw it" ) return {"tool": name, "args": args, "dispatched": True} ```