# `ExMCP.Content.Transformer`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/content/transformer.ex#L1)

Content transformation utilities for MCP content.

> #### Experimental {: .warning}
>
> Prefer `ExMCP.Content` for constructing MCP content blocks (`text`, `image`,
> `audio`, resources). MCP/ACP only require **carrying** image bytes + MIME
> type — not compressing, resizing, or generating thumbnails.

### Implemented

- `:normalize_whitespace` / `normalize_whitespace/1`
- `extract_text/1` (plain, simple HTML tag strip)
- `{:custom, fun/1}`
- limited text format conversion in `convert_format/2`

### Deprecated stubs (planned for removal in 2.0.0)

Image processing was never part of MCP/ACP and was never implemented:

- `compress_image/3`, `:compress_images`
- `resize_image/3`, `:resize_images`
- `generate_thumbnail/3`, `:generate_thumbnails`
- `convert_encoding/2` (needs external encoding libs)

# `transformation_op`

```elixir
@type transformation_op() ::
  :normalize_whitespace
  | :convert_encoding
  | :compress_images
  | :resize_images
  | :extract_text
  | :generate_thumbnails
  | {:custom, function()}
  | atom()
```

Transformation operation

# `compress_image`

> This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..

```elixir
@spec compress_image(binary(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, String.t()}
```

Compresses image data.

Deprecated stub — MCP only transports image content blocks; processing is app-level.

# `convert_encoding`

> This function is deprecated. Not implemented; not required by MCP/ACP. Planned for removal in 2.0.0..

```elixir
@spec convert_encoding(String.t(), String.t()) ::
  {:ok, String.t()} | {:error, String.t()}
```

Converts text encoding to UTF-8.

Deprecated stub — not an MCP requirement.

# `convert_format`

```elixir
@spec convert_format(ExMCP.Content.Protocol.content(), atom()) ::
  {:ok, ExMCP.Content.Protocol.content()} | {:error, String.t()}
```

Converts content from one format to another.

# `extract_text`

```elixir
@spec extract_text(ExMCP.Content.Protocol.content()) ::
  {:ok, String.t()} | {:error, String.t()}
```

Extracts plain text from various content types.

# `generate_thumbnail`

> This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..

```elixir
@spec generate_thumbnail(binary(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, String.t()}
```

Generates a thumbnail from image content.

Deprecated stub — not required by MCP/ACP.

# `normalize_whitespace`

```elixir
@spec normalize_whitespace(String.t()) :: String.t()
```

Normalizes whitespace in text content.

# `resize_image`

> This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..

```elixir
@spec resize_image(binary(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, String.t()}
```

Resizes image to fit within specified dimensions.

Deprecated stub — not required by MCP/ACP.

# `transform`

```elixir
@spec transform(ExMCP.Content.Protocol.content(), [transformation_op()]) ::
  {:ok, ExMCP.Content.Protocol.content()} | {:error, String.t()}
```

Transforms content by applying a list of transformation operations.

Deprecated image ops are **no-ops** in the pipeline for backward compatibility.

## Examples

    {:ok, transformed} = Transformer.transform(content, [:normalize_whitespace])

# `transform_with_validation`

```elixir
@spec transform_with_validation(ExMCP.Content.Protocol.content(), [
  transformation_op()
]) ::
  {:ok, ExMCP.Content.Protocol.content()} | {:error, String.t()}
```

Transforms content with validation after each operation.

---

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