Skip to main content

Module schema

Module schema 

Source
Expand description

JSON Schema for Rust types, for MCP tool inputSchema/outputSchema.

JsonSchema::json_schema returns a type’s schema as JSON text. It is implemented for the primitives, String, Option, Vec, sets, maps keyed by strings and smart pointers; #[derive(JsonSchema)] (macros feature) implements it for a struct with named fields or an enum of unit variants, following the type’s #[serde(...)] renames so the schema describes what serde_json actually reads and writes.

The schemas use the subset of JSON Schema 2020-12 MCP clients rely on: type, properties, required, items, additionalProperties, enum, anyOf (for Option), minimum, description.

Structs§

ObjectSchema
Builds an object schema property by property — what #[derive(JsonSchema)] expands to.

Constants§

MAX_DEPTH
Nesting deeper than this yields {} (any value): a type that contains itself (struct Node { children: Vec<Node> }) would otherwise recurse forever.

Traits§

JsonSchema
A type with a JSON Schema.

Functions§

is_object_schema
true when schema describes a JSON object — what MCP requires of an outputSchema.
nested
T’s schema, or {} past MAX_DEPTH levels of nesting. Used for every field and element type, so recursive types end in “any value”.
string_enum
A string schema allowing only values — a unit-variant enum.
with_description
schema with "description" added (schema must be a JSON object).