ExMCP.Server.Tools.ResponseNormalizer (ex_mcp v0.10.0)

View Source

Normalizes tool responses to comply with MCP specification.

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.