Skip to content
docsv0.2.0

ToolRegistry

Enhanced Tool Registry with security, validation, and observability. Pipeline: resolve → validate → authorize → execute → audit Features: - Token estimation for LLM context management - Tool filtering by category and scopes - Budget-aware tool selection

ToolRegistry::__construct()

public function __construct(Psr\Log\LoggerInterface $logger):

Parameters

Parameters of __construct()
NameTypeDescription
$loggerPsr\Log\LoggerInterface

ToolRegistry::register()

public function register(string $name, string $description, array $inputSchema, callable $callback, ?Milpa\ValueObjects\Tooling\ToolOptions $options = null): void

Register a tool.

Parameters

Parameters of register()
NameTypeDescription
$namestring
$descriptionstring
$inputSchemaarray
$callbackcallable
$options?Milpa\ValueObjects\Tooling\ToolOptions

Throws

ToolAlreadyRegisteredException if tool name already exists

ToolRegistry::getToolSummaries()

public function getToolSummaries(): array

Get all tools as plain-array summaries, for LLM/MCP exposure. This is the wire shape: a JSON-serializable summary per tool (no callback, no internal state) — exactly what an MCP `tools/list` response or a token-budget report needs. It is NOT the internal {@see ToolDefinition} object; use {@see getToolDefinitions()} when you need the typed VO (e.g. its `->callback` or `->mutating`). Renamed from `getTools()` in tool-runtime 0.2 — the old name was easy to confuse with a `list<ToolDefinition>` getter (which `ToolDefinition` existing internally invited), and a caller assuming `->name` on these entries got a silent `null` instead of a type error.

ToolRegistry::getToolDefinitions()

public function getToolDefinitions(): array

Get all registered tools as their typed {@see ToolDefinition} value objects. Unlike {@see getToolSummaries()}, this exposes the full internal VO — including `->callback` and `->mutating` — for consumers that need more than the LLM/MCP wire shape (e.g. building an alternate registry, introspecting tool metadata). Registration order is preserved.

ToolRegistry::getToolsByScopes()

public function getToolsByScopes(array $scopes): array

Get tools filtered by scopes.

Parameters

Parameters of getToolsByScopes()
NameTypeDescription
$scopesarray<string>Required scopes

ToolRegistry::getToolsByPrefix()

public function getToolsByPrefix(string $prefix): array

Get tools filtered by name prefix (category).

Parameters

Parameters of getToolsByPrefix()
NameTypeDescription
$prefixstringTool name prefix (e.g., "list_", "admin_")

ToolRegistry::getToolsWithinBudget()

public function getToolsWithinBudget(string $model, ?array $priorityTools = null): array

Get tools that fit within token budget for a model.

Parameters

Parameters of getToolsWithinBudget()
NameTypeDescription
$modelstringModel identifier (e.g., "gpt-4", "claude-3-sonnet")
$priorityTools(array<string> | null)Tools to include first (by name)

ToolRegistry::getTokenUsageReport()

public function getTokenUsageReport(string $model = 'gpt-4'): string

Get token usage report for current tools.

Parameters

Parameters of getTokenUsageReport()
NameTypeDescription
$modelstring

ToolRegistry::estimateTokens()

public function estimateTokens(): array

Estimate tokens for current tools.

ToolRegistry::checkTokenBudget()

public function checkTokenBudget(string $model): array

Check if tools fit within budget for a model.

Parameters

Parameters of checkTokenBudget()
NameTypeDescription
$modelstring

ToolRegistry::getTokenEstimator()

public function getTokenEstimator(): Milpa\ToolRuntime\TokenEstimator

Get the token estimator for direct use.

ToolRegistry::call()

public function call(string $name, array $args, ?Milpa\ToolRuntime\Contracts\ToolContext $ctx = null): Milpa\ToolRuntime\ToolResult

Call a tool with full pipeline.

Parameters

Parameters of call()
NameTypeDescription
$namestringTool name
$argsarray<string, mixed>Arguments
$ctx(ToolContext | null)Execution context (defaults to CLI)

ToolRegistry::has()

public function has(string $name): bool

Check if a tool exists.

Parameters

Parameters of has()
NameTypeDescription
$namestring

ToolRegistry::getDefinition()

public function getDefinition(string $name): ?Milpa\ToolRuntime\ToolDefinition

Get tool definition.

Parameters

Parameters of getDefinition()
NameTypeDescription
$namestring

ToolRegistry::getPolicyGate()

public function getPolicyGate(): Milpa\ToolRuntime\PolicyGate

Get policy gate for customization.

ToolRegistry::getConfirmationStore()

public function getConfirmationStore(): Milpa\ToolRuntime\ConfirmationTokenStore

Get confirmation store for customization.

ToolRegistry::setRateLimiter()

public function setRateLimiter(Milpa\ToolRuntime\RateLimiting\RateLimiterInterface $limiter): void

Set the rate limiter for tool call throttling.

Parameters

Parameters of setRateLimiter()
NameTypeDescription
$limiterMilpa\ToolRuntime\RateLimiting\RateLimiterInterface

ToolRegistry::getRateLimiter()

public function getRateLimiter(): ?Milpa\ToolRuntime\RateLimiting\RateLimiterInterface

Get the rate limiter if configured.