# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-poisoned-mcp-tool-description-has-displaced-the-true-capability-contract-after-a-manifest-refresh.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-a-poisoned-mcp-tool-description-has-displaced-the-true-capability-contract-after-a-manifest-refresh.warrant.json # Markdown SHA-256: 2f6362b96c708f3756e8d907b60cc150896849e825d2ee277794c0513fda7edd # Code AST SHA-256: c707d5cc95ea02527c5ca747c63a04b512e71dd64dfee02e0ad80a937006459e # Verified Classes: DescriptionDisplacementError, ToolManifest # Defensive Guards: 7 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass, field class DescriptionDisplacementError(RuntimeError): """Raised when a refreshed tool description asserts caller obligations that the tool's input schema does not encode. Indicates either an adversarial skill-injection or a sloppy server author; both are treated identically because the planner cannot distinguish them.""" @dataclass class ToolManifest: name: str description: str input_schema: dict # property name -> {"required": bool, ...} side_effects: list[str] = field(default_factory=list) # Structural signals, checked in order of severity. OBLIGATION_MARKERS = ( "must", "requires", "required to", "first transmit", "before calling", "include verbatim", "verbatim", "pass the full", "send the active", ) DATAFLOW_TARGETS = ( "session token", "session_token", "instruction", "system prompt", "prior message", "conversation", "context", "api key", "credential", ) def _required_props(schema: dict) -> set[str]: return {k for k, v in schema.items() if v.get("required")} def _clauses(description: str) -> list[str]: # Split on sentence and semicolon boundaries; keep it dumb and auditable. out = [] for chunk in description.replace(";", ".").split("."): c = chunk.strip() if c: out.append(c) return out def validate_refreshed_description( cached: ToolManifest, fresh: ToolManifest, inflation_ratio: float = 1.5, ) -> None: """Reconcile a refreshed manifest against the cached one. Raises DescriptionDisplacementError on the first hard signal. Returns None if the refresh is safe to adopt. """ if fresh.name != cached.name: raise DescriptionDisplacementError( f"manifest name changed {cached.name!r} -> {fresh.name!r}; " "identity swap, not a refresh" ) required = _required_props(fresh.input_schema) clauses = _clauses(fresh.description) for clause in clauses: low = clause.lower() # Signal 1: caller obligation naming a datum the schema does not require. if any(m in low for m in OBLIGATION_MARKERS): named = [t for t in DATAFLOW_TARGETS if t in low] # If the obligation references context-window data, it is hard-fail # regardless of schema, because no schema should carry that field. if named: raise DescriptionDisplacementError( f"tool {fresh.name!r} description obligates caller to " f"transmit context-window datum(s) {named} via argument; " f"schema required props = {sorted(required)}" ) # Otherwise require that *some* required prop exists to justify # an obligation clause; obligation with empty schema is suspicious. if not required: raise DescriptionDisplacementError( f"tool {fresh.name!r} description asserts obligation " f"(clause={clause!r}) but input_schema declares no " "required properties" ) # Signal 4: explicit data-flow directive from context into argument. if any(t in low for t in DATAFLOW_TARGETS) and any( v in low for v in ("include", "pass", "send", "transmit", "embed") ): raise DescriptionDisplacementError( f"tool {fresh.name!r} description directs context data into " f"argument (clause={clause!r})" ) # Signal 2: prefix-preserved with appended clauses. if ( fresh.description.startswith(cached.description) and len(fresh.description) > len(cached.description) ): appended = fresh.description[len(cached.description):].strip() if appended: raise DescriptionDisplacementError( f"tool {fresh.name!r} description preserves cached prefix " f"byte-for-byte and appends {appended[:80]!r}; " "prefix-preservation signature" ) # Signal 3: length inflation with unchanged schema and side effects. if ( fresh.input_schema == cached.input_schema and fresh.side_effects == cached.side_effects and len(fresh.description) > inflation_ratio * max(len(cached.description), 1) ): raise DescriptionDisplacementError( f"tool {fresh.name!r} description inflated " f"{len(cached.description)}->{len(fresh.description)} chars " "with identical schema and side effects" ) # Signal 5: echo-inducing phrasing (corroborating; hard-fail only if # combined with a dataflow target already caught above, so here we # only fail when verbatim is present without any legitimate field). if "verbatim" in fresh.description.lower() and not required: raise DescriptionDisplacementError( f"tool {fresh.name!r} requests verbatim inclusion with no " "required argument to carry it" )