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§
- Object
Schema - 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§
- Json
Schema - A type with a JSON Schema.
Functions§
- is_
object_ schema truewhenschemadescribes a JSON object — what MCP requires of anoutputSchema.- nested
T’s schema, or{}pastMAX_DEPTHlevels 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 schemawith"description"added (schemamust be a JSON object).