ExMCP.Content.Transformer (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Content transformation utilities for MCP content.

Experimental

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

Deprecated stubs (planned for removal in 2.0.0)

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

Summary

Types

Transformation operation

Functions

Compresses image data.

Converts text encoding to UTF-8.

Converts content from one format to another.

Extracts plain text from various content types.

Generates a thumbnail from image content.

Normalizes whitespace in text content.

Resizes image to fit within specified dimensions.

Transforms content by applying a list of transformation operations.

Transforms content with validation after each operation.

Types

transformation_op()

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

Transformation operation

Functions

compress_image(image_data, mime_type, opts \\ [])

This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..
@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(text, from_encoding \\ "auto")

This function is deprecated. Not implemented; not required by MCP/ACP. Planned for removal in 2.0.0..
@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(content, to_format)

@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(arg1)

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

Extracts plain text from various content types.

generate_thumbnail(image_data, mime_type, opts \\ [])

This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..
@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(text)

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

Normalizes whitespace in text content.

resize_image(image_data, mime_type, opts)

This function is deprecated. Not an MCP/ACP API; never implemented. Planned for removal in 2.0.0. Use app-level image tools..
@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(content, operations)

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(content, operations)

@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.