Helpers for building MCP tool responses.
structured/2 keeps the payload in structuredContent and also mirrors it
into a JSON text block for broad MCP client compatibility.
Examples
iex> MCPKit.Response.tool() |> MCPKit.Response.error("boom") |> MCPKit.Response.to_result()
%{"content" => [%{"text" => "boom", "type" => "text"}], "isError" => true}
Summary
Functions
Marks the response as an error with a plain text content block.
Stores structured tool output and mirrors it into text content.
Converts the response struct into an MCP tool result payload.
Builds a fresh tool response.
Types
Functions
Marks the response as an error with a plain text content block.
Stores structured tool output and mirrors it into text content.
Examples
iex> MCPKit.Response.tool() |> MCPKit.Response.structured(%{"ok" => true}) |> MCPKit.Response.to_result()
%{
"content" => [%{"text" => ~s({"ok":true}), "type" => "text"}],
"isError" => false,
"structuredContent" => %{"ok" => true}
}
Converts the response struct into an MCP tool result payload.
Builds a fresh tool response.
Examples
iex> MCPKit.Response.tool()
%MCPKit.Response{content: [], structured_content: nil, is_error: false}