LocalizeMcp.Tools.Invoke (Localize MCP v0.1.0)

View Source

Implementation of the localize_invoke tool.

Executes one allowlisted MFA from priv/mcp/invocable.exs and returns its result encoded through LocalizeMcp.TermGrammar.

Three safety layers:

  1. Allowlist. The MFA must appear in priv/mcp/invocable.exs; everything else returns :not_invokable.

  2. Task isolation. The call runs in a Task.async/1 so the caller's process dictionary (current locale, etc.) stays clean and exceptions / exits are captured locally.

  3. Resource caps. 5 second wall-clock timeout. The :max_heap_size flag is applied to the task process so a runaway call cannot grow the BEAM unboundedly.

Exceptions and timeouts return as structured {:error, ...} maps; the tool never raises.

Summary

Functions

call(arg1)

@spec call(map()) :: map()