# `ExMCP.Client.Response`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/client/response.ex#L1)

Response 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

# `normalized_prompt`

```elixir
@type normalized_prompt() :: %{
  name: String.t(),
  description: String.t() | nil,
  arguments: [map()] | nil,
  metadata: map()
}
```

# `normalized_resource`

```elixir
@type normalized_resource() :: %{
  uri: String.t(),
  name: String.t() | nil,
  description: String.t() | nil,
  mime_type: String.t() | nil,
  metadata: map()
}
```

# `normalized_tool`

```elixir
@type normalized_tool() :: %{
  name: String.t(),
  description: String.t() | nil,
  input_schema: map() | nil,
  metadata: map()
}
```

# `from_protocol`

```elixir
@spec from_protocol(map()) :: {:ok, any()} | {:error, any()}
```

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.

# `normalize_prompt`

```elixir
@spec normalize_prompt(map()) :: normalized_prompt()
```

Normalizes a prompt definition from MCP protocol format.

# `normalize_prompt_result`

```elixir
@spec normalize_prompt_result(map()) :: map()
```

Normalizes a prompt result (messages) from MCP protocol format.

# `normalize_resource`

```elixir
@spec normalize_resource(map()) :: normalized_resource()
```

Normalizes a resource definition from MCP protocol format.

# `normalize_resource_content`

```elixir
@spec normalize_resource_content(
  map(),
  keyword()
) :: any()
```

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)

# `normalize_server_info`

```elixir
@spec normalize_server_info(map()) :: map()
```

Normalizes server information response.

# `normalize_tool`

```elixir
@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: %{}
    # }

# `normalize_tool_result`

```elixir
@spec normalize_tool_result(map()) :: any()
```

Normalizes a tool call result from MCP protocol format.

Handles content parsing, error detection, and metadata extraction.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
