Skip to content

Commit 717ec56

Browse files
authored
fix: generate default schema for tools with no params (#446)
* fix: generate default schema for tools with no params
1 parent 57fc428 commit 717ec56

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/rmcp-macros/src/tool.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
199199
rmcp::handler::server::common::cached_schema_for_type::<#params_ty>()
200200
})?
201201
} else {
202-
// if not found, use a simple empty JSON object
202+
// if not found, use a default empty JSON schema object
203+
// TODO: should be updated according to the new specifications
203204
syn::parse2::<Expr>(quote! {
204-
std::sync::Arc::new(serde_json::Map::new())
205+
std::sync::Arc::new(serde_json::json!({
206+
"type": "object",
207+
"properties": {}
208+
}).as_object().unwrap().clone())
205209
})?
206210
}
207211
};

crates/rmcp/tests/test_tool_macros.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ async fn test_tool_macros() {
121121
async fn test_tool_macros_with_empty_param() {
122122
let _attr = Server::empty_param_tool_attr();
123123
println!("{_attr:?}");
124-
assert!(_attr.input_schema.get("type").is_none());
125-
assert!(_attr.input_schema.get("properties").is_none());
124+
assert_eq!(
125+
_attr.input_schema.get("type"),
126+
Some(&serde_json::Value::String("object".to_string()))
127+
);
128+
assert_eq!(
129+
_attr.input_schema.get("properties"),
130+
Some(&serde_json::Value::Object(serde_json::Map::new()))
131+
);
126132
}
127133

128134
#[tokio::test]

0 commit comments

Comments
 (0)