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
:normalize_whitespace/normalize_whitespace/1extract_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_imagesresize_image/3,:resize_imagesgenerate_thumbnail/3,:generate_thumbnailsconvert_encoding/2(needs external encoding libs)
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
Functions
Compresses image data.
Deprecated stub — MCP only transports image content blocks; processing is app-level.
Converts text encoding to UTF-8.
Deprecated stub — not an MCP requirement.
@spec convert_format(ExMCP.Content.Protocol.content(), atom()) :: {:ok, ExMCP.Content.Protocol.content()} | {:error, String.t()}
Converts content from one format to another.
@spec extract_text(ExMCP.Content.Protocol.content()) :: {:ok, String.t()} | {:error, String.t()}
Extracts plain text from various content types.
Generates a thumbnail from image content.
Deprecated stub — not required by MCP/ACP.
Normalizes whitespace in text content.
Resizes image to fit within specified dimensions.
Deprecated stub — not required by MCP/ACP.
@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])
@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.