barrel_mcp_schema (barrel_mcp v2.0.2)

View Source

Minimal JSON Schema validator for MCP tool inputs.

Implements the subset of JSON Schema that real MCP tools use, in pure Erlang with no extra dependencies. Covers:

  • type: object, array, string, number, integer, boolean, null, or a list of those for unions.
  • properties + required for objects.
  • additionalProperties: false rejection.
  • items for arrays (single schema applied to every item).
  • enum for string/number/integer/boolean.
  • oneOf / anyOf / allOf (allOf = each must validate).
  • minimum/maximum/exclusiveMinimum/exclusiveMaximum for numbers and integers.
  • minLength/maxLength/pattern for strings.
  • minItems/maxItems/uniqueItems for arrays.

Returns ok or {error, [Error]} where each error is a tuple {Path, Reason} (Path is a list of keys / indices from the root, Reason an atom or {atom, Detail}).

Anything outside the supported subset is silently accepted; this is a permissive validator by design — its job is to catch obvious bugs before sending an LLM-generated arg map to a remote tool, not to be a JSON Schema reference implementation.

Summary

Functions

Validate Value against Schema. Returns ok or {error, [Error]}.

Types

error/0

-type error() :: {path(), atom() | {atom(), term()}}.

path/0

-type path() :: [binary() | non_neg_integer()].

Functions

validate(Value, Schema)

-spec validate(term(), map()) -> ok | {error, [error()]}.

Validate Value against Schema. Returns ok or {error, [Error]}.