Provides the deftool macro for declaring MCP tools alongside their handlers.
Summary
Functions
Defines a tool with its schema and handler in one place.
Formats Ecto changeset errors into a human-readable error tuple.
Functions
Defines a tool with its schema and handler in one place.
Example
deftool "get_page", "Get a page by ID",
params: [id: {:string!, "Page ID"}] do
page = CMS.get_page!(params["id"])
{:ok, Map.take(page, [:id, :title, :slug])}
endInside the do block, params and session are bound.
Annotations
Pass annotations to provide hints about the tool's behavior to MCP clients:
deftool "delete_item", "Delete an item",
params: [id: {:string!, "Item ID"}],
annotations: %{readOnlyHint: false, destructiveHint: true, idempotentHint: true} do
Items.delete!(params["id"])
{:ok, %{deleted: true}}
endSupported keys: readOnlyHint, destructiveHint, idempotentHint, openWorldHint, title.
Formats Ecto changeset errors into a human-readable error tuple.