# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-reject-a-dynamically-loaded-mcp-tool-whose-manifest-declares-a-capability-the-runtime-did-not-negotiate.md # Remnant Warrant: https://corpusfetch.com/c/when-must-an-instance-reject-a-dynamically-loaded-mcp-tool-whose-manifest-declares-a-capability-the-runtime-did-not-negotiate.warrant.json # Markdown SHA-256: 306acfcee73f668fa74d396d7ffc38c82a7b73e2202efce9dae3b0bc07fe910f # Code AST SHA-256: 99a5f779222c9e2ba0bd06e38a7f5c2019fe6df8a8e251efb47c26b2f170a051 # Verified Classes: CapabilityWarrantViolation # Defensive Guards: 3 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) class CapabilityWarrantViolation(RuntimeError): """Raised when a dynamically loaded tool's manifest exceeds the session warrant.""" pass KNOWN_MANIFEST_KEYS = frozenset({ "name", "version", "description", "inputSchema", "capabilities", "requiresScopes", "tools", }) def load_dynamic_tool(manifest: dict, session_warrant: frozenset[str], sandbox_enforces_warrant: bool) -> dict: """Load a dynamically discovered MCP tool only if it fits the negotiated warrant. Rejects on: unknown manifest keys, declared scopes outside the warrant, or any side-effecting declaration when the sandbox cannot enforce the warrant. """ unknown = set(manifest) - KNOWN_MANIFEST_KEYS if unknown: raise CapabilityWarrantViolation( f"manifest {manifest.get('name')!r} contains unrecognized keys " f"{sorted(unknown)}; refusing to load (dialect mismatch is an " f"injection surface)" ) declared = set(manifest.get("capabilities", [])) required = set(manifest.get("requiresScopes", [])) # Absence of requiresScopes is not a grant; it is an absence of information. # Treat every declared capability as a requirement in that case. effective_requirement = required if required else declared overreach = effective_requirement - session_warrant if overreach: raise CapabilityWarrantViolation( f"tool {manifest.get('name')!r} requires {sorted(overreach)} " f"not present in session warrant {sorted(session_warrant)}; " f"re-negotiation with caller required" ) # A manifest that declares side effects cannot be trusted to self-limit. # If the sandbox does not enforce the warrant below the model, the # description-injection vector is open and the tool must not load. side_effecting = any( not t.get("annotations", {}).get("readOnlyHint", False) for t in manifest.get("tools", []) ) if side_effecting and not sandbox_enforces_warrant: raise CapabilityWarrantViolation( f"tool {manifest.get('name')!r} declares side-effecting operations " f"but no sandbox enforces the warrant; manifest self-description " f"is attacker-controlled and cannot be the boundary" ) return { "name": manifest["name"], "effective_capabilities": declared & session_warrant, "enforced_by": "sandbox" if sandbox_enforces_warrant else "none", }