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
|
|
@ -27,7 +27,14 @@ fn extract_schema_from_return_type(ret_type: &syn::Type) -> Option<Expr> {
|
|||
// First, try direct Json<T>
|
||||
if let Some(inner_type) = extract_json_inner_type(ret_type) {
|
||||
return syn::parse2::<Expr>(quote! {
|
||||
rmcp::handler::server::tool::cached_schema_for_type::<#inner_type>()
|
||||
rmcp::handler::server::tool::schema_for_output::<#inner_type>()
|
||||
.unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Invalid output schema for Json<{}>: {}",
|
||||
std::any::type_name::<#inner_type>(),
|
||||
e
|
||||
)
|
||||
})
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
|
@ -57,7 +64,14 @@ fn extract_schema_from_return_type(ret_type: &syn::Type) -> Option<Expr> {
|
|||
let inner_type = extract_json_inner_type(ok_type)?;
|
||||
|
||||
syn::parse2::<Expr>(quote! {
|
||||
rmcp::handler::server::tool::cached_schema_for_type::<#inner_type>()
|
||||
rmcp::handler::server::tool::schema_for_output::<#inner_type>()
|
||||
.unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Invalid output schema for Result<Json<{}>, E>: {}",
|
||||
std::any::type_name::<#inner_type>(),
|
||||
e
|
||||
)
|
||||
})
|
||||
})
|
||||
.ok()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue