MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / RegisterMCPTools

Function RegisterMCPTools

tools/mcp.go:204–254  ·  view source on GitHub ↗
(registry *ToolRegistry, cwd string, execCtx ExecutionContext)

Source from the content-addressed store, hash-verified

202 in.URI,
203 in.ServerName,
204 err,
205 ), nil
206 }
207 return output, nil
208}
209
210func RegisterMCPTools(registry *ToolRegistry, cwd string, execCtx ExecutionContext) error {
211 if registry == nil {
212 return nil
213 }
214 configs := trustedMCPConfigs(cwd, execCtx)
215 if len(configs) == 0 {
216 return nil
217 }
218 clients := map[string]*mcp.McpClient{}
219 execCtx["mcp_clients"] = clients
220 var clientOrder []string
221 registeredCount := 0
222 for _, cfg := range configs {
223 client := mcp.NewMcpClient(cfg)
224 if !client.Connect(context.Background()) {
225 continue
226 }
227 discovered, err := client.DiscoverTools(context.Background())
228 if err != nil {
229 client.Disconnect(context.Background())
230 continue
231 }
232 clients[cfg.Name] = client
233 clientOrder = append(clientOrder, cfg.Name)
234 for _, toolDef := range discovered {
235 toolName := stringValueFromMap(toolDef, "name", "")
236 if toolName == "" {
237 continue
238 }
239 safeName := SanitizeMCPToolName(cfg.Name, toolName)
240 schema, _ := toolDef["inputSchema"].(map[string]any)
241 description := stringValueFromMap(toolDef, "description", "MCP tool: "+toolName)
242 registry.Register(NewMCPDynamicTool(
243 safeName,
244 cfg.Name,
245 toolName,
246 fmt.Sprintf("[MCP Server: %s] %s", cfg.Name, description),
247 schema,
248 fmt.Sprintf("mcp %s %s %s", cfg.Name, toolName, description),
249 ))
250 registeredCount++
251 }
252 }
253 if len(clients) > 0 {
254 execCtx["mcp_client_order"] = clientOrder
255 registry.Register(NewListMCPResourcesTool())
256 registry.Register(NewReadMCPResourceTool())
257 }

Callers

nothing calls this directly

Calls 11

ConnectMethod · 0.95
DiscoverToolsMethod · 0.95
DisconnectMethod · 0.95
NewMcpClientFunction · 0.92
trustedMCPConfigsFunction · 0.85
stringValueFromMapFunction · 0.85
SanitizeMCPToolNameFunction · 0.85
NewMCPDynamicToolFunction · 0.85
NewListMCPResourcesToolFunction · 0.85
NewReadMCPResourceToolFunction · 0.85
RegisterMethod · 0.45

Tested by

no test coverage detected