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

Method CallToolsParallel

pkg/tools/bridge/bridge.go:134–165  ·  view source on GitHub ↗

CallToolsParallel 并行调用工具

(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

132
133// CallToolsParallel 并行调用工具
134func (b *ToolBridge) CallToolsParallel(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult {
135 results := make([]*CallToolResult, len(calls))
136 var wg sync.WaitGroup
137 var mu sync.Mutex
138 succeeded := 0
139 failed := 0
140
141 for i, call := range calls {
142 wg.Add(1)
143 go func(idx int, c CallToolInput) {
144 defer wg.Done()
145 result, _ := b.CallTool(ctx, c.Name, c.Input, tc)
146
147 mu.Lock()
148 results[idx] = result
149 if result.Success {
150 succeeded++
151 } else {
152 failed++
153 }
154 mu.Unlock()
155 }(i, call)
156 }
157
158 wg.Wait()
159
160 return &BatchCallResult{
161 Results: results,
162 Succeeded: succeeded,
163 Failed: failed,
164 }
165}
166
167// ListAvailableTools 列出所有可用工具
168func (b *ToolBridge) ListAvailableTools() []string {

Callers 1

Calls 3

CallToolMethod · 0.95
WaitMethod · 0.80
AddMethod · 0.65

Tested by 1