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.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Names currently gated off.

Link copied to clipboard
suspend fun executeTool(name: String, params: Map<String, Any>): ToolResult

Execute the named tool with params. Returns a tool_disabled error if the tool is gated off, an Unknown tool error if it isn't registered, and converts any exception thrown by McpTool.execute into a failed ToolResult — this method never throws.

Link copied to clipboard
fun getTool(name: String): McpTool?

The registered tool with this name, or null if none is registered.

Link copied to clipboard

Whether the named tool is currently enabled (registered tools are enabled by default).

Link copied to clipboard

Tools currently visible to clients — registered and not gated off.

Link copied to clipboard

All registered tools, regardless of gate state. See listEnabledTools for the client-visible set.

Link copied to clipboard
fun register(tool: McpTool)

Register tool, replacing any existing tool with the same McpTool.name.

Link copied to clipboard
fun registerAll(toolList: List<McpTool>)

Register every tool in toolList (e.g. the output of a module provider's all(context)).

Link copied to clipboard

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.

Link copied to clipboard

Enable or disable a single tool by name. @Synchronized so concurrent single-tool toggles don't lose updates in the copy-on-write swap.