MCPKit.Response (mcp_kit v0.2.4)

Copy Markdown View Source

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

t()

@type t() :: %MCPKit.Response{
  content: [map()],
  is_error: boolean(),
  structured_content: map() | nil
}

Functions

error(response, message)

Marks the response as an error with a plain text content block.

structured(response, payload)

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}
}

to_result(response)

Converts the response struct into an MCP tool result payload.

tool()

Builds a fresh tool response.

Examples

iex> MCPKit.Response.tool()
%MCPKit.Response{content: [], structured_content: nil, is_error: false}