Fix: Three blocking defects found by the MCP tool survey
The survey in docs/Mcp_Test_Report_2026-10-29.md turned up three P0s, each
of which stopped a whole capability rather than degrading it. Two of them
were the same mistake: the input schema promised something the output
schema then rejected. The third was an output with no size limit, plus a
client that never implemented the command at all.
Batch calls could never succeed. A call carrying ids[] goes through
BuildBatchCall, which returns {tool, total, succeeded, failed, skipped,
results[]}; every tool declares only the single-host shape. The client
validates structuredContent against that declaration, so any batch call
failed with -32602: data must have required property 'host' - the input
schema advertises ids, the output schema kills it. Tools/call cannot fix
this one call at a time, so ApplyBatchOutputSchema runs at the end of
tools/list, next to ApplyToolAnnotations, and rewrites the schema of every
tool in the batch list to {type: object, anyOf: [single, batch]}. Placing
it at the end is what makes it cover all three registration points
(inline, McpMachine, McpChat) and any tool added later. IsBatchReadOnlyTool
moved from McpServer.cpp to McpInternal.cpp for the same reason: the list
is now read by tools/call and tools/list, and the two must not drift.
list_registry failed whenever path was omitted. The root-key branch
returns keys only, while the output schema listed values in required as
well, so the first usage the documentation describes - omit path, get the
five root keys - could not work. values is no longer required and the
schema says it is absent in that branch. The root branch also returns
path: "" now, so both branches carry the same field set and callers need
not branch.
get_client_log was unusable on both platforms, for two unrelated reasons.
Windows returned the whole 1000-line ring buffer, 90,473 characters, over
the client's result limit: fetched, then not deliverable. Linux and macOS
timed out because their clients never handled COMMAND_QUERY_LOG at all -
only client/ClientLogManager.cpp does - so TOKEN_REPORT_LOG never arrived.
Adding a limit alone would have left Linux broken; fixing the client alone
would have left Windows over the limit.
The server now takes limit (default 200, max 2000) and filter, and reads
backwards from the end: troubleshooting wants the last thing that happened,
not the first line after boot. A 64 KB byte budget sits under the line
count, because one line can be a stack dump; when the final line alone
exceeds it, the tail is returned and truncated says so. Responses carry
lines_total, lines_matched, lines_returned and truncated. The timeout
message now names the likely cause and two ways around it instead of
saying only "Timeout waiting for client log".
The POSIX clients get common/ClientLogHandler.h, a counterpart to the
Windows CClientLogManager, and one line each in linux/main.cpp and
macos/main.mm. It must open a sub-connection: MessageHandle's
TOKEN_REPORT_LOG branch takes the first packet and then calls CancelIO on
that connection, so answering on the main connection would close the main
connection and drop the client offline.
Verified against a server built at 21:17:21 with both clients rebuilt. A
batch get_host_detail over the two A6 records returns succeeded=2 with
per-host data; host_list_processes with ids returns 2 of 2, which exercises
the McpMachine registration point rather than the inline one; a mixed
Windows/Linux batch of get_client_log returns 2 of 2. list_registry with
no path returns the five root keys and path ""; with a path it still
returns its values. get_client_log on Windows goes from 1000 lines to 200
with truncated=true, and limit=3 with filter=ConnAuth yields 28 matched and
3 returned. On Ubuntu 24.04 it returns logs at all, and the client's own
log shows Enter ClientLogThread, TOKEN_REPORT_LOG, then Leave about a
second later when the server cancels the connection - paired, no leak.
The connector still caches an old input schema for get_client_log, so
limit and filter are rejected locally until it reconnects; the defaults
already cover the P0, and this is the same cache problem as the
copy_files_c2c.overwrite entry in the report's P1 list.
docs/Mcp_Design.md section 18 records the implementation and the reasoning;
section 7 of the test report carries the verification table.
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
dc4fd792f6
commit
56a937fabb
8 files changed
+796
-21
No files matched your search
@@ -481,6 +481,9 @@ void CMcpSettingsDlg::OnBnClickedBtnSave()
|
||||
- 写操作工具传 `ids` 直接 `-32602` 拒绝(不逐个执行,避免误操作扩散)。
|
||||
- 返回:`{tool, total, succeeded, failed, results:[{id, ok, data|error, text}]}`;`content` 里是「共 N 台,成功 X 台,失败 Y 台」+ 最多 ~1200 字节的失败明细。
|
||||
- `limit` / `offset` 对每台主机各自生效;批量是串行执行,单台超时会占用整批等待时间。
|
||||
- **outputSchema 必须声明批量形状**:只声明单机形状会让客户端把批量结果判为不合规
|
||||
(`-32602: data must have required property 'host'`)。现在由 `ApplyBatchOutputSchema`
|
||||
统一补成 `anyOf:[单机, 批量]`,见 §18.1。
|
||||
|
||||
### 9.3 N3 `get_keylog`
|
||||
|
||||
@@ -886,3 +889,69 @@ Linux 客户端(`LNX`)早已实现下面这些工具的**线上协议**,
|
||||
- **`remote_keyboard` 的 `type` 仍是 ASCII-only**:Linux 侧 `VKtoKeySym` 把 VK 映射为 keysym 后走 XTest,IME 组合输入做不到;非 ASCII 走 `remote_clipboard` + `Ctrl+V`(Linux 客户端把服务端下发的 GBK 转回 UTF-8 再调 `xclip`/`xsel`,需要 X11 桌面)。
|
||||
- **限制**:纯 Wayland 会话无法抓屏/注入(要 X11 或 XWayland);多显示器仍按 §7.2 拒绝(Linux 客户端心跳里 `RES_RESOLUTION` 依赖 `xrandr`,没有 `xrandr` 的系统上报 `0:0*0`,按「无法判定」放行);`remote_*` 需要安装 `libX11` + `libXtst`,剪贴板需要 `xclip`/`xsel`。
|
||||
- **验收**(Debug 实例 + WSL Ubuntu 24.04 客户端,WSLg `DISPLAY=:0`):`exec_command` 真实退出码(`ls` 不存在路径 → 2)、`-32007`/`-32008` 负例、`grep -v ^#` 放行、输出无提示符噪声;持久终端 `cd`/环境变量保持、`false` → 1、`;` 串联取末条、`close` 幂等;`kill_process` 杀死自己起的 `sleep` 且 `remaining` 为空、`pid 1` 被跳过;`remote_open` 返回 3840x1140、`remote_mouse` 归一化 (0.5,0.5) 落在 (1920,570)、`xev` 观测到按键/按钮成对、剪贴板中文往返 UTF-8 一致。Windows 客户端同批工具回归无变化。
|
||||
|
||||
## 18. 增补(2026-10-29:修掉实测报告的三个 P0)
|
||||
|
||||
`docs/Mcp_Test_Report_2026-10-29.md` 的 P0-1/P0-2/P0-3 有三个共同点:**inputSchema 与
|
||||
outputSchema 不是同一份契约**,或者**输出体积没有上限**。三者都只改服务端(P0-3 的
|
||||
Linux 半边另需客户端补一段)。
|
||||
|
||||
### 18.1 批量只读的 outputSchema(P0-1)
|
||||
|
||||
`tools/call` 带 `ids[]` 时走 `BuildBatchCall`,返回的是
|
||||
`{tool, total, succeeded, failed, skipped, results[]}`;而每个工具声明的 `outputSchema`
|
||||
只有单机形状。客户端按声明校验 `structuredContent`,于是**任何** `ids` 调用都以
|
||||
`-32602: data must have required property 'host'` 失败——inputSchema 明写「支持 ids」,
|
||||
outputSchema 却把它判死,十余个只读工具的批量能力整条不可用。
|
||||
|
||||
修法:`McpInternal::ApplyBatchOutputSchema(tools)` 在 `tools/list` 的最后一步(与
|
||||
`ApplyToolAnnotations` 并列)给 `IsBatchReadOnlyTool` 命中的工具把 `outputSchema`
|
||||
改写成 `{type:object, anyOf:[单机形状, 批量形状]}`。放最后一步是为了让三个注册点
|
||||
(本文件内联 / `McpMachine` / `McpChat`)一视同仁,新增工具只要进批量清单就自动生效。
|
||||
`IsBatchReadOnlyTool` 也随之从 `McpServer.cpp` 移到 `McpInternal.cpp`——清单现在同时被
|
||||
`tools/call`(入口判定)和 `tools/list`(补 schema)使用,两处必须共用一份。
|
||||
|
||||
批量形状里的 `results[].data` 只能声明成 `object`:它就是该工具单机的
|
||||
`structuredContent`,字段随工具而定。
|
||||
|
||||
### 18.2 `list_registry` 的根键分支(P0-2)
|
||||
|
||||
`path` 为空时 `BuildRegistryRoots` 只回 `keys`,而 outputSchema 把 `values` 也列进了
|
||||
`required`——于是文档写的**第一种用法**(省略 path 列根键)必然 `-32602`,AI 必须先猜一个
|
||||
真实键路径才能进注册表。现在 `required` 只保留 `keys`,`values` 在根键分支不返回,并在
|
||||
schema 里写明这一点;同时根键分支补上 `path: ""`,让两个分支返回同一组字段(`path` /
|
||||
`keys`),调用方不必按分支判断。
|
||||
|
||||
### 18.3 `get_client_log` 的体积与平台(P0-3)
|
||||
|
||||
两个症状、两个原因:
|
||||
|
||||
| 平台 | 症状 | 原因 |
|
||||
|---|---|---|
|
||||
| Windows | 返回 90,473 字符,超出客户端工具结果上限 | 快照是客户端 ring buffer 全量(最多 1000 行),工具没有 limit |
|
||||
| Linux/macOS | `-32001` 稳定超时 | 客户端**根本没有处理** `COMMAND_QUERY_LOG`(只有 Windows 的 `ClientLogManager` 有),服务端永远等不到 `TOKEN_REPORT_LOG` |
|
||||
|
||||
服务端:`get_client_log` 新增 `limit`(默认 200,上限 2000)与 `filter`(子串,ASCII
|
||||
不区分大小写),**从末尾往前取**——排障看的是最后发生了什么,不是开机第一行。返回补
|
||||
`lines_total` / `lines_matched` / `lines_returned` / `truncated`。除行数外还有 64 KB
|
||||
字节预算:单行可能是超长的堆栈或报文转储,只按行数截断仍会撑爆结果;末尾一行自己就超
|
||||
预算时回它的尾部并置 `truncated=true`。超时文案也改成可诊断的(点明「客户端版本可能
|
||||
不支持日志上报」并给出两条替代路径),而不是一句 `Timeout waiting for client log`。
|
||||
|
||||
客户端:新增 `common/ClientLogHandler.h`(POSIX 版,与 Windows 的 `CClientLogManager`
|
||||
对应),`linux/main.cpp` 与 `macos/main.mm` 在 `COMMAND_QUERY_LOG` 分支开子连接、首包发
|
||||
`TOKEN_REPORT_LOG` + `Logger::DumpMemoryLogFrom(0)`。**必须走子连接**:服务端
|
||||
`MessageHandle` 的 `TOKEN_REPORT_LOG` 分支取走首包后会 `CancelIO` 关掉这条连接,回在
|
||||
主连接上就是把主连接关掉(客户端当场掉线)。
|
||||
|
||||
### 18.4 验证与未覆盖
|
||||
|
||||
- 服务端 21:17:21 构建 + 两端客户端重编后实测:`ids` 批量(`get_host_detail` /
|
||||
`host_list_processes` / `get_client_log`)全部 `succeeded=全数`;`list_registry` 省略
|
||||
`path` 返回 5 个根键;`get_client_log` 在 Windows 上 `1000→200` 行(`truncated=true`)、
|
||||
在 Linux 上正常返回 8 行,且客户端日志里 `Enter/Leave ClientLogThread` 成对、无泄漏。
|
||||
明细见测试报告 §7。
|
||||
- `get_activity_history` 仍是全量返回(实测 501 条),与 P0-3 同一类问题,但不在本次
|
||||
三个 P0 内,留待下一轮。
|
||||
- 连接器会缓存 `tools/list`,`limit`/`filter` 在重连前对模型不可见(默认参数已覆盖
|
||||
P0-3 的场景),与既有的 `overwrite` 缓存问题同源。
|
||||
Reference in new issue
Block a user