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:
parent
3c62ee8952
commit
df84555065
1 changed files with 122 additions and 10 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue