agent: Improve compatibility when using MCP servers with Gemini models (#28700)

WIP

Release Notes:

- agent: Improve compatibility when using MCPs with Gemini models
This commit is contained in:
Bennet Bo Fenner 2025-04-14 13:55:25 -06:00 committed by GitHub
parent 6c93d107c2
commit 2603f36737
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 307 additions and 103 deletions

View file

@ -84,7 +84,7 @@ mod tests {
use super::*;
#[gpui::test]
fn test_tool_schema_compatibility(cx: &mut App) {
fn test_builtin_tool_schema_compatibility(cx: &mut App) {
crate::init(
Arc::new(http_client::HttpClientWithUrl::new(
FakeHttpClient::with_200_response(),
@ -95,18 +95,23 @@ mod tests {
);
for tool in ToolRegistry::global(cx).tools() {
let schema =
tool.input_schema(language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset);
assert!(schema.is_object());
if schema.as_object().unwrap().contains_key("$schema") {
let error_message = format!(
"Tool schema for `{}` is not compatible with `language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset` (Gemini Models).\n\
Are you using `schema::json_schema_for<T>(format)` to generate the schema?",
tool.name()
);
let actual_schema = tool
.input_schema(language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset)
.unwrap();
let mut expected_schema = actual_schema.clone();
assistant_tool::adapt_schema_to_format(
&mut expected_schema,
language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset,
)
.unwrap();
panic!("{}", error_message)
}
let error_message = format!(
"Tool schema for `{}` is not compatible with `language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset` (Gemini Models).\n\
Are you using `schema::json_schema_for<T>(format)` to generate the schema?",
tool.name(),
);
assert_eq!(actual_schema, expected_schema, "{}", error_message)
}
}
}