fix: generate default schema for tools with no params (#446)
* fix: generate default schema for tools with no params
This commit is contained in:
parent
57fc428c57
commit
717ec56e23
2 changed files with 14 additions and 4 deletions
|
|
@ -199,9 +199,13 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
|
|||
rmcp::handler::server::common::cached_schema_for_type::<#params_ty>()
|
||||
})?
|
||||
} else {
|
||||
// if not found, use a simple empty JSON object
|
||||
// if not found, use a default empty JSON schema object
|
||||
// TODO: should be updated according to the new specifications
|
||||
syn::parse2::<Expr>(quote! {
|
||||
std::sync::Arc::new(serde_json::Map::new())
|
||||
std::sync::Arc::new(serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}).as_object().unwrap().clone())
|
||||
})?
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,8 +121,14 @@ async fn test_tool_macros() {
|
|||
async fn test_tool_macros_with_empty_param() {
|
||||
let _attr = Server::empty_param_tool_attr();
|
||||
println!("{_attr:?}");
|
||||
assert!(_attr.input_schema.get("type").is_none());
|
||||
assert!(_attr.input_schema.get("properties").is_none());
|
||||
assert_eq!(
|
||||
_attr.input_schema.get("type"),
|
||||
Some(&serde_json::Value::String("object".to_string()))
|
||||
);
|
||||
assert_eq!(
|
||||
_attr.input_schema.get("properties"),
|
||||
Some(&serde_json::Value::Object(serde_json::Map::new()))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue