Skip to main content
Version: 1.1.0 (latest)

JsonSchema

The JsonSchema derive macro generates JSON Schema for your struct fields, used by mcp_tool, mcp_resource, and mcp_elicit.

#[derive(macros::JsonSchema)]
pub struct MyTool {
pub name: String,
#[json_schema(title = "Age", minimum = 0, maximum = 150)]
pub age: u32,
#[json_schema(title = "Tags", max_length = 10)]
pub tags: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub optional_field: Option<String>,
}

Supported Attributesโ€‹

AttributeTypeDescription
titlestringHuman-readable field name
descriptionstringField description
minimum / maximumnumberNumeric range
min_length / max_lengthintegerString length (minLength/maxLength) or array size (minItems/maxItems) for Vec<T> fields
formatstringFormat hint (e.g., "email", "uri", "date-time")
defaultanyDefault value

Required/repeated #[json_schema(...)] attributes can be stacked on a single field.