Feature: Add upload_file MCP tool (V2 protocol, main-connection upload)

Implement the P2 upload_file tool to push a local file or directory from the
master to an online Windows host over the existing V2 file-transfer protocol.
The server drives FileBatchTransferWorkerV2 synchronously on the main
connection through a headless callback, reuses the list_files chain for the
overwrite pre-check, and is gated by McpFileTransfer=1 plus McpReadonly=0.

The client main connection never initialized the file-transfer module, so
g_status stayed 0 and RecvFileChunkV2 silently dropped every chunk, truncating
uploads to zero bytes. Add a once-per-process lazy InitFileUpload in the
COMMAND_SEND_FILE_V2 handler that mirrors the FileManager init; the destructor
deliberately does not Uninit so g_status remains 1 across reconnects.

Update the design doc to record the client-side change and correct the
upload_file description to state that sha256 is not returned (V2 has no
receiver-to-sender ACK; integrity is checked client-side and logged only).

Co-Authored-By: deepseek-v4-pro
This commit is contained in:
yuanyuanxiang
2026-08-31 22:43:16 +02:00
parent 5c77f5ce14
commit 6bcd593b6d
4 changed files with 531 additions and 12 deletions

View File

@@ -218,6 +218,11 @@ public:
const std::string& localDir, const std::string& remotePath,
bool overwrite);
// 登记上传会话false = 该 host 已有文件会话或一次性挂起请求。upload 走主连接、
// 工具线程同步驱动 FileBatchTransferWorkerV2会话仅为单设备单传输互斥标记
// (无 fmSubCtx/streamSubCtxClearFileTransfer 对空指针安全)。
bool BeginFileUpload(uint64_t device_id);
// TOKEN_DRIVE_LIST识别 download_file存文件管理器子链接并下发 CMD_DOWN_FILES_V2。
// 返回 true=已接管(保持子链接,收尾由 ClearFileTransferfalse=会话已清理(调用方 CancelIO
bool OnDownloadDriveList(uint64_t device_id, context* fmSubCtx);
@@ -317,8 +322,8 @@ private:
// ===== P6文件传输会话受 m_FileXferMutex 保护;单设备单传输)=====
struct FileTransferSession {
std::string tool; // 恒为 "download_file"
std::string localDir; // 本机保存目录ANSI结尾 '\'
std::string tool; // "download_file" / "upload_file"
std::string localDir; // download本机保存目录ANSI结尾 '\'
std::string remotePath; // 客户端远程路径ANSI发 CMD_DOWN_FILES_V2 用)
bool overwrite = false; // 是否覆盖已存在文件
context* fmSubCtx = nullptr; // 文件管理器子链接(下发 CMD_DOWN_FILES_V2