fix: ensure tagged-enum schema injection meets tool expectations
This commit is contained in:
1 parent
2cfaeda0cb
commit
26eaf03b6f
1 file changed
+9
-1
+9
-1
@@ -22,7 +22,7 @@ pub fn error(id: serde_json::Value, code: i32, message: &str) -> serde_json::Val
|
||||
|
||||
pub fn tool_def<T: JsonSchema>(name: &str, fallback_desc: &str) -> serde_json::Value {
|
||||
let schema = schemars::schema_for!(T);
|
||||
let schema_val = serde_json::to_value(&schema).unwrap_or_default();
|
||||
let mut schema_val = serde_json::to_value(&schema).unwrap_or_default();
|
||||
|
||||
let desc = schema_val
|
||||
.get("description")
|
||||
@@ -31,6 +31,14 @@ pub fn tool_def<T: JsonSchema>(name: &str, fallback_desc: &str) -> serde_json::V
|
||||
.unwrap_or(fallback_desc)
|
||||
.to_string();
|
||||
|
||||
// MCP clients strictly expect a top-level `type: "object"` for tool schemas.
|
||||
// Tagged enums usually generate a root `oneOf` or `anyOf`.
|
||||
if let Some(obj) = schema_val.as_object_mut() {
|
||||
if !obj.contains_key("type") && (obj.contains_key("oneOf") || obj.contains_key("anyOf")) {
|
||||
obj.insert("type".to_string(), json!("object"));
|
||||
}
|
||||
}
|
||||
|
||||
// MCP expects standard JSON schema. Schemars returns draft-07.
|
||||
json!({
|
||||
"name": name,
|
||||
|
||||
Reference in new issue
Block a user