From 40fad91ec219dbcd17b86bccfca928d550c4a2c1 Mon Sep 17 00:00:00 2001 From: lihua Date: Fri, 13 Mar 2026 16:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8Cmcp=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9Atool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nanobot/agent/tools/mcp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.py index 400979b..8c5c6ba 100644 --- a/nanobot/agent/tools/mcp.py +++ b/nanobot/agent/tools/mcp.py @@ -138,11 +138,17 @@ async def connect_mcp_servers( await session.initialize() tools = await session.list_tools() + enabled_tools = set(cfg.enabled_tools) if cfg.enabled_tools else None + registered_count = 0 for tool_def in tools.tools: + if enabled_tools and tool_def.name not in enabled_tools: + logger.debug("MCP: skipping tool '{}' from server '{}' (not in enabledTools)", tool_def.name, name) + continue wrapper = MCPToolWrapper(session, name, tool_def, tool_timeout=cfg.tool_timeout) registry.register(wrapper) logger.debug("MCP: registered tool '{}' from server '{}'", wrapper.name, name) + registered_count += 1 - logger.info("MCP server '{}': connected, {} tools registered", name, len(tools.tools)) + logger.info("MCP server '{}': connected, {} tools registered", name, registered_count) except Exception as e: logger.error("MCP server '{}': failed to connect: {}", name, e)