FastestMCP.Tools.Result (fastest_mcp v0.1.2)

Copy Markdown View Source

Canonical tool result helper.

Tool handlers can return plain Elixir values for the common case, but FastestMCP.Tools.Result is the explicit shape when the tool needs:

  • human-readable content that should not be derived automatically
  • structured content for machine consumers
  • result-level metadata
  • an explicit isError flag

When you provide structured_content without content, FastestMCP derives a readable text block from the structured payload so MCP transports still emit a complete tool result.

Examples

FastestMCP.Tools.Result.new("Release checklist generated",
  structured_content: %{status: "ok"}
)

FastestMCP.Tools.Result.new(
  [
    %{type: "text", text: "Release checklist generated"},
    %{type: "text", text: "Warnings: 0"}
  ],
  structured_content: %{status: "ok", warnings: 0},
  meta: %{source: "release-planner"}
)

Summary

Functions

Normalizes result-like values into %FastestMCP.Tools.Result{}.

Builds a normalized tool result.

Converts the helper struct into the normalized tool-result map used by the runtime.

Types

t()

@type t() :: %FastestMCP.Tools.Result{
  content: any(),
  is_error: boolean() | nil,
  meta: map() | nil,
  structured_content: any() | nil
}

Functions

from(result)

Normalizes result-like values into %FastestMCP.Tools.Result{}.

new(content \\ nil, opts \\ [])

Builds a normalized tool result.

to_map(result)

Converts the helper struct into the normalized tool-result map used by the runtime.