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

Method RegisterTools

pkg/tools/mcp/server.go:74–95  ·  view source on GitHub ↗

RegisterTools 将 MCP 工具注册到 aster Registry

()

Source from the content-addressed store, hash-verified

72
73// RegisterTools 将 MCP 工具注册到 aster Registry
74func (s *MCPServer) RegisterTools() error {
75 s.mu.RLock()
76 defer s.mu.RUnlock()
77
78 if len(s.tools) == 0 {
79 return errors.New("no tools available, call Connect() first")
80 }
81
82 // 为每个 MCP 工具创建工厂并注册
83 for _, mcpTool := range s.tools {
84 // 使用 server_id 作为前缀避免工具名冲突
85 toolName := fmt.Sprintf("%s:%s", s.serverID, mcpTool.Name)
86
87 // 创建工具工厂
88 factory := ToolFactory(s.client, mcpTool)
89
90 // 注册到 Registry
91 s.registry.Register(toolName, factory)
92 }
93
94 return nil
95}
96
97// ListTools 返回已发现的工具列表
98func (s *MCPServer) ListTools() []cloud.MCPTool {

Callers 2

ConnectServerMethod · 0.80

Calls 2

ToolFactoryFunction · 0.70
RegisterMethod · 0.65

Tested by 1