Ectomancer.Output (Ectomancer v1.7.0)

Copy Markdown View Source

Sanitizes and serializes Ectomancer tool results into JSON-safe output.

Ecto structs are converted to plain maps, Ecto internals (__meta__, #Ecto.Association.NotLoaded<>) are removed or replaced with null, and datetime/decimal values are rendered as ISO-8601 strings so that MCP clients receive valid, parseable JSON.

Field filtering is applied recursively so only:/except: redaction also reaches nested records (e.g. batch results and preloaded associations).

Summary

Functions

Encodes a value as a JSON string, sanitizing Ecto structs along the way.

Recursively filters the fields of Ecto structs to the given allowlist.

Functions

encode!(data)

@spec encode!(term()) :: String.t()

Encodes a value as a JSON string, sanitizing Ecto structs along the way.

filter_fields(term, allowed)

@spec filter_fields(term(), [atom()]) :: term()

Recursively filters the fields of Ecto structs to the given allowlist.

Works on single structs, lists, plain maps, paginated results, and batch result maps. Non-struct values (strings, numbers, datetimes) pass through unchanged.