Module

tools.registry

Tool registry — compiled tool table with dispatch.

Mirrors theRouter + Route pattern from chirp.routing: ToolDef is the frozen definition (like Route), ToolRegistry is the compiled lookup table (likeRouter).

Free-threading safety:

  • ToolDef is a frozen dataclass (immutable)
  • ToolRegistry._tools is a dict built at freeze time, never mutated
  • ToolEventBus handles its own synchronization

Classes

ToolDef 4
A frozen tool definition. Created during app setup, compiled into the registry at freeze time.

A frozen tool definition.

Created during app setup, compiled into the registry at freeze time.

Attributes

Name Type Description
name str
description str
handler Callable[..., Any]
schema dict[str, Any]
ToolRegistry 6
Compiled tool table. Created at freeze time, immutable at runtime. Provides ``list_tools()`` for M…

Compiled tool table. Created at freeze time, immutable at runtime.

Provideslist_tools() for MCP tools/list and call_tool() for MCPtools/calldispatch.

Methods

list_tools 0 list[dict[str, Any]]
Return MCP-formatted tool list for ``tools/list`` response.
def list_tools(self) -> list[dict[str, Any]]
Returns
list[dict[str, Any]]
call_tool 2 Any
Dispatch a tool call by name. Calls the handler with the provided arguments, e…
async
async def call_tool(self, name: str, arguments: dict[str, Any]) -> Any

Dispatch a tool call by name.

Calls the handler with the provided arguments, emits a ToolCallEventon success, and returns the result.

RaisesKeyErrorif the tool name is not registered.

Parameters
Name Type Description
name
arguments
Returns
Any
get 1 ToolDef | None
Look up a tool by name. Returns ``None`` if not found.
def get(self, name: str) -> ToolDef | None
Parameters
Name Type Description
name
Returns
ToolDef | None
Internal Methods 3
__init__ 2
def __init__(self, tools: list[ToolDef], event_bus: ToolEventBus) -> None
Parameters
Name Type Description
tools
event_bus
__len__ 0 int
def __len__(self) -> int
Returns
int
__contains__ 1 bool
def __contains__(self, name: str) -> bool
Parameters
Name Type Description
name
Returns
bool

Functions

compile_tools 2 ToolRegistry
Compile pending tool registrations into a frozen ToolRegistry. Called during `…
def compile_tools(pending: list[tuple[str, str, Callable[..., Any]]], event_bus: ToolEventBus) -> ToolRegistry

Compile pending tool registrations into a frozen ToolRegistry.

Called duringApp._freeze(). Each tuple is (name, description, handler). Schema generation happens here so errors surface at startup, not at runtime.

Parameters
Name Type Description
pending list[tuple[str, str, Callable[..., Any]]]
event_bus ToolEventBus
Returns
ToolRegistry