ExMCP.Server.Tools.ResponseNormalizer (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Normalizes tool responses to comply with MCP specification.

Deprecated

Part of the deprecated ExMCP.Server.Tools API. Planned for removal in 2.0.0. Prefer ExMCP.Server.DSL.Result normalization used by ExMCP.Server.DSL.

This module extracts the response normalization logic from the original Server.Tools module into a focused, testable unit.

Summary

Functions

Normalizes various response formats into MCP-compliant structure.

Normalizes error responses.

Functions

normalize(response)

@spec normalize(any()) :: map()

Normalizes various response formats into MCP-compliant structure.

Examples

# String response
normalize("Hello") 
# => %{content: [%{type: "text", text: "Hello"}]}

# Map with text key
normalize(%{text: "Hello"})
# => %{content: [%{type: "text", text: "Hello"}]}

# Already normalized
normalize(%{content: [%{type: "text", text: "Hello"}]})
# => %{content: [%{type: "text", text: "Hello"}]}

normalize_error(reason)

@spec normalize_error(any()) :: map()

Normalizes error responses.