Feature: Turn client failure reports into branchable MCP errors
Wire the four new failure tokens into MessageHandle and translate them in the tool builders, so the three previously silent failures now return a code an agent can branch on: list_services on a non-elevated client is -32010 in well under a second instead of a 20 s timeout, list_files and list_registry distinguish a missing path or key (-32009) from an empty one, and download_file no longer waits for the stall watchdog when the remote path does not exist. Access denied gets its own code, -32010, and the win32 code is kept in the message for every case. TakeRegError fills both registry wait flags in one packet because a failing client sends no subkey or value packet at all. OnDownloadError sets the session error without cancelling the file-manager sub-connection, which stays owned by ClearFileTransfer. ListRemoteTopLevelNames treats "not found" as "directory not created yet" so uploading into a fresh directory keeps working now that the client reports it. Also converge the error codes that were overloaded: a multi-monitor host is a capability limit, not a parameter mistake, so remote_open reports -32005 instead of -32008. The tool wait timeout moves from a compile-time constant to McpToolTimeoutMs in settings.ini (default 20000, clamped to 1-600 s), which makes it possible to tune without a rebuild. The smoke test gains the three reproducible negatives. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
315a0855dc
commit
3b1626f415
4 files changed
+211
-25
No files matched your search
@@ -139,6 +139,10 @@ public:
|
||||
// MessageHandle(TOKEN_REG_PATH / TOKEN_REG_KEY) 调用:两包都到齐后置 done 并唤醒等待者。
|
||||
void TakeRegPath(uint64_t device_id, const BYTE* data, ULONG len);
|
||||
void TakeRegKey(uint64_t device_id, const BYTE* data, ULONG len);
|
||||
// MessageHandle(TOKEN_REG_ERROR) 调用:键打不开(不存在/拒绝访问)。失败时客户端只发这一包,
|
||||
// 故一次置满 pathDone/keyDone/done,让 WaitPendingRegistry 立即返回;错误包原样存进 regPath,
|
||||
// 由 BuildListRegistry 读首字节转译成 -32009/-32010。
|
||||
void TakeRegError(uint64_t device_id, const BYTE* data, ULONG len);
|
||||
|
||||
// 工具线程:等待注册表两包(子键 + 值);成功返回 true 并把两包分别写入 out,超时返回 false。
|
||||
bool WaitPendingRegistry(uint64_t device_id, std::vector<BYTE>& subkeys,
|
||||
@@ -272,6 +276,11 @@ public:
|
||||
// COMMAND_SEND_FILE_V2:解析 chunk,路径校验 + overwrite 判定 + 落盘(RecvFileChunkV2)。
|
||||
void OnFileChunkV2(uint64_t device_id, context* streamSubCtx, const BYTE* buf, ULONG len);
|
||||
|
||||
// TOKEN_DOWNLOAD_ERROR:客户端在建立传输子链接之前就判定「无可传输文件」(远端路径不存在/
|
||||
// 不可访问)。置会话 error=1005(不存在)/1006(拒绝访问)/1007(其他)并唤醒等待线程。
|
||||
// 不在此 CancelIO:文件管理器子链接由 ClearFileTransfer 统一收尾。
|
||||
void OnDownloadError(uint64_t device_id, context* fmSubCtx, const BYTE* buf, ULONG len);
|
||||
|
||||
// COMMAND_FILE_COMPLETE_V2:SHA-256 校验(HandleFileCompleteV2)+ 完成判定。
|
||||
void OnFileCompleteV2(uint64_t device_id, const BYTE* buf, ULONG len);
|
||||
|
||||
@@ -279,7 +288,8 @@ public:
|
||||
// 无论成败,files 都会返回已见文件的落盘路径(成功=完整文件,失败=供调用方删半成品)。
|
||||
// 调用方随后必须调 ClearFileTransfer 收尾(擦会话 + CancelIO 子链接)。
|
||||
bool WaitFileTransferDone(uint64_t device_id, int timeoutMs,
|
||||
std::vector<FileTransferEntry>& files, int& skipped, int& error);
|
||||
std::vector<FileTransferEntry>& files, int& skipped, int& error,
|
||||
DWORD* errorDetail = nullptr);
|
||||
|
||||
// 收尾:擦会话 + 锁外 CancelIO 文件管理器/流式两条子链接(幂等)。
|
||||
void ClearFileTransfer(uint64_t device_id);
|
||||
@@ -348,6 +358,12 @@ public:
|
||||
void SetKeylogEnabled(bool enabled) { m_keylogEnabled = enabled; }
|
||||
bool IsKeylogEnabled() const { return m_keylogEnabled; }
|
||||
|
||||
// ===== 工具默认等待超时([settings] McpToolTimeoutMs,ini-only 键)=====
|
||||
// 慢主机上 20s 固定的工具超时太紧;调到 60s 更实用。范围 clamp 到 [1000, 120000]。
|
||||
// 改动需重启服务端生效(与其它 Mcp* 开关一致)。
|
||||
void SetToolTimeoutMs(int ms);
|
||||
int ToolTimeoutMs() const { return m_toolTimeoutMs; }
|
||||
|
||||
bool BeginKeylogSession(uint64_t device_id, const std::string& tool, context* mainCtx);
|
||||
|
||||
enum class KeylogWaitResult { Ok, Timeout, Closed };
|
||||
@@ -607,7 +623,9 @@ private:
|
||||
uint32_t directoryCount = 0; // 目录项计数(目录不发 COMPLETE 包)
|
||||
uint32_t filesDone = 0; // 已完成的文件数(含跳过的)
|
||||
bool done = false; // 全部完成或出错
|
||||
int error = 0; // 0=ok;8=哈希不匹配;1001=路径逃逸;1002=超时;1003=流式子连接断线;1004=停滞(看门狗)
|
||||
int error = 0; // 0=ok;8=哈希不匹配;1001=路径逃逸;1002=超时;1003=流式子连接断线;
|
||||
// 1004=停滞(看门狗);1005=远端路径不存在;1006=拒绝访问;1007=其他下载失败
|
||||
DWORD errorDetail = 0; // error=1005/1006/1007 时的 win32 码(原样带进文案,便于分支/排查)
|
||||
std::map<uint32_t, FileTransferEntry> fileEntries; // fileIndex → {path,size,sha256}
|
||||
std::set<uint32_t> skipIndexes; // overwrite=false 跳过的 fileIndex
|
||||
std::vector<FileTransferEntry> skipped; // 跳过的文件(供输出)
|
||||
@@ -669,6 +687,7 @@ private:
|
||||
bool m_machineEnabled = false; // P8 主机管理族总开关(默认关;16 个 host_* 工具)
|
||||
bool m_machineDangerousEnabled = false; // P8 高风险子集(冻结/解冻进程、停止/重启服务)
|
||||
bool m_keylogEnabled = false; // N3 键盘记录开关(默认关;get_keylog)
|
||||
int m_toolTimeoutMs = 20000; // 工具默认等待超时(McpToolTimeoutMs,见 SetToolTimeoutMs)
|
||||
};
|
||||
|
||||
// 全局访问器(仿 WebService(),见 WebService.h 末尾)
|
||||
|
||||
Reference in new issue
Block a user