ExMCP.Server.Tools.Builder (ex_mcp v0.10.0)
View SourceSimplified tool builder that reduces metaprogramming complexity.
Instead of heavy AST manipulation, this module uses a cleaner builder pattern with explicit data structures and runtime registration.
Summary
Functions
Sets annotations for the tool.
Builds the final tool definition.
Sets the tool's description.
Sets the handler function.
Sets the input schema explicitly.
Creates a new tool builder.
Sets the output schema for validation.
Adds a parameter to the tool.
Sets the tool's title (optional).
Functions
@spec annotations(ExMCP.Server.Tools.Builder.Tool.t(), map() | any()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets annotations for the tool.
@spec build(ExMCP.Server.Tools.Builder.Tool.t()) :: {:ok, map()} | {:error, String.t()}
Builds the final tool definition.
Generates input schema from params if not explicitly set.
@spec description(ExMCP.Server.Tools.Builder.Tool.t(), String.t()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets the tool's description.
@spec handler(ExMCP.Server.Tools.Builder.Tool.t(), function()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets the handler function.
@spec input_schema(ExMCP.Server.Tools.Builder.Tool.t(), map() | any()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets the input schema explicitly.
@spec new(String.t()) :: ExMCP.Server.Tools.Builder.Tool.t()
Creates a new tool builder.
Example
ExMCP.Server.Tools.Builder.new("echo")
|> description("Echo back the input")
|> param(:message, :string, required: true)
|> handler(fn %{message: msg}, state -> {:ok, %{text: msg}, state} end)
|> build()
@spec output_schema(ExMCP.Server.Tools.Builder.Tool.t(), map() | any()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets the output schema for validation.
@spec param( ExMCP.Server.Tools.Builder.Tool.t(), atom(), atom() | {atom(), any()}, keyword() ) :: ExMCP.Server.Tools.Builder.Tool.t()
Adds a parameter to the tool.
@spec title(ExMCP.Server.Tools.Builder.Tool.t(), String.t()) :: ExMCP.Server.Tools.Builder.Tool.t()
Sets the tool's title (optional).