McpServer.Tool.CallResult (HTTP MCP Server v0.8.0)

View Source

Extended tool call result supporting structured content for UI rendering.

Controllers can return this struct instead of a plain content list to include structured_content (structured data optimized for UI rendering) alongside the standard content (text representation for model context).

Fields

Usage

Return from a tool controller function:

def get_weather(_conn, %{"location" => location}) do
  weather = fetch_weather(location)

  {:ok, McpServer.Tool.CallResult.new(
    content: [McpServer.Tool.Content.text("Weather in #{location}: #{weather.temp}°F")],
    structured_content: %{
      "temperature" => weather.temp,
      "unit" => "fahrenheit",
      "humidity" => weather.humidity,
      "forecast" => weather.forecast
    }
  )}
end

For backward compatibility, controllers can still return a plain content list:

def echo(_conn, %{"message" => message}) do
  {:ok, [McpServer.Tool.Content.text(message)]}
end

Summary

Functions

Creates a new CallResult struct.

Types

t()

@type t() :: %McpServer.Tool.CallResult{
  _meta: map() | nil,
  content: list(),
  structured_content: map() | nil
}

Functions

new(opts)

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

Creates a new CallResult struct.

Parameters

  • opts - Keyword list of options:
    • :content (required) - List of content blocks
    • :structured_content - Structured data for UI rendering (optional)
    • :_meta - Additional metadata (optional)

Examples

iex> McpServer.Tool.CallResult.new(
...>   content: [McpServer.Tool.Content.text("hello")],
...>   structured_content: %{"greeting" => "hello"}
...> )
%McpServer.Tool.CallResult{
  content: [%McpServer.Tool.Content.Text{text: "hello"}],
  structured_content: %{"greeting" => "hello"}
}