DSL for defining MCP tools in server handlers.
Deprecated
ExMCP.Server.Tools is deprecated, retained throughout 1.x, and planned for
removal in 2.0.0.
Use ExMCP.Server.Handler with ExMCP.Server.DSL instead (tools, resources,
and prompts in one API). See the project DSL guide for migration examples.
use ExMCP.Server.Tools emits a compile-time warning.
This module provides a declarative way to define tools with automatic
schema generation and validation. Prefer ExMCP.Server.DSL for new code.
Migration
# Deprecated
use ExMCP.Server.Handler
use ExMCP.Server.Tools
tool "echo", "Echo back the input" do
param :message, :string, required: true
handle fn %{message: message}, _state ->
{:ok, text: message}
end
end
# Preferred
use ExMCP.Server.Handler
use ExMCP.Server.DSL, name: "my-server", version: "1.0.0"
tool "echo", "Echo back the input" do
param :message, :string, required: true
run fn %{message: message}, state ->
{:ok, message, state}
end
end
Summary
Functions
Set annotations for a tool.
Set the description for a tool.
Define the handler function for a tool.
Set the input schema for a tool.
Set the output schema for a tool.
Define a parameter for a tool.
Set the title for a tool (2025-06-18 feature).
Define a tool using the DSL.
Functions
Set annotations for a tool.
Set the description for a tool.
Define the handler function for a tool.
The handler receives the arguments and state, and should return {:ok, response} or {:ok, response, new_state}.
Set the input schema for a tool.
Set the output schema for a tool.
Define a parameter for a tool.
This macro is used within a tool definition to specify parameters.
Examples
param :name, :string, required: true
param :age, :integer, default: 0
param :tags, {:array, :string}
Set the title for a tool (2025-06-18 feature).
Define a tool using the DSL.
Examples
tool "echo", "Echo back the input" do
param :message, :string, required: true
handle fn %{message: message}, _state ->
{:ok, text: message}
end
end