ToolRegistry
Thread-safe collection of registered McpTools, keyed by McpTool.name. Backed by a ConcurrentHashMap so tools can be registered and invoked concurrently. Also tracks a host-controlled runtime gate (see setDisabledTools) that hides/blocks tools without unregistering them.
This is the single source of truth the transports and McpProtocol read from for tools/list and tools/call. Every change to the client-visible set (register, unregister, gate edits) is reported to addChangeListener subscribers; the HTTP transport turns that into notifications/tools/list_changed.
Constructors
Properties
Upper bound on a single executeTool call; a tool still running after this is cancelled and reported as a tool_timeout error. Must be positive. The same bound applies to waiting for confirmer.
Functions
Call listener whenever the client-visible tool set may have changed.
Names currently gated off.
Execute the named tool with params on Dispatchers.IO, bounded by toolTimeoutMs. Returns a tool_disabled error if the tool is gated off, an Unknown tool error if it isn't registered, a tool_timeout error if it overran, and converts any exception thrown by McpTool.execute into a failed ToolResult. Coroutine cancellation of the caller is rethrown rather than swallowed, so a cancelled request stops its tool.
Tools currently visible to clients — registered and not gated off.
All registered tools, regardless of gate state. See listEnabledTools for the client-visible set.
Register tool, replacing any existing tool with the same McpTool.name.
Register every tool in toolList (e.g. the output of a module provider's all(context)), notifying listeners once.
Replace the entire disabled set in one atomic swap (e.g. from a checkbox grid). @Synchronized on the same monitor as setToolEnabled so a full replace can't interleave with a single-tool toggle and lose its update.
Enable or disable a single tool by name. @Synchronized so concurrent single-tool toggles don't lose updates in the copy-on-write swap.
Remove the named tool (e.g. after the user revokes the permission it needs).