ExMCP.Server.DSL.Result (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Response helpers for the modern server DSL.

When a module uses ExMCP.Server.DSL, this module is aliased as ToolResult. Outside DSL modules, call the functions via ExMCP.Server.DSL.Result.

Building results

ToolResult.text("hello")
ToolResult.error("something went wrong")
ToolResult.structured("done", %{count: 1})

Normalization

Handlers may also return plain values; the DSL normalizes them:

  • binaries and %{text: ...} → text content
  • %{content: ...} maps → used as tool results
  • {:ok, result} / {:ok, result, state} / {:error, reason} tuples

Summary

Functions

Builds an error tool result.

Suspends a modern tool, resource, or prompt result for MRTR input.

Builds a tool result with both text and structured content.

Builds a text tool result.

Functions

error(reason)

@spec error(any()) :: map()

Builds an error tool result.

input_required(input_requests, request_state \\ nil)

@spec input_required(map(), term()) :: ExMCP.Server.MRTR.InputRequired.t()

Suspends a modern tool, resource, or prompt result for MRTR input.

The optional application state must be JSON encodable. ExMCP seals it into an opaque requestState; handlers can read it on the retry through ExMCP.Server.Context.request_state/0.

structured(text, data)

@spec structured(String.t(), map()) :: map()

Builds a tool result with both text and structured content.

text(text)

@spec text(String.t()) :: map()

Builds a text tool result.