MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

pkg/tools/mcp/adapter.go:62–77  ·  view source on GitHub ↗

Execute 执行 MCP 工具调用

(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

60
61// Execute 执行 MCP 工具调用
62func (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 工具工厂函数
80func ToolFactory(mcpClient *cloud.MCPClient, mcpTool cloud.MCPTool) tools.ToolFactory {

Callers 1

Calls 1

CallToolMethod · 0.45

Tested by 1