FastestMCP.Schema (fastest_mcp v0.2.0)

Copy Markdown View Source

Compile-once JSON Schema validation for FastestMCP.

Schemas default to JSON Schema Draft 2020-12. Draft 7 is also accepted when selected explicitly. Validation never coerces submitted values and remote references fail closed unless an application resolver is provided.

Summary

Functions

Compiles a JSON Schema into a reusable validator.

Compiles a JSON Schema, raising FastestMCP.Schema.Error on failure.

Returns a deterministic SHA-256 digest for a JSON Schema.

Returns whether the schema has the MCP-required object root.

Validates a value without coercion and returns the original value on success.

Types

raw()

@type raw() :: boolean() | map()

Functions

compile(schema, opts \\ [])

@spec compile(
  raw(),
  keyword()
) ::
  {:ok, FastestMCP.Schema.Compiled.t()} | {:error, FastestMCP.Schema.Error.t()}

Compiles a JSON Schema into a reusable validator.

compile!(schema, opts \\ [])

@spec compile!(
  raw(),
  keyword()
) :: FastestMCP.Schema.Compiled.t()

Compiles a JSON Schema, raising FastestMCP.Schema.Error on failure.

digest(schema)

@spec digest(raw()) :: {:ok, String.t()} | {:error, FastestMCP.Schema.Error.t()}

Returns a deterministic SHA-256 digest for a JSON Schema.

object_root?(schema)

@spec object_root?(term()) :: boolean()

Returns whether the schema has the MCP-required object root.

validate(compiled, value)

@spec validate(FastestMCP.Schema.Compiled.t(), term()) ::
  {:ok, term()} | {:error, FastestMCP.Schema.Error.t()}

Validates a value without coercion and returns the original value on success.