ExMCP.Server.Tools.Builder (ex_mcp v0.9.2)

View Source

Simplified 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

annotations(tool, anns)

Sets annotations for the tool.

build(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.

description(tool, desc)

Sets the tool's description.

handler(tool, handler_fn)

Sets the handler function.

input_schema(tool, schema)

Sets the input schema explicitly.

new(name)

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()

output_schema(tool, schema)

Sets the output schema for validation.

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

Adds a parameter to the tool.

title(tool, title)

Sets the tool's title (optional).