Behaviour and schema DSL for MCP tool modules.
A tool module declares its JSON-schema-like input contract with schema/1
and implements execute/2 to return an MCPKit.Response.
Example:
defmodule MyApp.MCP.Tools.Ping do
use MCPKit.Tool
alias MCPKit.Response
schema do
field :message, :string, required: true
end
def execute(arguments, context) do
{:reply, Response.tool() |> Response.structured(arguments), context}
end
endSupported schema nodes today:
field/2field/3embeds_many/2embeds_many/3
Summary
Callbacks
Returns the description shown in tools/list.
Executes the tool and returns an MCPKit.Response.
Returns the JSON-schema-like MCP input schema generated from schema/1.
Validates and normalizes incoming tool arguments.
Functions
Declares the MCP input schema for a tool.
Callbacks
@callback description() :: String.t() | nil
Returns the description shown in tools/list.
@callback execute(map(), map()) :: {:reply, MCPKit.Response.t(), map()}
Executes the tool and returns an MCPKit.Response.
The context map currently includes at least :session.
@callback input_schema() :: map()
Returns the JSON-schema-like MCP input schema generated from schema/1.
Validates and normalizes incoming tool arguments.
This callback is generated by schema/1 unless overridden.