From f293c95c3359f3808a163d19739a25bd80661856 Mon Sep 17 00:00:00 2001 From: byte1024 Date: Mon, 7 Sep 2026 02:01:57 +0800 Subject: [PATCH] fix(mcp): preserve operation return docs --- core/switch_core/bridges/agent/mcp/server.py | 2 +- .../switch_core/bridges/agent/test_mcp_tool_surface.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/switch_core/bridges/agent/mcp/server.py b/core/switch_core/bridges/agent/mcp/server.py index 8bd62fbfc..f66b5dd79 100644 --- a/core/switch_core/bridges/agent/mcp/server.py +++ b/core/switch_core/bridges/agent/mcp/server.py @@ -84,7 +84,7 @@ async def on_call_tool(self, context: MiddlewareContext, call_next): # type: ig # Every operation, registered as a tool. This loop is the only thing that makes # an operation an MCP tool, so the two surfaces cannot diverge. for _op in all_operations().values(): - mcp.tool(_op.fn) + mcp.tool(_op.fn, description=_op.description) logger.debug("Registered %d operations as MCP tools", len(all_operations())) diff --git a/core/tests/switch_core/bridges/agent/test_mcp_tool_surface.py b/core/tests/switch_core/bridges/agent/test_mcp_tool_surface.py index 797749bad..274b8a9ba 100644 --- a/core/tests/switch_core/bridges/agent/test_mcp_tool_surface.py +++ b/core/tests/switch_core/bridges/agent/test_mcp_tool_surface.py @@ -13,6 +13,7 @@ import pytest from switch_core.bridges.agent.mcp.server import mcp +from switch_core.bridges.agent.operations import all_operations TASK_PROTOCOL_TOOLS = { "delegate_task", @@ -87,6 +88,14 @@ async def test_documented_tools_exist(tool_names: set[str]) -> None: ) +async def test_tool_descriptions_preserve_the_full_operation_contract() -> None: + tools = {tool.name: tool for tool in await mcp.list_tools()} + operation = all_operations()["list_agents"] + + assert tools[operation.name].description == operation.description + assert "Returns:" in tools[operation.name].description + + SKILLS = sorted( (Path(__file__).parents[5] / "connectors").glob("*/skills/switch/SKILL.md") )