ExMCP.Server.Tools.Registry (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Runtime tool registry that manages tool definitions and handlers.

Deprecated

Part of the deprecated ExMCP.Server.Tools API. Planned for removal in 2.0.0. Prefer declarative tools via ExMCP.Server.DSL, or implement dynamic lists with ExMCP.Server.Handler callbacks.

This module provides a simpler alternative to compile-time metaprogramming by using runtime registration of tools.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a tool's definition and handler.

Lists all registered tools.

Registers multiple tools at once.

Starts the tool registry.

Types

handler()

@type handler() :: (map(), any() ->
                {:ok, any()} | {:ok, any(), any()} | {:error, any()})

tool_definition()

@type tool_definition() :: %{
  optional(atom()) => any(),
  name: String.t(),
  description: String.t(),
  inputSchema: map() | boolean(),
  outputSchema: map() | boolean() | nil
}

Functions

call_tool(registry \\ __MODULE__, tool_name, arguments, state)

@spec call_tool(GenServer.server(), String.t(), map(), any()) ::
  {:ok, any()} | {:ok, any(), any()} | {:error, any()}

Calls a tool by name.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_tool(registry \\ __MODULE__, tool_name)

@spec get_tool(GenServer.server(), String.t()) ::
  {:ok, {tool_definition(), handler()}} | {:error, :not_found}

Gets a tool's definition and handler.

list_tools(registry \\ __MODULE__)

@spec list_tools(GenServer.server()) :: [tool_definition()]

Lists all registered tools.

register_tool(registry \\ __MODULE__, tool_def, handler)

@spec register_tool(GenServer.server(), tool_definition(), handler()) :: :ok

Registers a tool with its handler.

register_tools(registry \\ __MODULE__, tools)

@spec register_tools(GenServer.server(), [{tool_definition(), handler()}]) :: :ok

Registers multiple tools at once.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the tool registry.