ToolRegistry class

Full-featured tool registry.

Manages tool registration/unregistration, lookup, execution with pre/post hooks, enable/disable, restrict, stats tracking, schema access, and fuzzy name matching.

Constructors

ToolRegistry()

Properties

all Iterable<Tool>
All registered tools.
no setter
allRegistrations Iterable<ToolRegistration>
Get all registrations.
no setter
available Iterable<Tool>
All currently executable tools.
no setter
definitions List<ToolDefinition>
Tool definitions for API calls (only executable tools).
no setter
hashCode int
The hash code for this object.
no setterinherited
names Iterable<String>
All registered tool names.
no setter
onToolExecuted Stream<ToolExecutionEvent>
Stream of tool execution events.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addPostHook(void hook(ToolExecutionEvent event)) → void
Add a post-execution hook.
addPreHook(Future<bool> hook(String name, Map<String, dynamic> input)) → void
Add a pre-execution hook. Return false from the hook to block execution.
clear() → void
Remove all registered tools.
disable(String name) → void
Disable a tool.
dispose() → void
Dispose of internal resources.
enable(String name) → void
Enable a tool.
execute(String name, Map<String, dynamic> input) Future<ToolResult>
Execute a tool by name, running pre/post hooks and tracking stats.
findSimilar(String query) List<ToolRegistration>
Find tools whose names are similar to query (case-insensitive prefix and substring matching).
get(String name) Tool?
Get a tool by name.
getAllSchemas() Map<String, Map<String, dynamic>>
Get all tool schemas keyed by name.
getAllStats() List<ToolStats>
Get stats for all tools.
getByCategory(ToolCategory category) List<ToolRegistration>
Get tools in a specific category.
getRegistration(String name) ToolRegistration?
Get a tool registration by name.
getSchema(String name) Map<String, dynamic>?
Get the input schema for a specific tool.
getStats(String name) ToolStats?
Get stats for a specific tool.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(Tool tool, {ToolCategory category = ToolCategory.custom}) → void
Register a tool with a category.
registerBuiltinTools({Tool? bashTool, Tool? fileReadTool, Tool? fileWriteTool, Tool? fileEditTool, Tool? globTool, Tool? grepTool, Tool? agentTool, Tool? sendMessageTool, Tool? todoWriteTool, Tool? taskOutputTool, Tool? toolSearchTool, Tool? webFetchTool, Tool? webSearchTool, Tool? notebookEditTool, Tool? skillTool, Tool? enterPlanModeTool, Tool? exitPlanModeTool, Tool? powerShellTool}) → void
Register all 18+ built-in tools.
registerMcpTools(List<Tool> mcpTools) → void
Register tools from an MCP server.
restrict(String name) → void
Restrict a tool (e.g. during plan mode).
restrictAllExcept(Set<String> allowed) → void
Restrict all tools except those in allowed.
toString() String
A string representation of this object.
inherited
unregister(String name) → void
Unregister a tool by name.
unrestrict(String name) → void
Unrestrict a tool.
unrestrictAll() → void
Unrestrict all tools.
validateInput(String name, Map<String, dynamic> input) ValidationResult
Validate input for a named tool against its schema.

Operators

operator ==(Object other) bool
The equality operator.
inherited