fix(upstream): 支持 Claude custom 类型工具 (MCP) 格式
- ClaudeTool 结构体增加 Type 和 Custom 字段 - buildTools 函数支持从 custom 字段读取 input_schema - convertClaudeToolsToGeminiTools 函数支持 MCP 工具格式 - 修复 Antigravity upstream error 400: JSON schema invalid 修复 Issue 0.2: tools.X.custom.input_schema 验证错误
This commit is contained in:
@@ -37,8 +37,19 @@ type ClaudeMetadata struct {
|
||||
}
|
||||
|
||||
// ClaudeTool Claude 工具定义
|
||||
// 支持两种格式:
|
||||
// 1. 标准格式: { "name": "...", "description": "...", "input_schema": {...} }
|
||||
// 2. Custom 格式 (MCP): { "type": "custom", "name": "...", "custom": { "description": "...", "input_schema": {...} } }
|
||||
type ClaudeTool struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type,omitempty"` // "custom" 或空(标准格式)
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"` // 标准格式使用
|
||||
InputSchema map[string]any `json:"input_schema,omitempty"` // 标准格式使用
|
||||
Custom *CustomToolSpec `json:"custom,omitempty"` // custom 格式使用
|
||||
}
|
||||
|
||||
// CustomToolSpec MCP custom 工具规格
|
||||
type CustomToolSpec struct {
|
||||
Description string `json:"description,omitempty"`
|
||||
InputSchema map[string]any `json:"input_schema"`
|
||||
}
|
||||
|
||||
@@ -379,12 +379,26 @@ func buildTools(tools []ClaudeTool) []GeminiToolDeclaration {
|
||||
// 普通工具
|
||||
var funcDecls []GeminiFunctionDecl
|
||||
for _, tool := range tools {
|
||||
var description string
|
||||
var inputSchema map[string]any
|
||||
|
||||
// 检查是否为 custom 类型工具 (MCP)
|
||||
if tool.Type == "custom" && tool.Custom != nil {
|
||||
// Custom 格式: 从 custom 字段获取 description 和 input_schema
|
||||
description = tool.Custom.Description
|
||||
inputSchema = tool.Custom.InputSchema
|
||||
} else {
|
||||
// 标准格式: 从顶层字段获取
|
||||
description = tool.Description
|
||||
inputSchema = tool.InputSchema
|
||||
}
|
||||
|
||||
// 清理 JSON Schema
|
||||
params := cleanJSONSchema(tool.InputSchema)
|
||||
params := cleanJSONSchema(inputSchema)
|
||||
|
||||
funcDecls = append(funcDecls, GeminiFunctionDecl{
|
||||
Name: tool.Name,
|
||||
Description: tool.Description,
|
||||
Description: description,
|
||||
Parameters: params,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2245,12 +2245,32 @@ func convertClaudeToolsToGeminiTools(tools any) []any {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name, _ := tm["name"].(string)
|
||||
desc, _ := tm["description"].(string)
|
||||
params := tm["input_schema"]
|
||||
|
||||
var name, desc string
|
||||
var params any
|
||||
|
||||
// 检查是否为 custom 类型工具 (MCP)
|
||||
toolType, _ := tm["type"].(string)
|
||||
if toolType == "custom" {
|
||||
// Custom 格式: 从 custom 字段获取 description 和 input_schema
|
||||
custom, ok := tm["custom"].(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name, _ = tm["name"].(string)
|
||||
desc, _ = custom["description"].(string)
|
||||
params = custom["input_schema"]
|
||||
} else {
|
||||
// 标准格式: 从顶层字段获取
|
||||
name, _ = tm["name"].(string)
|
||||
desc, _ = tm["description"].(string)
|
||||
params = tm["input_schema"]
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
funcDecls = append(funcDecls, map[string]any{
|
||||
"name": name,
|
||||
"description": desc,
|
||||
|
||||
Reference in New Issue
Block a user