ExMCP.Server.Tools.Simplified (ex_mcp v0.10.0)
View SourceSimplified tool definition DSL that reduces metaprogramming complexity.
This module provides a cleaner API that avoids heavy AST manipulation while maintaining a similar developer experience to the original DSL.
Example Usage
defmodule MyServer do
use ExMCP.Server.Handler
use ExMCP.Server.Tools.Simplified
deftool "echo", "Echo back the input" do
param :message, :string, required: true
param :uppercase, :boolean, default: false
run fn %{message: msg, uppercase: up}, state ->
result = if up, do: String.upcase(msg), else: msg
{:ok, %{text: result}, state}
end
end
deftool "calculator" do
description "Perform basic calculations"
input_schema %{
type: "object",
properties: %{
operation: %{type: "string", enum: ["add", "subtract", "multiply", "divide"]},
a: %{type: "number"},
b: %{type: "number"}
},
required: ["operation", "a", "b"]
}
output_schema %{
type: "object",
properties: %{
result: %{type: "number"}
}
}
run &Calculator.execute/2
end
end
Summary
Functions
Define a tool with a cleaner syntax.
Instead of heavy metaprogramming, this builds a tool at compile time and registers it at runtime.