Fix(mcp): list the whole directory before paging list_files

list_files stopped parsing at 500 entries, so a larger directory reported
total=500 with hasMore=false and offsets past 500 returned nothing: the model
was told a false limit and could not reach the tail. Parse the full
TOKEN_FILE_LIST payload (100000 cap only to bound a pathological directory),
page over it, and report truncated=true plus a summary note when the cap hits.

Only an empty path now means list drives. Windows "." "/" "\" are normalized
to empty in BuildListFiles, while Linux/macOS "/" is a real root directory and
is listed; OnDriveList no longer keeps its own copy of the magic-path rule.

The file-manager channel carries GBK both ways (Windows FindFirstFileA;
common/FileManager.h runs gbkToUtf8 on incoming paths, utf8ToGbk on outgoing
names). The old CP_UTF8 choice for LNX/MAC decoded GBK names wrongly and sent
UTF-8 paths to a client that treats them as GBK. Paths now go out as GBK, or
as raw UTF-8 when GBK cannot represent them (the client's iconv then passes
the bytes through). Names decode GBK-first, UTF-8 on failure: UTF-8-first
misreads ~18% of common hanzi whose GBK bytes are also valid UTF-8.

Go's server gets the same contract: 100000 cap, truncated in
structuredContent, and the cap check after a real record so an exact-cap
listing with trailing padding is not called truncated. tools_minimal.json is
regenerated; the Go truncation test and the design doc are updated.

Debug server builds; check_platform_table, gen_go_tools --check and
go test ./... pass. The Release instance was not rebuilt or restarted.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-13 12:13:20 +01:00
1 parent 42dd70fe20
commit 5e012019ba
6 files changed
+137 -40

No files matched your search

+1 -1
View File
@@ -511,7 +511,7 @@ void CMcpSettingsDlg::OnBnClickedBtnSave()
- `structuredContent` 统一附 `total` / `totalAll` / `offset` / `limit` / `hasMore`,与 `McpMachine.cpp` 既有约定一致(`host_list_*` / `list_network_connections` 本来就是这样)。
- `content` 摘要统一为「共 N <单位>,本次返回第 a-b 条(还有更多,可用 offset 继续取)。」;`hasMore=false` 时不再出现「继续取」的误导提示;`offset` 越界时明确写「offset 超出范围,本次返回 0 条」。
- 实现集中在 `McpInternal.h/.cpp`:`PageWindow` / `ResolvePageWindow` / `ApplyPageWindow` / `WritePageFields` / `AppendPagingProps` / `PageSummary`。
- `list_files` 仍受服务端 `ParseFileList` 的 500 条硬限制(`total=500` 且原目录确有更多条目时表示截断,不是服务端分页)。客户端侧不截断、按需扩缓冲一次性回全量;本轮未加 `truncated` 标记(要加得改服务端 `ParseFileList` 的调用约定),仍靠「`total=500` 且 `hasMore`」判断。
- `list_files` 整目录解析后再分页:`ParseFileList` 的上限是 100000 条,只用于兜住病态目录;到上限时 `structuredContent.truncated=true`,摘要与 `total` 也会说明 `total` 只是上限内的数量。`total` / `hasMore` 反映真实目录条目数,`offset` 可翻到 500 条之后。分页由服务端完成(`limit` 默认 100、上限 1000),客户端仍一次性回全量。
---