ExMCP.Server.DSL (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Modern DSL for defining MCP server primitives next to their handlers.

Use this module with ExMCP.Server.Handler:

defmodule MyServer do
  use ExMCP.Server.Handler
  use ExMCP.Server.DSL, name: "my-server", version: "1.0.0"

  tool "echo", "Echo back the input" do
    param :message, :string, required: true
    param :tags, {:array, :string}, default: []

    run fn %{message: message}, state ->
      {:ok, message, state}
    end
  end
end

Param types include :string, :integer, :number, :boolean, :object/:map, and {:array, item_type}. Bare :array is rejected at compile time.

Invalid declarations fail at compile time with file/line and fix hints (missing handlers, duplicate names, wrong instructions per kind, etc.).

Inside DSL modules, ToolResult is an alias for ExMCP.Server.DSL.Result. See the project DSL guide for full details.

Summary

Functions

annotations(annotations)

(macro)

arg(name, opts \\ [])

(macro)

description(description)

(macro)

execution(execution)

(macro)

handle(handler)

(macro)

icons(icons)

(macro)

input_schema(schema)

(macro)

meta(meta)

(macro)

mime_type(mime_type)

(macro)

name(name)

(macro)

output_schema(schema)

(macro)

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

(macro)

prompt(name, description \\ nil, list)

(macro)

Defines a prompt with a co-located renderer.

read(handler)

(macro)

render(handler)

(macro)

resource(uri, description \\ nil, list)

(macro)

Defines a static resource with a co-located read handler.

resource_template(uri_template, description \\ nil, list)

(macro)

Defines a resource template with a co-located read handler.

run(handler)

(macro)

size(size)

(macro)

title(title)

(macro)

tool(name, description \\ nil, list)

(macro)

Defines a tool with a co-located handler.