Sign in

    #shiguri-01/mcp/schema

    Typed JSON Schema (Draft 2020-12) builder, validator, and decoder.

    #Defining Schemas

    ///|
    struct UserInput {
    name : String
    age : Int?
    } derive(@json.FromJson, ToJson)

    ///|
    impl @schema.JsonSchema for UserInput with fn json_schema() {
    @schema.Schema::object(
    properties={
    "name": @schema.Schema::string(min_length=1),
    "age": @schema.Schema::integer(minimum=0),
    },
    required=["name"],
    )
    }

    #Validating & Decoding

    // Validate & decode JSON into typed struct in one step
    let input : UserInput = try! @schema.decode(json)

    // Direct instance validation
    let schema = @schema.Schema::string(min_length=3)
    try! schema.validate(Json::string("hello"))

    JsonSchema

    pub(open) trait JsonSchema {
    fn json_schema() -> Schema raise SchemaError
    }

    JSON Schema provider for typed tool inputs.
    impl JsonSchema for Bool
    impl JsonSchema for Int
    impl JsonSchema for Int64
    impl JsonSchema for Option[T]
    impl JsonSchema for Array[T]
    impl JsonSchema for Json

    SchemaError

    pub suberror SchemaError {
    InvalidDocument(String)
    UnsupportedDialect(String)
    UnsupportedKeyword(String)
    InvalidSchema(String)
    } derive(Eq,
    Debug
    )

    Errors raised while constructing, compiling, or validating a schema.
    impl Show for SchemaError

    ValidationIssues

    pub suberror ValidationIssues {
    ValidationIssues(Array[ValidationIssue])
    } derive(Eq,
    Debug
    )

    Validation failure holding one or more validation issues.

    Schema

    pub struct Schema {
    // private fields
    }

    A first-class JSON Schema value wrapping any JSON Schema construct.
    impl Eq for Schema
    impl Show for Schema
    impl ToJson for Schema

    Schema::all_of

    fn Schema::all_of(values : Array[Schema], description? : String) -> Schema

    An allOf combinator schema.

    Schema::always

    fn Schema::always() -> Schema

    A boolean JSON schema that always passes validation (true).

    Schema::any_of

    fn Schema::any_of(values : Array[Schema], description? : String) -> Schema raise SchemaError

    An anyOf combinator schema.

    Schema::array

    fn Schema::array(items? : Schema, min_items? : Int, max_items? : Int, unique_items? : Bool, description? : String) -> Schema raise SchemaError

    An array type schema.

    Schema::boolean

    fn Schema::boolean(description? : String) -> Schema

    A boolean primitive type schema (type: "boolean").

    Schema::constant

    fn[T : ToJson] Schema::constant(value : T, description? : String) -> Schema

    A const assertion schema.

    Schema::enumeration

    fn[T : ToJson] Schema::enumeration(values : Array[T], description? : String) -> Schema raise SchemaError

    An enum assertion schema.

    Schema::from_json

    fn Schema::from_json(value : Json, max_depth? : Int, max_nodes? : Int) -> Schema raise SchemaError

    Parse a JSON value as a JSON Schema document (Draft 2020-12).

    Schema::integer

    fn Schema::integer(minimum? : Int, maximum? : Int, description? : String) -> Schema raise SchemaError

    An integer type schema.

    Schema::never

    fn Schema::never() -> Schema

    A boolean JSON schema that always fails validation (false).

    Schema::not

    fn Schema::not(value : Schema, description? : String) -> Schema

    A not combinator schema.

    Schema::null

    fn Schema::null(description? : String) -> Schema

    A null type schema (type: "null").

    Schema::number

    fn Schema::number(minimum? : Double, maximum? : Double, exclusive_minimum? : Double, exclusive_maximum? : Double, multiple_of? : Double, description? : String) -> Schema raise SchemaError

    A number type schema.

    Schema::object

    fn Schema::object(properties? : Map[String, Schema], required? : Array[String], additional_properties? : Bool, min_properties? : Int, max_properties? : Int, description? : String) -> Schema raise SchemaError

    An object type schema.

    Schema::one_of

    fn Schema::one_of(values : Array[Schema], description? : String) -> Schema raise SchemaError

    A oneOf combinator schema.

    Schema::raw

    fn Schema::raw(value : Json) -> Schema raise SchemaError

    An unconstrained escape hatch schema for raw JSON.

    Schema::ref_

    fn Schema::ref_(reference : String, description? : String) -> Schema raise SchemaError

    A $ref reference schema.

    Schema::string

    fn Schema::string(min_length? : Int, max_length? : Int, description? : String) -> Schema raise SchemaError

    A string type schema.

    Schema::to_json

    fn Schema::to_json(self : Schema) -> Json

    Schema::validate

    fn Schema::validate(self : Schema, instance : Json, max_depth? : Int) -> Unit raise ValidationIssues

    Validate a JSON instance against this schema. Raises ValidationIssues if any validation constraints are violated.

    ValidationIssue

    pub struct ValidationIssue {
    path :
    JsonPath

    message : String
    } derive(Eq,
    Debug
    )

    An individual issue found during JSON Schema validation.

    ValidationIssue::ValidationIssue

    fn ValidationIssue::ValidationIssue(path~ :
    JsonPath
    , message~ : String) -> ValidationIssue

    DRAFT_2020_12

    let DRAFT_2020_12 : String

    The JSON Schema dialect used by MCP 2026-07-28 when $schema is absent.

    decode

    fn[T : JsonSchema +
    FromJson
    ] decode(json : Json, max_depth? : Int) -> T raise

    Validates a JSON instance against the schema associated with type T, and decodes it into T.

    schema_of

    fn[A : JsonSchema] schema_of(_witness : A?) -> Schema raise SchemaError

    Obtain a typed schema without constructing a runtime value of A.