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
@@ -6867,6 +6867,25 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
ContextObject->CancelIO(); // 无论是否命中,用完即关(无 MFC 对话框接管此子链接)
|
||||
break;
|
||||
}
|
||||
case TOKEN_SEARCH_FILE_LIST: { // 搜索结果【B2:仅 MCP 无头搜索会到达】
|
||||
// 有挂起的 search_file 且是本连接发的 → 收下这一包;否则是已被放弃的旧搜索
|
||||
// (工具线程已超时返回部分结果)的尾包,原地丢弃即可。
|
||||
// 注意:这里绝不能 CancelIO。客户端搜索线程持有 CFileManager 的 this 指针,
|
||||
// 且关连接后 ~CFileManager(client/FileManager.cpp)只会 m_bSearching=false 并
|
||||
// 最多等 5s;线程若正在 FindFirstFile 里就会继续跑。子连接统一等
|
||||
// TOKEN_SEARCH_FILE_FINISH 再关——那时客户端搜索线程已经退出。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
McpServer().OnSearchFileRecords(devId, ContextObject, szBuffer, len);
|
||||
break;
|
||||
}
|
||||
case TOKEN_SEARCH_FILE_FINISH: { // 搜索结束【B2】
|
||||
// 客户端是「先停搜索线程、再发 FINISH」(自然结束或收到 COMMAND_FILES_SEARCH_STOP
|
||||
// 后下一轮循环退出),所以 FINISH 到达时关子连接是安全的。挂起命中则同时唤醒工具线程。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
McpServer().FinishSearchFile(devId, ContextObject);
|
||||
ContextObject->CancelIO();
|
||||
break;
|
||||
}
|
||||
case TOKEN_TALK_START: { // 发送消息【x】
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENTALKDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user