ExMCP.Server.Tools.ASTValidator (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Validates AST nodes to ensure they are safe for evaluation.

Deprecated

Part of the deprecated ExMCP.Server.Tools API. Planned for removal in 2.0.0.

This module provides security validation for AST nodes that will be evaluated using Code.eval_quoted, preventing code injection attacks.

Summary

Functions

Validates that an AST node contains only safe constructs.

Functions

validate_schema_ast(ast)

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

Validates that an AST node contains only safe constructs.

Returns {:ok, ast} if the AST is safe, or {:error, reason} if unsafe constructs are detected.

Examples

iex> ASTValidator.validate_schema_ast({:%{}, [], [type: "string"]})
{:ok, {:%{}, [], [type: "string"]}}

iex> ASTValidator.validate_schema_ast({:eval, [], ["dangerous code"]})
{:error, "Unsafe AST node: eval"}