fix(agent-scan): Tool.inputSchema renamed to input_schema in mcp 2.0 - #614
fix(agent-scan): Tool.inputSchema renamed to input_schema in mcp 2.0#614toBeYoungD wants to merge 1 commit into
Conversation
MCP Python SDK 2.0.0 (pinned in agent-scan requirements.txt) renamed the Tool model's inputSchema attribute (camelCase) to input_schema (snake_case). describe_mcp_tools() still accessed t.inputSchema, so any Agent-Scan task that connects to a live MCP server raises AttributeError: 'Tool' object has no attribute 'inputSchema' when enumerating tools. mcp-scan got the same fix in PR Tencent#609 (dc5ae7f); agent-scan was missed. Changes: - Replace t.inputSchema with t.input_schema (3 occurrences in describe_mcp_tools()). - Add a regression test for describe_mcp_tools() in pytests/test_mcp_sdk_v2.py using an mcp 2.0-shaped Tool stub. Verified both tests pass with mcp==2.0.0 inside the agent image.
|
Thanks @toBeYoungD — clean, well-scoped fix and the root cause is spot on: Two non-blocking suggestions:
Otherwise this is correct and ready to merge. |
|
Thanks for the review! On the getattr guard — I kept the direct access deliberately, for two reasons: Version mixing can't occur in any supported deployment: requirements.txt pins mcp==2.0.0 (used by the Docker agent image, where the resolution is baked in), and pyproject.toml bounds it to mcp>=2.0.0,<3.0.0 for source installs. It also keeps agent-scan consistent with the already-merged mcp-scan fix in #609, which uses plain t.input_schema as well. Happy to add the guard if you feel strongly, but I'd prefer the two modules stay symmetric here. On mcp-scan parity — confirmed there is no shared helper today: mcp-scan/ and agent-scan/ are independent sub-projects (separate venvs and pyprojects, each spawned as a subprocess by the Go agent), and each carries its own full copy of MCPTools. Unifying them into a common package would be a refactor well beyond this PR's scope — happy to open a separate issue to discuss that if the maintainers are interested. |
|
Thanks for the detailed follow-up, @toBeYoungD — and your reasoning on the
The regression test ( Approving — this is ready to merge. 🚀 (Leaving as review comment only; not merging.) |
|
@toBeYoungD — still approved from my earlier review; the root cause, fix, and regression test are all correct, and checks are green. The |
问题
mcp==2.0.0环境下,agent-scan 连接 MCP 服务器成功(initialize / list_tools 均正常),但在遍历工具 schema 时抛出:最终表现为 Agent-Scan 任务连接 MCP 服务器失败。
根因
MCP Python SDK 2.0.0 将
Tool模型的inputSchema字段(camelCase)改名为input_schema(snake_case)。agent_scan/utils/mcp_tools.py的describe_mcp_tools()仍访问t.inputSchema,而 agent-scan 的requirements.txt已锁定mcp==2.0.0,因此该 bug 必然触发。mcp-scan 的同款问题已在 #609 (dc5ae7f) 修复,agent-scan 被遗漏。
改动
agent_scan/utils/mcp_tools.py:describe_mcp_tools()内 3 处t.inputSchema→t.input_schemapytests/test_mcp_sdk_v2.py:新增回归测试test_describe_mcp_tools_reads_input_schema,用 mcp 2.0 形状的 Tool 桩(只有input_schema属性)验证describe_mcp_tools()正常读取 schema 并缓存到_tools_schema;修复前该测试失败,修复后通过验证
在 agent 镜像内(Python 3.12 +
mcp==2.0.0)运行:结果:2 个测试全部通过(新增的 schema 测试 + 原有的 streamable-http 传输层测试,无回归)。