Fix(mcp): put listing rows and host ids into text blocks
MCP clients that surface only content[].text saw just count summaries from list_hosts and get_audit_log; the 64-bit host id lived only in structuredContent. Without the id, read_file, get_host_detail and terminal_exec cannot be addressed, so the tools were unusable from those clients. Append a tab-separated table after the summary for every list-shaped local tool: list_hosts (id first, then name/ip/group/os/online/clientType/ last_seen), get_audit_log (time/type/msg), list_files (drives and directory entries) and get_host_detail (compact host JSON; id/ok/detail rows for a batch call). Only the returned page is rendered, cells are flattened to one line, and the truncation note stays on its own line before the table. structuredContent is unchanged and remains the authoritative copy. Tests cover row contents, paging, escaping and truncation ordering; a live run against a Debug client confirmed the id is now visible in text. The MFC server needs no equivalent change: BuildResult already appends the full structuredContent as a second text item, so text-only clients there already receive host ids. Go's envelope emits a single text item, which is why the rows go into it. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
70556391dd
commit
3d18b2119a
5 files changed
+197
-4
No files matched your search
@@ -246,6 +246,30 @@ M5 之前传任一参数都返回 `-32005` 并在 message 里点名。细节见
|
||||
**整文件上限 2 MiB**(`YAMA_MCP_READ_MAX`):V2 下载没有区间参数,只能整文件拉,超过就拒绝
|
||||
(`-32602`)。`offset`/`limit` 是下载后的窗口裁剪,绕不过这个门。
|
||||
|
||||
### 3.3 文本块(`content[].text`)
|
||||
|
||||
`structuredContent` 是权威数据,但部分 MCP 客户端只把 `content[].text` 交给模型,
|
||||
`structuredContent` 不会出现在模型上下文里。因此列表类工具的文本块不能只有「共 N 台」
|
||||
这样的汇总——主机 64 位 id 是 `read_file`、`get_host_detail`、`terminal_exec` 等后续调用
|
||||
的寻址键,模型拿不到就等于工具不可用。
|
||||
|
||||
| 工具 | 汇总行之后 |
|
||||
|---|---|
|
||||
| `list_hosts` | 表头 `id name ip group os online clientType last_seen`,随后每台一行 |
|
||||
| `get_host_detail` | 单台:主机 JSON(compact);批量:`id ok detail`,成功行是主机 JSON,失败行是错误信息 |
|
||||
| `list_files` | 盘符 `drive typeName fileSystem totalMB freeMB`;目录 `name isDir size mtime` |
|
||||
| `get_audit_log` | `time type msg`,`msg` 是去掉信封字段后的 compact JSON |
|
||||
|
||||
列用制表符分隔,首列一定是后续调用的寻址键(主机 id / 文件名)。单元格内的制表符与换行
|
||||
替换成空格,精确值以 `structuredContent` 为准;空值显示 `-`。分页只渲染当前页,不会把
|
||||
全表塞进文本块。
|
||||
|
||||
MFC 端不需要同样的改动:`McpInternal.cpp` 的 `BuildResult` 会把整个
|
||||
`structuredContent` 作为**第二个** `type:"text"` 项追加到 `content`(除非 builder 用
|
||||
`SetStructuredTextPayload` 指定了更小的载荷)。实测线上 `list_hosts` / `get_audit_log`
|
||||
的 `content[1]` 已是完整 JSON(含主机 id),文本型客户端本来就能拿到。Go 的
|
||||
`newToolResult` 只写一个 text 项,所以把行放进第一项。
|
||||
|
||||
---
|
||||
|
||||
## 4. 端点
|
||||
|
||||
Reference in new issue
Block a user