fix(gemini): correct MCP server config format for Gemini CLI (#275)

Transform MCP server configurations to match Gemini CLI's expected format:
- Remove 'type' field (Gemini infers transport from field presence)
- Use 'httpUrl' field for HTTP streaming servers (type: "http")
- Keep 'url' field for SSE servers (type: "sse")
- Keep 'command' field for stdio servers unchanged

This fixes MCP servers not being recognized by Gemini CLI when
configured through cc-switch.
This commit is contained in:
Bill ZHANG
2025-11-22 22:18:05 +11:00
committed by GitHub
parent b64bb6cfa1
commit 824bf796a8

View File

@@ -96,7 +96,20 @@ pub fn set_mcp_servers_map(
obj = server_obj;
}
// 移除 UI 辅助字段
// Gemini CLI 格式转换:
// - Gemini 不使用 "type" 字段(从字段名推断传输类型)
// - HTTP 使用 "httpUrl" 字段SSE 使用 "url" 字段
let transport_type = obj.get("type").and_then(|v| v.as_str());
if transport_type == Some("http") {
// HTTP streaming: 将 "url" 重命名为 "httpUrl"
if let Some(url_value) = obj.remove("url") {
obj.insert("httpUrl".to_string(), url_value);
}
}
// SSE 保持 "url" 字段不变
// 移除 UI 辅助字段和 type 字段Gemini 不需要)
obj.remove("type");
obj.remove("enabled");
obj.remove("source");
obj.remove("id");