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

Method AddTool

pkg/agent/tool_manager.go:227–248  ·  view source on GitHub ↗

AddTool 添加新工具

(tool tools.Tool, source string, deferred bool)

Source from the content-addressed store, hash-verified

225
226// AddTool 添加新工具
227func (tm *ToolManager) AddTool(tool tools.Tool, source string, deferred bool) error {
228 tm.mu.Lock()
229 defer tm.mu.Unlock()
230
231 name := tool.Name()
232
233 // 添加到索引
234 if err := tm.index.IndexTool(tool, source, deferred); err != nil {
235 return fmt.Errorf("failed to index tool: %w", err)
236 }
237
238 if deferred {
239 entry := tm.index.GetTool(name)
240 if entry != nil {
241 tm.deferredTools[name] = *entry
242 }
243 } else {
244 tm.activeTools[name] = tool
245 }
246
247 return nil
248}
249
250// AddToolEntry 添加工具条目(用于 MCP 延迟加载)
251func (tm *ToolManager) AddToolEntry(entry search.ToolIndexEntry) error {

Callers

nothing calls this directly

Calls 3

IndexToolMethod · 0.80
NameMethod · 0.65
GetToolMethod · 0.45

Tested by

no test coverage detected