Vancouver.Tool behaviour (Vancouver v0.1.1)
View SourceTools enable LLMs to perform actions.
You can implement a tool as follows:
defmodule MyApp.Tools.CalculateSum do
use Vancouver.Tool
def name, do: "calculate_sum"
def description, do: "Add two numbers together"
def input_schema do
%{
"type" => "object",
"properties" => %{
"a" => %{"type" => "number"},
"b" => %{"type" => "number"}
},
"required" => ["a", "b"]
}
end
def run(conn, %{"a" => a, "b" => b}) do
send_text(conn, "#{a + b}")
end
end
The input schema must be a valid JSON Schema object.
Sending responses
Tools provide helper functions to send valid MCP responses:
send_json/2
- sends a JSON responsesend_text/2
- sends a text responsesend_error/2
- sends an error response
Summary
Callbacks
Human readable description of what the tool does.
JSON Schema defining the tool's input parameters.
Unique identifier for the tool.
Execute the tool with the given parameters.
Callbacks
@callback description() :: String.t()
Human readable description of what the tool does.
@callback input_schema() :: map()
JSON Schema defining the tool's input parameters.
@callback name() :: String.t()
Unique identifier for the tool.
@callback run(conn :: Plug.Conn.t(), params :: map()) :: Plug.Conn.t()
Execute the tool with the given parameters.
Functions
@spec send_error(Plug.Conn.t(), binary()) :: Plug.Conn.t()
Sends an error response.
Examples
iex> send_error(conn, "an error occurred")
@spec send_json(Plug.Conn.t(), term()) :: Plug.Conn.t()
Sends JSON response.
Examples
iex> send_json(conn, %{id: 123})
@spec send_text(Plug.Conn.t(), binary()) :: Plug.Conn.t()
Sends text response.
Examples
iex> send_text(conn, "hello")