McpServer.Tool (HTTP MCP Server v0.6.0)

View Source

Represents a complete tool definition with metadata and schema.

This module defines the structure for MCP tools, which are callable functions with input validation, output schemas, and behavioral hints.

Fields

  • name - Unique tool identifier
  • description - Human-readable description
  • input_schema - JSON Schema for input validation (can be a map or McpServer.Schema struct)
  • annotations - Optional metadata including title and behavioral hints
  • callback - Internal callback information (module/function pair for execution, not serialized to JSON)

Examples

iex> tool = McpServer.Tool.new(
...>   name: "calculator",
...>   description: "Performs arithmetic operations",
...>   input_schema: %{
...>     "type" => "object",
...>     "properties" => %{
...>       "operation" => %{"type" => "string"}
...>     }
...>   }
...> )
%McpServer.Tool{
  name: "calculator",
  description: "Performs arithmetic operations",
  input_schema: %{...}
}

Summary

Functions

Creates a new Tool struct.

Types

callback_info()

@type callback_info() :: {module :: atom(), function :: atom()} | nil

t()

@type t() :: %McpServer.Tool{
  annotations: McpServer.Tool.Annotations.t() | nil,
  callback: callback_info(),
  description: String.t(),
  input_schema: map() | McpServer.Schema.t(),
  name: String.t()
}

Functions

new(opts)

@spec new(keyword()) :: t()

Creates a new Tool struct.

Parameters

  • opts - Keyword list of tool options:
    • :name (required) - Unique tool identifier
    • :description (required) - Human-readable description
    • :input_schema (required) - JSON Schema for input validation
    • :annotations - Optional Tool.Annotations struct
    • :callback - Optional callback information as {module, function} tuple

Examples

iex> McpServer.Tool.new(
...>   name: "echo",
...>   description: "Echoes back the input",
...>   input_schema: %{"type" => "object"}
...> )
%McpServer.Tool{
  name: "echo",
  description: "Echoes back the input",
  input_schema: %{"type" => "object"}
}

iex> McpServer.Tool.new(
...>   name: "greet",
...>   description: "Greets a person",
...>   input_schema: McpServer.Schema.new(type: "object"),
...>   annotations: McpServer.Tool.Annotations.new(title: "Greeter"),
...>   callback: {MyController, :greet}
...> )
%McpServer.Tool{
  name: "greet",
  description: "Greets a person",
  annotations: %McpServer.Tool.Annotations{title: "Greeter"},
  callback: {MyController, :greet}
}