本地 SDK 实测
MCP 1.30 和 2.0 客户端如何处理工具错误
两个客户端访问同一个 SDK 1.30.0 服务端,分别查询已有键和缺失键。四次请求均返回 HTTP 200。两次缺失键查询都正常返回带有 isError: true 的工具结果。
观测记录
从 1.30.0 SDK 客户端切换到 2.0.0 客户端后,查询缺失键会返回怎样的结果?
- @modelcontextprotocol/sdk 1.30.0 · 已有键 / 缺失键 isError
- false / true
- @modelcontextprotocol/client 2.0.0 · 已有键 / 缺失键 isError
- false / true
- 工具请求的 MCP 协议头
- 2025-11-25
结果解读
在这个迁移场景中,两种客户端都可在 callTool 返回后读取 isError。仅检查 HTTP 状态或捕获抛出的异常会遗漏工具报告的错误。
如何复现
在空目录中运行以下命令。可先下载脚本,检查测试如何构造请求和记录结果。
mkdir -p niubiagent-client-comparison && cd niubiagent-client-comparison
npm install --prefix . --ignore-scripts --no-audit --no-fund @modelcontextprotocol/sdk@1.30.0 @modelcontextprotocol/client@2.0.0 zod@4.5.4
curl -fsSLo compare-clients.mjs https://www.niubiagent.com/lab/compare-clients.mjs
node compare-clients.mjs下载复现脚本 ↓