Skip to content

API Reference parrot.tools.tooling_policy

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.tooling_policy

View source

Host-owned tenant tooling policy (FEAT-622 M7, review R1). Pure and synchronous: no I/O.

Alias AgentMCPServerSpec

Re-exported from parrot.tools.spec.AgentMCPServerSpec.

Class HostMCPServer

An MCP server registered by the host; tenants may reference it by name only.

Fields:

Field Type Default Description
name str
config dict[str, Any]
tenant_fields frozenset[str] frozenset({'allowed_tools', 'blocked_tools', 'description'})

Alias NormalizedTooling

Re-exported from parrot.tools.spec.NormalizedTooling.

Alias SECRET_MASK

Re-exported from parrot.tools.spec.SECRET_MASK.

Attribute TenantMCPTransport

Class TenantToolingPolicy

Frozen host policy; the default is :meth:deny_all.

Fields:

Field Type Default Description
mcp_servers Mapping[str, HostMCPServer] {}
mcp_endpoints tuple[str, ...] ()
mcp_transports frozenset[TenantMCPTransport] frozenset({'http', 'sse', 'streamable-http'})
builtin_tools frozenset[str] frozenset()
host_toolkits bool True
apply_to_global bool False
tenant_toolkits Callable[[str], Collection[str] | None] | None None Host callback: enabled host-toolkit slugs for a tenant, None = unrestricted. Sync, no I/O.
tenant_builtin_tools Callable[[str], Collection[str] | None] | None None PA-5: like tenant_toolkits but for BUILT-IN slugs (those also in builtin_tools): the per-tenant allow-list narrows the global builtin_tools set. None = no per-tenant narrowing. Same semantics: fail closed when it errors, held stored tooling still builds (refused at call time), phase build and the tenant-less global partition are never refused.

Method TenantToolingPolicy.deny_all

Host toolkits only, no MCP, no built-ins.

deny_all() -> 'TenantToolingPolicy'

Returns: 'TenantToolingPolicy'

Method TenantToolingPolicy.check_tool

Refuse a slug that is unknown, or a non-host tool outside builtin_tools.

check_tool(slug: str, *, subject: ToolingSubject) -> None

Parameter Type Default Description
slug str
subject ToolingSubject

Method TenantToolingPolicy.pinned_for

This policy with the tenant's allow-lists (host toolkits AND built-ins) resolved ONCE: each callback runs (and logs a failure) once per request, however many slugs are then checked. Returns self when no allow-list applies.

pinned_for(subject: ToolingSubject) -> 'TenantToolingPolicy'

Parameter Type Default Description
subject ToolingSubject

Returns: 'TenantToolingPolicy'

Method TenantToolingPolicy.enabled_toolkits

Lower-cased enabled host-toolkit slugs for tenant; None = unrestricted.

Anything the callback returns that is not None, a str (one slug, never a substring pool) or an iterable of names — a coroutine, a bool, an int — and any exception it raises, fails CLOSED (empty set).

enabled_toolkits(tenant: str) -> frozenset[str] | None

Parameter Type Default Description
tenant str

Returns: frozenset[str] | None

Method TenantToolingPolicy.enabled_builtin_tools

Lower-cased built-in slugs tenant may use (PA-5); None = no per-tenant narrowing. Fails closed.

enabled_builtin_tools(tenant: str) -> frozenset[str] | None

Parameter Type Default Description
tenant str

Returns: frozenset[str] | None

Method TenantToolingPolicy.resolve_mcp

Spec §2 checks 1–4 on the FINAL kwargs; returns MCPServerConfig kwargs.

resolve_mcp(config: Mapping[str, Any], *, subject: ToolingSubject) -> dict[str, Any]

Parameter Type Default Description
config Mapping[str, Any]
subject ToolingSubject

Returns: dict[str, Any]

Method TenantToolingPolicy.check_tooling

Check every tool, toolkit and MCP spec of tooling (and secret references by phase).

check_tooling(tooling: NormalizedTooling, *, subject: ToolingSubject, owner: str | None = None) -> None

Parameter Type Default Description
tooling NormalizedTooling
subject ToolingSubject
owner str | None None

Method TenantToolingPolicy.precheck_toolkit

Slug check plus phase-dependent secret-reference check of one toolkit spec (no vault access).

precheck_toolkit(spec: Any, *, subject: ToolingSubject, owner: str | None = None) -> None

Parameter Type Default Description
spec Any
subject ToolingSubject
owner str | None None

Method TenantToolingPolicy.precheck_mcp

Effective-config check plus secret-reference check of one MCP spec (no vault access).

precheck_mcp(spec: AgentMCPServerSpec, *, subject: ToolingSubject, owner: str | None = None) -> None

Parameter Type Default Description
spec AgentMCPServerSpec
subject ToolingSubject
owner str | None None

Class TenantToolingRefused

Raised when tenant tooling is not permitted (HTTP 422 on writes/assign, 403 on execute).

Parameter Type Default Description
reason ToolingRefusal
item str

Attributes:

Attribute Type Description
code str
reason ToolingRefusal

Class ToolParamRefused

A host toolkit-parameter hook refuses constructor parameters (PA-9): 422 tooling_not_permitted, reason tool_params_not_permitted and details.params; a stored agent that carries them fails its build closed.

Parameter Type Default Description
params Iterable[str] ()
item str ''

Attributes:

Attribute Type Description
params list[str]

Attribute ToolingRefusal

Class ToolingSubject

Who/what/when a tooling check applies to.

Fields:

Field Type Default Description
tenant str | None
agent_id UUID | None
actor str | None
phase Literal['write', 'activate', 'build', 'attach', 'execute']
held frozenset[str] frozenset() Lower-cased slugs the write leaves untouched: exempt from the per-tenant allow-lists only (delta check).

Function detect_transport

Mirror MCPClient._detect_transport as a pure function (None = undetectable).

detect_transport(config: Mapping[str, Any]) -> str | None

Parameter Type Default Description
config Mapping[str, Any]

Returns: str | None

Function effective_mcp_config

Exactly what hydrate_mcp returns, minus the vault read (secret fields → SECRET_MASK).

effective_mcp_config(spec: AgentMCPServerSpec) -> dict[str, Any]

Parameter Type Default Description
spec AgentMCPServerSpec

Returns: dict[str, Any]

Function enforce_tenant_tooling

THE write/activation hook: raises TenantToolingRefused; pure, no I/O.

enforce_tenant_tooling(app: Mapping[str, Any], tooling: NormalizedTooling, *, subject: ToolingSubject) -> None

Parameter Type Default Description
app Mapping[str, Any]
tooling NormalizedTooling
subject ToolingSubject

Function get_tenant_tooling_policy

Registered policy, or deny_all() when the host registered nothing.

get_tenant_tooling_policy(app: Mapping[str, Any]) -> TenantToolingPolicy

Parameter Type Default Description
app Mapping[str, Any]

Returns: TenantToolingPolicy

Alias get_toolkit_resolver

Re-exported from parrot.tools.resolver.get_toolkit_resolver.

Attribute logger

Alias mcp_vault_name

Re-exported from parrot.tools.spec.mcp_vault_name.

Function set_tenant_tooling_policy

Register the host policy once, before startup completes.

set_tenant_tooling_policy(app: MutableMapping[str, Any], policy: TenantToolingPolicy) -> None

Parameter Type Default Description
app MutableMapping[str, Any]
policy TenantToolingPolicy

Alias toolkit_vault_name

Re-exported from parrot.tools.spec.toolkit_vault_name.

Function unchanged_slugs

Lower-cased slugs of after that a write leaves exactly as in before (tools and toolkit specs).

unchanged_slugs(before: NormalizedTooling, after: NormalizedTooling) -> frozenset[str]

Parameter Type Default Description
before NormalizedTooling
after NormalizedTooling

Returns: frozenset[str]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally