ExMCP.Client.Response (ex_mcp v0.10.0)
View SourceResponse normalization and transformation utilities for MCP.
This module provides consistent, developer-friendly response formats by normalizing raw MCP protocol responses into standardized structures.
Features
- Standardized field names (snake_case instead of mixed case)
- Type coercion and validation
- Automatic content parsing (JSON, text, etc.)
- Error context enrichment
- Missing field defaults
Response Types
All normalized responses follow consistent patterns:
- Tools:
%{name, description, input_schema, metadata} - Resources:
%{uri, name, description, mime_type, metadata} - Prompts:
%{name, description, arguments, metadata} - Content: Automatic parsing based on type detection
Summary
Functions
Converts a raw protocol response to a normalized format.
Normalizes a prompt definition from MCP protocol format.
Normalizes a prompt result (messages) from MCP protocol format.
Normalizes a resource definition from MCP protocol format.
Normalizes resource content with automatic parsing.
Normalizes server information response.
Normalizes a tool definition from MCP protocol format.
Normalizes a tool call result from MCP protocol format.
Types
Functions
Converts a raw protocol response to a normalized format.
This is a convenience function that handles the most common response types and provides a unified interface for response normalization.
@spec normalize_prompt(map()) :: normalized_prompt()
Normalizes a prompt definition from MCP protocol format.
Normalizes a prompt result (messages) from MCP protocol format.
@spec normalize_resource(map()) :: normalized_resource()
Normalizes a resource definition from MCP protocol format.
Normalizes resource content with automatic parsing.
Options
:parse_json- Parse JSON content automatically (default: true):encoding- Text encoding to use (default: "utf-8"):max_size- Maximum content size to parse (default: 10MB)
Normalizes server information response.
@spec normalize_tool(map()) :: normalized_tool()
Normalizes a tool definition from MCP protocol format.
Examples
# Raw MCP response
raw = %{
"name" => "calculator",
"description" => "Performs calculations",
"inputSchema" => %{"type" => "object", "properties" => %{...}}
}
# Normalized response
tool = Response.normalize_tool(raw)
# => %{
# name: "calculator",
# description: "Performs calculations",
# input_schema: %{type: "object", properties: %{...}},
# metadata: %{}
# }
Normalizes a tool call result from MCP protocol format.
Handles content parsing, error detection, and metadata extraction.