Feature(mcp): add http_probe for private-network HTTP checks

Run an HTTP/HTTPS request inside a shell on a managed host and return a
structured result: status code, headers, body (UTF-8 or base64), size and
elapsed time, so interface health on the host or its subnet can be checked
without a full remote-control session.

The safety boundary is hard-coded on the server, not in the shell script:
only http/https and IP literals (or localhost); only loopback and private
ranges (127/8, ::1, 10/8, 172.16/12, 192.168/16) are accepted; redirects
are not followed; the body is capped at 64KB; TLS certificates are
verified. Domain names are refused on purpose - resolving them on the
server would probe the wrong network.

Windows runs a single-line PowerShell 2.0-compatible script based on
HttpWebRequest. Accept/User-Agent/Referer are mapped to their dedicated
properties because .NET rejects them through Headers.Add. Linux uses curl
with temp files.

Payloads cross the terminal channel as 56-character base64 chunks with a
declared byte length. ConPTY re-emits the boundary character of lines
wider than 80 columns, so single-line base64 arrives corrupted; the length
check converts any remaining loss into an explicit error rather than
silent garbage.

The tool reuses an existing persistent terminal session. Sessions it
creates itself are closed after the command and kept only when the probe
timed out while still running. Platform gating: Windows and Linux only.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 16:52:17 +01:00
1 parent 697044d84b
commit 613aa7291a
3 files changed
+992 -2

No files matched your search

+117 -1
View File
@@ -15,7 +15,7 @@
],
"version": 2,
"protocolVersion": "2025-06-18",
"toolCount": 64,
"toolCount": 65,
"tools": [
{
"name": "list_online_hosts",
@@ -3027,6 +3027,122 @@
"type": "object"
}
},
{
"name": "http_probe",
"description": "在指定在线 Windows 或 Linux 主机上请求一个 HTTP/HTTPS 地址,返回结构化结果(状态码、响应头、响应体、耗时),用于探测主机上或同网段的业务接口健康。url 必须是 http:// 或 https:// + IP 字面量(或 localhost)+ 可选 :端口 + 路径;只允许私网/回环地址(127.0.0.0/8、::1、10/8、172.16/12、192.168/16)与 localhost,域名和公网地址一律拒绝(域名要通过被管主机解析才有意义,服务端解析自己的 DNS 是错的)。默认 GET;method 支持 GET/POST/PUT/DELETE/HEAD/PATCH/OPTIONS;headers 为名→值的字符串对象;body 为请求体(≤2048 字节,按 UTF-8 发送)。不跟随重定向(3xx 原样返回,Location 在 headers 里);https 校验证书,自签名证书会失败。响应体最多返回 max_bytes(默认与上限均为 64KB),超出置 truncated=true;响应体是合法 UTF-8 时放在 body,否则 body 为空并给出 body_base64。实现上复用终端通道(需 McpTerminal=1、McpReadonly=0):会复用该主机已有的持久终端会话;没有则内部打开一个、用完即关(超时仍在跑时保留,便于轮询)。该主机上已有命令在跑或输出未取完时返回 -32003。",
"gate": "terminal",
"write": true,
"platforms": [
"win",
"lnx"
],
"impl": "mfc",
"inputSchema": {
"properties": {
"body": {
"description": "请求体(可选,≤2048 字节),按 UTF-8 发送;POST/PUT/PATCH 时常用",
"type": "string"
},
"headers": {
"additionalProperties": {
"type": "string"
},
"description": "请求头(对象,名→值都是字符串),如 {\"Authorization\":\"Bearer x\"};序列化后上限 512 字节,不接受 Content-Length;Windows 上少数受限头(如 Connection、Expect、Range)会被系统拒收,Accept/User-Agent/Referer 已单独支持",
"type": "object"
},
"id": {
"description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段",
"type": "string"
},
"max_bytes": {
"description": "响应体最多返回的字节数(默认 65536,范围 1-65536),超出置 truncated=true",
"type": "integer"
},
"method": {
"description": "HTTP 方法,默认 GET",
"enum": [
"GET",
"POST",
"PUT",
"DELETE",
"HEAD",
"PATCH",
"OPTIONS"
],
"type": "string"
},
"timeout_ms": {
"description": "请求超时毫秒数(默认 10000,范围 1000-60000);工具等待 = 该值 + 20 秒(含 shell 启动)",
"type": "integer"
},
"url": {
"description": "要请求的地址:http:// 或 https:// + IP 字面量(或 localhost)+ 可选 :端口 + 路径,如 http://127.0.0.1:8003/health",
"type": "string"
}
},
"required": [
"id",
"url"
],
"type": "object"
},
"outputSchema": {
"properties": {
"body": {
"description": "响应体(响应体是合法 UTF-8 时才填;否则为空,看 body_base64)",
"type": "string"
},
"body_base64": {
"description": "响应体的 base64(仅 body_encoding=base64 时提供,非 UTF-8 的二进制响应)",
"type": "string"
},
"body_bytes": {
"description": "本次返回的响应体字节数(被截断时即 max_bytes 内实际读到的)",
"type": "integer"
},
"body_encoding": {
"description": "body 的编码:utf-8 或 base64",
"type": "string"
},
"elapsed_ms": {
"description": "请求耗时毫秒(Windows 在 PowerShell 内计时;Linux 为服务端整轮计时)",
"type": "integer"
},
"headers": {
"description": "响应头(名→值;同名多值用逗号拼接)",
"type": "object"
},
"ok": {
"description": "true = 2xx/3xx;3xx 未跟随重定向",
"type": "boolean"
},
"status": {
"description": "HTTP 状态码",
"type": "integer"
},
"truncated": {
"description": "true = 响应体超过 max_bytes,只返回了前缀",
"type": "boolean"
},
"url": {
"description": "回显请求的 url",
"type": "string"
}
},
"required": [
"status",
"ok",
"headers",
"body",
"body_encoding",
"body_bytes",
"truncated",
"elapsed_ms",
"url"
],
"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 复核。",