Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gemini: Fix tool schema issues when type field is array (#53834)
Bennet Bo Fennerdec1a2a3b855
diff --git a/crates/language_model_core/src/tool_schema.rs b/crates/language_model_core/src/tool_schema.rsindex 0e82b2f4108..86e6d6d137e 100644--- a/crates/language_model_core/src/tool_schema.rs+++ b/crates/language_model_core/src/tool_schema.rs@@ -118,6 +118,15 @@ fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {}}+ // Ensure that the type field is not an array. This can happen with MCP tool+ // schemas that use multiple types (e.g. `["string", "number"]` or `["string", "null"]`).+ if let Some(type_value) = obj.get_mut("type")+ && let Some(types) = type_value.as_array()+ && let Some(first_type) = types.first().cloned()+ {+ *type_value = first_type;+ }+if matches!(obj.get("description"), Some(Value::String(_)))&& !obj.contains_key("type")&& !(obj.contains_key("anyOf")@@ -307,6 +316,42 @@ mod tests {);}+ #[test]+ fn test_transform_array_type_to_single_type() {+ let mut json = json!({+ "type": "object",+ "properties": {+ "projectSlugOrId": {+ "type": ["string", "number"],+ "description": "Project slug or numeric ID"+ },+ "optionalName": {+ "type": ["string", "null"],+ "description": "An optional name"+ }+ }+ });++ adapt_to_json_schema_subset(&mut json).unwrap();++ assert_eq!(+ json,+ json!({+ "type": "object",+ "properties": {+ "projectSlugOrId": {+ "type": "string",+ "description": "Project slug or numeric ID"+ },+ "optionalName": {+ "type": "string",+ "description": "An optional name"+ }+ }+ })+ );+ }+#[test]fn test_transform_fails_if_unsupported_keys_exist() {let mut json = json!({