Execute 执行 MCP 工具调用
(ctx context.Context, input map[string]any, tc *tools.ToolContext)
| 60 | |
| 61 | // Execute 执行 MCP 工具调用 |
| 62 | func (m *MCPToolAdapter) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) { |
| 63 | // 调用远程 MCP 工具 |
| 64 | result, err := m.client.CallTool(ctx, m.name, input) |
| 65 | if err != nil { |
| 66 | return nil, fmt.Errorf("mcp tool call failed: %w", err) |
| 67 | } |
| 68 | |
| 69 | // 解析结果 |
| 70 | var output any |
| 71 | if err := json.Unmarshal(result, &output); err != nil { |
| 72 | // 如果无法解析为通用接口,返回原始 JSON |
| 73 | return string(result), nil |
| 74 | } |
| 75 | |
| 76 | return output, nil |
| 77 | } |
| 78 | |
| 79 | // ToolFactory 创建 MCP 工具工厂函数 |
| 80 | func ToolFactory(mcpClient *cloud.MCPClient, mcpTool cloud.MCPTool) tools.ToolFactory { |