McpServer.Tool.CallResult (HTTP MCP Server v0.8.0)
View SourceExtended 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
content(required) - List of content blocks (McpServer.Tool.Content.Text,McpServer.Tool.Content.Image,McpServer.Tool.Content.Resource). This is the text representation included in model context.structured_content- Map of structured data optimized for UI rendering. Excluded from model context. Used by views to render rich interfaces._meta- Additional metadata (timestamps, source info). Not included in model context.
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
}
)}
endFor backward compatibility, controllers can still return a plain content list:
def echo(_conn, %{"message" => message}) do
{:ok, [McpServer.Tool.Content.text(message)]}
end
Summary
Types
Functions
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"}
}