Implements outputSchema validation (#566)

* feat: implement output schema validation

* fix: calculator example comply MCP spec

* refactor: merge cached_schema_for_output into schema_for_output
This commit is contained in:
Dale Seo 2025-12-08 16:13:19 -05:00 • committed by GitHub
commit df84555065
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -165,8 +165,14 @@ impl Tool {
}
/// Set the output schema using a type that implements JsonSchema
///
/// # Panics
///
/// Panics if the generated schema does not have root type "object" as required by MCP specification.
pub fn with_output_schema<T: JsonSchema + 'static>(mut self) -> Self {
self.output_schema = Some(crate::handler::server::tool::cached_schema_for_type::<T>());
let schema = crate::handler::server::tool::schema_for_output::<T>()
.unwrap_or_else(|e| panic!("Invalid output schema for tool '{}': {}", self.name, e));
self.output_schema = Some(schema);
self
}