ExMCP.Content.Transformer (ex_mcp v0.10.0)

View Source

Content transformation utilities for MCP content.

This module handles all content transformation operations including format conversion, normalization, and media processing. Extracted from the original Content.Validation module.

Summary

Types

Transformation operation

Functions

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 \\ [])

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

Compresses image data.

convert_encoding(text, from_encoding \\ "auto")

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

Converts text encoding to UTF-8.

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 \\ [])

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

Generates a thumbnail from image content.

normalize_whitespace(text)

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

Normalizes whitespace in text content.

resize_image(image_data, mime_type, opts)

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

Resizes image to fit within specified dimensions.

transform(content, operations)

Transforms content by applying a list of transformation operations.

Examples

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

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.