Feature(mcp): add read_file for byte-accurate remote text reads

read_file fetches a single remote file through the existing V2 download
channel into a per-call temp directory, decodes it, and deletes the temp
files on every exit path. It returns the file size, detected encoding, EOL
style, total line count, the requested slice (negative offset counts from
the end), a truncation flag and the whole file's SHA-256.

Encoding auto-detection follows BOM -> UTF-8 validity -> GBK fallback, and
utf-8/gbk/gb18030/latin1 can be forced. Files above 2MB and directories are
rejected from the first chunk, so nothing is written to disk for them.
The tool is gated by McpFileTransfer only: it never writes to the remote
host, so it stays available in readonly mode.

The V2 receive path now serves both download_file and read_file.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 16:11:27 +01:00
1 parent 0378e96470
commit 697044d84b
4 files changed
+663 -10

No files matched your search

+3
View File
@@ -64,6 +64,8 @@ GATE = {
# ---- file_transfer ----
"download_file": ("file_transfer", True, False),
# read_file 只读远端(不写),因此不受 readonly 约束
"read_file": ("file_transfer", False, False),
"upload_file": ("file_transfer", True, False),
"copy_files_c2c": ("file_transfer", True, False),
@@ -173,6 +175,7 @@ PLATFORMS = {
# 需要 CLIENT_CAP_V2;三个桌面平台的 DefaultCaps() 都含 V2
"download_file": _TRIO,
"read_file": _TRIO,
"upload_file": _TRIO,
# 远程控制:Windows / Linux 全功能;Android 只支持整屏目标,输入翻译成触摸与全局动作