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

View Source

Simplified 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

annotations(anns)

(macro)

apply_default_description(tool, desc)

deftool(name, description \\ nil, list)

(macro)

Define a tool with a cleaner syntax.

Instead of heavy metaprogramming, this builds a tool at compile time and registers it at runtime.

description(text)

(macro)

input_schema(schema)

(macro)

output_schema(schema)

(macro)

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

(macro)

process_instructions(tool, instructions)

run(handler)

(macro)

title(text)

(macro)