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:
1 parent
0378e96470
commit
697044d84b
4 files changed
+663
-10
No files matched your search
+102
-1
@@ -15,7 +15,7 @@
|
||||
],
|
||||
"version": 2,
|
||||
"protocolVersion": "2025-06-18",
|
||||
"toolCount": 63,
|
||||
"toolCount": 64,
|
||||
"tools": [
|
||||
{
|
||||
"name": "list_online_hosts",
|
||||
@@ -2926,6 +2926,107 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "read_file",
|
||||
"description": "按字节读取指定在线主机上的一个文本文件(分页 + 编码识别 + 整文件 SHA-256),只支持单个普通文件。path 为远程绝对路径:Windows 用 D:\\cfg\\app.ini 这类盘符路径,Linux/macOS 用 /etc/app.conf 这类 POSIX 路径。offset 支持负数(-200 = 最后 200 行,看日志尾部);limit 为最多返回的行数(默认 2000);encoding=auto 时按 BOM → UTF-8 合法性 → GBK 回退识别,也可显式传 utf-8 / gbk / latin1;max_bytes 限制本次返回的文本字节数(默认 262144=256KB,超出按 truncated=true 截断)。目录、或大于 2MB 的文件返回 -32602(请改用 download_file)。返回 size/encoding/eol/lines_total/offset/lines_returned/truncated/text/sha256(sha256 是整个文件,不是本次片段)。读配置文件/日志时用它,不要用 exec_command 的 type/Get-Content(GBK 会乱码、行尾会被归一化)。",
|
||||
"gate": "file_transfer",
|
||||
"platforms": [
|
||||
"win",
|
||||
"lnx",
|
||||
"mac"
|
||||
],
|
||||
"impl": "mfc",
|
||||
"inputSchema": {
|
||||
"properties": {
|
||||
"encoding": {
|
||||
"description": "auto(默认,按 BOM → UTF-8 合法性 → GBK 回退)/ utf-8 / gbk / gb18030 / latin1",
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段",
|
||||
"type": "string"
|
||||
},
|
||||
"limit": {
|
||||
"description": "最多返回的行数(1..200000,默认 2000)",
|
||||
"type": "integer"
|
||||
},
|
||||
"max_bytes": {
|
||||
"description": "本次返回文本的字节上限(1024..2097152,默认 262144=256KB),超出按 truncated=true 截断",
|
||||
"type": "integer"
|
||||
},
|
||||
"offset": {
|
||||
"description": "起始行(0 基)。负数表示从末尾倒数:-200 = 最后 200 行;默认 0",
|
||||
"type": "integer"
|
||||
},
|
||||
"path": {
|
||||
"description": "远程文件的绝对路径。Windows 用 D:\\cfg\\app.ini 这类盘符路径;Linux/macOS 用 /etc/app.conf 这类 POSIX 路径。必须是单个普通文件(目录或大于 2MB 的文件返回 -32602)",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"path"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"outputSchema": {
|
||||
"properties": {
|
||||
"encoding": {
|
||||
"description": "实际使用的编码:utf-8 / utf-16le / utf-16be / gbk / gb18030 / latin1",
|
||||
"type": "string"
|
||||
},
|
||||
"eol": {
|
||||
"description": "行尾风格:crlf / lf / cr / mixed / none",
|
||||
"type": "string"
|
||||
},
|
||||
"lines_returned": {
|
||||
"description": "本次返回的行数",
|
||||
"type": "integer"
|
||||
},
|
||||
"lines_total": {
|
||||
"description": "文件总行数(末尾换行不计空行)",
|
||||
"type": "integer"
|
||||
},
|
||||
"offset": {
|
||||
"description": "本次实际起始行(负数已换算成绝对行号)",
|
||||
"type": "integer"
|
||||
},
|
||||
"path": {
|
||||
"description": "远程路径(原样回传)",
|
||||
"type": "string"
|
||||
},
|
||||
"sha256": {
|
||||
"description": "整个文件的 SHA-256(不是本次片段),可与 download_file 的结果比对",
|
||||
"type": "string"
|
||||
},
|
||||
"size": {
|
||||
"description": "文件总字节数",
|
||||
"type": "integer"
|
||||
},
|
||||
"text": {
|
||||
"description": "文件内容(UTF-8,行以 \\n 分隔,已去掉 BOM)",
|
||||
"type": "string"
|
||||
},
|
||||
"truncated": {
|
||||
"description": "true=还有内容没返回(超出 limit / max_bytes),可调整 offset 继续读",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"size",
|
||||
"encoding",
|
||||
"eol",
|
||||
"lines_total",
|
||||
"offset",
|
||||
"lines_returned",
|
||||
"truncated",
|
||||
"text",
|
||||
"sha256"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "upload_file",
|
||||
"description": "把主控本机文件或目录上传到指定在线主机的目录(V2 协议,主连接发送)。支持 Windows 与 Linux/macOS 主机;local_path 为主控本机绝对路径(文件或目录,目录递归上传);remote_dir 为远程保存目录(不存在自动创建),Windows 用 C:\\uploads 这类盘符路径,Linux/macOS 用 /home/user/uploads 这类绝对 POSIX 路径;overwrite=false 时跳过 remote_dir 下已存在的同名顶层项。返回 files[{path,size,sha256}] 与 total_bytes/skipped/receiver_ack;sha256 恒为空(发送端不计算)。receiver_ack=true 表示目标端已确认写入(Linux 客户端回执),false 表示目标端没有回执(Windows 目标、老客户端或 macOS),此时需要确证请用 list_files 复核。",
|
||||
|
||||
Reference in new issue
Block a user