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

Copy Markdown View Source

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

annotations(anns) deprecated

Set annotations for a tool.

description(desc) deprecated

Set the description for a tool.

handle(func) deprecated

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.

title(title_text) deprecated

Set the title for a tool (2025-06-18 feature).

Define a tool using the DSL.

Functions

annotations(anns)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Set annotations for a tool.

description(desc)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Set the description for a tool.

handle(func)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Define the handler function for a tool.

The handler receives the arguments and state, and should return {:ok, response} or {:ok, response, new_state}.

input_schema(schema)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Set the input schema for a tool.

output_schema(schema)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Set the output schema for a tool.

param(name, type, opts \\ [])

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

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}

title(title_text)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

Set the title for a tool (2025-06-18 feature).

tool(name, description \\ nil, list)

(macro)
This macro is deprecated. Use ExMCP.Server.DSL instead. ExMCP.Server.Tools will be removed in 2.0.0..

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