improve(agent): clarify MCP tool registration logging

Separate tool counting metrics for better clarity:
- unique_tools: number of distinct MCP tools
- total_registrations: total tool registrations across all agents
- agent_count: number of agents receiving the tools

Previously, tool_count was misleading as it showed total registrations,
making it appear that more unique tools were registered than actually exist.

Addresses Copilot code review feedback.
This commit is contained in:
yuchou87 2026-02-19 19:31:13 +08:00
parent 23cf757d46
commit 2dc48c0632

View file

@ -162,8 +162,12 @@ func (al *AgentLoop) Run(ctx context.Context) error {
// Register MCP tools for all agents // Register MCP tools for all agents
servers := mcpManager.GetServers() servers := mcpManager.GetServers()
toolCount := 0 uniqueTools := 0
totalRegistrations := 0
agentCount := len(al.registry.ListAgentIDs())
for serverName, conn := range servers { for serverName, conn := range servers {
uniqueTools += len(conn.Tools)
for _, tool := range conn.Tools { for _, tool := range conn.Tools {
for _, agentID := range al.registry.ListAgentIDs() { for _, agentID := range al.registry.ListAgentIDs() {
agent, ok := al.registry.GetAgent(agentID) agent, ok := al.registry.GetAgent(agentID)
@ -172,7 +176,7 @@ func (al *AgentLoop) Run(ctx context.Context) error {
} }
mcpTool := tools.NewMCPTool(mcpManager, serverName, tool) mcpTool := tools.NewMCPTool(mcpManager, serverName, tool)
agent.Tools.Register(mcpTool) agent.Tools.Register(mcpTool)
toolCount++ totalRegistrations++
logger.DebugCF("agent", "Registered MCP tool", logger.DebugCF("agent", "Registered MCP tool",
map[string]interface{}{ map[string]interface{}{
"agent_id": agentID, "agent_id": agentID,
@ -185,8 +189,10 @@ func (al *AgentLoop) Run(ctx context.Context) error {
} }
logger.InfoCF("agent", "MCP tools registered successfully", logger.InfoCF("agent", "MCP tools registered successfully",
map[string]interface{}{ map[string]interface{}{
"server_count": len(servers), "server_count": len(servers),
"tool_count": toolCount, "unique_tools": uniqueTools,
"total_registrations": totalRegistrations,
"agent_count": agentCount,
}) })
} }
} }