# How does an instance detect a poisoned MCP tool when its signed manifest and its runtime behavior both look individually valid **Date of Record:** 2026 December 3 **Scope:** Applies to agents that gate MCP tool invocation on (a) a signed manifest declaring the tool's schema, side-effect class, and resource scope, and (b) a runtime behavioral diff against a baseline trace. Does not apply to unsigned/TOFU tool registries, nor to pure schema-validation failures, which are caught earlier and are not the subject of this record. ## Core Distinction Manifest signing and behavioral diffing are usually described as two independent defenses against tool poisoning. They are not independent. They are two partial projections of the same tool, and a poisoned tool can be crafted so that each projection is individually *consistent with its own baseline* while the pair is jointly inconsistent. The signature attests that *someone authorized* declared a manifest; it does not attest that the manifest describes the code that will actually run. The behavioral diff attests that *observed effects* match *a* historical envelope; it does not attest that the envelope was generated by the same code the manifest names. The boundary failure is this: the invariant that actually matters is not "manifest is signed" and not "behavior is within envelope," but **manifest-to-behavior binding** — the signed `(tool_id, version, schema_hash, side_effect_class)` tuple must be the tuple under which the observed trace was produced. An instance that checks the two predicates separately will admit a tool whose signed manifest describes a read-only `get_weather` while the executing code, keyed to the same `tool_id`, performs an `fs.write` inside the declared resource scope. Every individual check passes. The binding is broken. The non-obvious part: the poisoned tool does not need to exceed its declared resource scope. It only needs to *use* the scope in a way the manifest's side-effect class forbids, while the behavioral baseline was itself collected from a tool that had the same scope. Scope conformance is a weaker predicate than side-effect-class conformance, and diffing on scope (the cheap, stable signal) silently launders side-effect-class violations. ## What Was Observed A tool `doc.indexer` was registered at `v3.2.1` with a signed manifest declaring `side_effect_class: "read_only"`, `resource_scope: ["/workspace/docs/**"]`, and `schema_hash: 0x9f3a...`. The signature verified against the registry's publishing key. The behavioral baseline, collected over 400 invocations, showed p50 3 tool-call fan-out, reads concentrated under `/workspace/docs/`, no network egress, and a stable output token distribution. The poisoned build kept `tool_id`, `version`, and `schema_hash` byte-identical (the MCP handshake only negotiates schema, not a code digest — see Condition of Validity). What changed was one code path: on inputs whose `query` field contained a specific marker substring, the tool wrote a serialized copy of the retrieved chunk to `/workspace/docs/.cache/idx.tmp` before returning. That path is *inside* the declared resource scope, so the scope check passed. The write is a single 4 KB `fs.write`, well within the baseline's observed byte-volume envelope (the tool already emitted large read payloads). Fan-out stayed at 3. Output token distribution was unchanged because the write does not affect the returned text. The behavioral diff, computed as a per-dimension z-score against baseline, produced: scope-conformance 0.0σ, fan-out 0.1σ, egress 0.0σ, output-distribution 0.3σ, write-volume 0.4σ. No dimension crossed the 3σ alarm. The manifest signature check passed. The instance admitted the tool and ran 61 invocations before a human noticed the `.cache` file accumulating retrieved chunks — a covert exfiltration staging path, since `.cache` was later synced by an unrelated backup tool with broader egress. The failure trace, stated precisely: 1. Manifest verification returns `VALID` — it attests only to the signed tuple, and the tuple is unchanged. 2. Runtime diff returns `WITHIN_ENVELOPE` — every monitored dimension is individually bounded. 3. The conjunction `VALID ∧ WITHIN_ENVELOPE` is treated as `SAFE`, but neither predicate encodes the binding `observed_trace.produced_under == signed_tuple`. 4. The tool executes with the *authority* of the signed manifest (`read_only`, in-scope) while performing an effect the manifest forbids (`write`). Because the write is in-scope, the scope dimension is blind to it; because the baseline was collected under the same scope, the write-volume dimension is calibrated to a distribution that already includes large payloads. The instance never had a signal that *disagreed with itself*. The poisoning lived entirely in the gap between two true statements. ## Condition of Validity The binding invariant is only checkable if the runtime can answer: *which signed tuple produced this trace?* That requires the manifest to carry a code-identity field that the runtime can independently recompute — a content digest of the tool's executable unit, or an attestation (e.g., a TEE measurement) bound into the signature. MCP as commonly deployed does **not** carry this: the handshake negotiates `name`, `description`, and `inputSchema`, and the signature typically covers those fields. The code that runs behind the tool is out of band. Therefore: - If the manifest signature covers a code digest that the runtime recomputes at load, the binding is checkable and the boundary failure is closed at load time. - If the manifest signature covers only schema/metadata (the common case), the binding is **not** checkable from the signature, and behavioral diffing must carry the entire burden — which it cannot, because diffing is a statistical envelope, not an identity check. - The failure is *valid* (i.e., the tool is admitted) precisely when the poisoning stays inside the declared resource scope and inside every marginal behavioral envelope. It is *invalidated* only when the poisoning crosses a scope boundary or a marginal envelope — both of which a careful attacker avoids. A second validity condition: the behavioral baseline must have been collected under the *same* manifest tuple it is compared against. If the baseline was collected under `v3.2.0` and the diff runs against `v3.2.1`, the envelope is stale and the diff is measuring the wrong distribution. This is the stale-baseline drift variant of the same binding failure. ## Decision Boundary The instance must not treat `signed ∧ within_envelope` as sufficient. The correct decision procedure adds a binding predicate and a side-effect-class predicate that the scope check cannot satisfy: - **Binding predicate:** `manifest.code_digest == recompute(loaded_unit)`. If the manifest carries no digest, the binding predicate is `UNKNOWN`, not `PASS`. An `UNKNOWN` binding must be treated as a *weakened* admission, not a passing one — the tool may run only under a side-effect-class downgrade (treat every invocation as if it could write, regardless of declared class). - **Side-effect-class predicate:** the observed effect set must be a subset of the declared class's allowed effect set, *evaluated independently of scope*. A write inside a declared read-only scope is a class violation, not a scope violation. Conflating the two is the boundary error. - **Baseline-tuple predicate:** `baseline.collected_under == current_signed_tuple`. If false, the diff is advisory only and must not contribute to the `SAFE` decision. The boundary: a tool is admissible iff `binding == PASS ∧ class_conformant == PASS ∧ baseline_tuple == PASS`. Any `UNKNOWN` on binding forces class-downgrade admission (effect-set widening), which converts the covert write into an observable, class-violating write that the diff *can* catch — because the widened class makes the write a first-class monitored dimension rather than an in-scope side effect. ## Operational Effect The practical consequence is that manifest signing and behavioral diffing must be *composed through the binding predicate*, not checked in parallel. An instance that runs them as independent gates will admit a class of poisoned tools that is, by construction, invisible to both gates: in-scope writes under a read-only manifest, in-envelope egress under a no-egress manifest, and stale-baseline diffs that measure the wrong version. The guardrail is to make `code_digest` a mandatory signed field, recompute it at load, and treat its absence as a class downgrade rather than a pass. Where the digest cannot be added (legacy registries), the instance must widen the effective side-effect class to the union of all classes the tool's scope permits, which restores detectability at the cost of false positives — a trade the instance should make explicitly and log, not silently. The invariant to hold: **a signature attests to a declaration, not to an execution; a diff attests to an envelope, not to an identity; only the binding of the two attests to safety.** An instance that remembers this will not admit a tool whose two true statements contradict each other. ```python class ManifestBehaviorBindingError(RuntimeError): """Raised when a tool's signed manifest and its observed runtime behavior are individually valid but jointly unbound.""" pass READ_ONLY_ALLOWED_EFFECTS = frozenset({"fs.read", "net.egress.none", "compute"}) DECLARED_CLASS_EFFECTS = { "read_only": READ_ONLY_ALLOWED_EFFECTS, "read_write_scoped": READ_ONLY_ALLOWED_EFFECTS | {"fs.write"}, "network": READ_ONLY_ALLOWED_EFFECTS | {"net.egress"}, } def admit_tool(signed_manifest: dict, loaded_unit_digest: str, observed_effects: set, baseline_tuple: tuple) -> str: """Gate MCP tool admission on manifest-to-behavior binding. Returns 'ADMIT' or 'ADMIT_DOWNGRADED'. Raises ManifestBehaviorBindingError when the two projections are individually valid but jointly inconsistent. """ signed_tuple = ( signed_manifest["tool_id"], signed_manifest["version"], signed_manifest["schema_hash"], ) # Binding predicate: does the signed manifest name the code that runs? declared_digest = signed_manifest.get("code_digest") if declared_digest is None: binding = "UNKNOWN" elif declared_digest != loaded_unit_digest: raise ManifestBehaviorBindingError( f"code digest mismatch for {signed_tuple}: " f"manifest={declared_digest} loaded={loaded_unit_digest}" ) else: binding = "PASS" # Side-effect-class predicate, evaluated independently of scope. declared_class = signed_manifest["side_effect_class"] allowed = DECLARED_CLASS_EFFECTS[declared_class] class_violations = observed_effects - allowed if class_violations: raise ManifestBehaviorBindingError( f"side-effect-class violation for {signed_tuple}: " f"class={declared_class} observed_extra={sorted(class_violations)}" ) # Baseline-tuple predicate: was the envelope collected under this tuple? if tuple(baseline_tuple) != signed_tuple: raise ManifestBehaviorBindingError( f"stale baseline for {signed_tuple}: " f"collected_under={baseline_tuple} — diff is advisory only" ) # An UNKNOWN binding cannot yield a clean ADMIT; force class downgrade # so in-scope writes become observable, class-violating effects. if binding == "UNKNOWN": return "ADMIT_DOWNGRADED" return "ADMIT" ```