Excessibility.MCP.Tool behaviour (Excessibility v0.14.0)

View Source

Behaviour for MCP tools.

Tools are executable actions that can be called via the MCP protocol.

Example

defmodule MyApp.MCP.Tools.MyTool do
  @behaviour Excessibility.MCP.Tool

  @impl true
  def name, do: "my_tool"

  @impl true
  def description, do: "Does something useful"

  @impl true
  def input_schema do
    %{
      "type" => "object",
      "properties" => %{
        "arg1" => %{"type" => "string", "description" => "First argument"}
      },
      "required" => ["arg1"]
    }
  end

  @impl true
  def execute(args, _opts) do
    {:ok, %{"result" => args["arg1"]}}
  end
end

Callbacks

  • name/0 - Returns string identifier for this tool
  • description/0 - Human-readable description of what the tool does
  • input_schema/0 - JSON Schema for the tool's input arguments
  • execute/2 - Takes args map and opts keyword list, returns result

Options

The opts keyword list may contain:

  • :progress_callback - Function to call with progress updates
  • :elicit - A 2-arity function fn message, schema -> result for structured user interaction via the MCP elicitation protocol. Only present when the client supports elicitation. See Excessibility.MCP.Elicitation for details.

Summary

Functions

Formats a successful tool result for MCP response.

Returns the MCP tool definition for a tool module.

Callbacks

description()

@callback description() :: String.t()

execute(args, opts)

@callback execute(args :: map(), opts :: keyword()) :: {:ok, map()} | {:error, String.t()}

input_schema()

@callback input_schema() :: map()

name()

@callback name() :: String.t()

Functions

format_result(arg)

Formats a successful tool result for MCP response.

to_mcp_definition(tool_module)

Returns the MCP tool definition for a tool module.