fix: generate default schema for tools with no params (#446)

* fix: generate default schema for tools with no params
This commit is contained in:
V 2025-09-26 03:16:08 -07:00 • committed by GitHub
commit 717ec56e23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View file

@ -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())
})?
}
};

View file

@ -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]