ExMCP.DSL.Tool (ex_mcp v0.9.2)

View Source

Simplified DSL for defining MCP tools.

Provides the deftool macro for defining tools with metadata and JSON Schema.

Summary

Functions

Validates a tool definition at compile time.

Converts atom keys to string keys recursively in a data structure.

Defines a tool with its schema and metadata.

Sets task execution support for the current tool (new in 2025-11-25).

Sets icons for the current tool (new in 2025-11-25).

Sets a raw JSON Schema for the tool input.

Sets annotations for the current tool.

Functions

__validate_tool_definition__(name, meta, input_schema)

Validates a tool definition at compile time.

This function is called during the deftool macro expansion to ensure the tool definition is complete and valid.

convert_schema_keys_to_strings(schema)

Converts atom keys to string keys recursively in a data structure.

This ensures that JSON schemas use string keys as required by the MCP specification.

deftool(name, list)

(macro)

Defines a tool with its schema and metadata.

Examples

deftool "say_hello" do
  meta do
    name "Hello Tool"
    description "Says hello to a given name"
    version "1.0.0"
  end

  input_schema %{
    type: "object",
    properties: %{name: %{type: "string"}},
    required: ["name"]
  }
end

execution(config)

(macro)

Sets task execution support for the current tool (new in 2025-11-25).

Examples

execution %{taskSupport: :optional}

icons(icon_list)

(macro)

Sets icons for the current tool (new in 2025-11-25).

Examples

icons [%{type: "icon", uri: "https://example.com/icon.svg", mediaType: "image/svg+xml"}]

input_schema(schema)

(macro)

Sets a raw JSON Schema for the tool input.

tool_annotations(annotations)

(macro)

Sets annotations for the current tool.