Files
verify/docs/mcp.md
T
Hermes Agent a90f394eb1
Docker Build / Build and Push Docker Image (push) Successful in 1m7s
Docker Build / Deploy to Server (push) Successful in 3s
feat(mcp): 内置 MCP 服务端(streamable-http)
- 新增 backend/internal/router/mcp:MCP 端点 /api/v1/mcp,Bearer/X-MCP-Token/?token 鉴权
- 只读工具:list_apps / list_versions / get_version / simulate_check_update /
  list_cards / app_stats / list_devices / list_logs
- 写工具(mcp.allow_write=true):publish_version / deprecate_version,默认 dry_run,
  写操作落 logs 审计
- simulate_check_update 复刻 check-update 判定规则,可预判“同版本号重传不生效”
- 导出 app.BuildManifest 复用清单计算口径,避免逻辑漂移
- 构建环境 go 1.21 -> 1.23(mcp-go 要求),Dockerfile 同步
- 文档 docs/mcp.md
2026-11-21 00:31:03 +08:00

69 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MCP(Model Context Protocol)端点
verify 内置的 MCP 服务端,走 **Streamable HTTP**,默认路径 `/api/v1/mcp`。
让 Hermes / Claude 等 MCP 客户端可以直接查应用、版本、卡密、设备、日志,并在允许时发布/废弃版本。
## 开关与鉴权
在 `data/config.yaml` 增加(不配 `mcp.token` 时端点不挂载,避免裸奔):
```yaml
mcp:
enabled: true
path: "/api/v1/mcp"
token: "<随机长串>" # openssl rand -hex 32 生成
allow_write: false # true 才注册发布/废弃等写工具
```
鉴权(三选一,值必须等于 `mcp.token`):
- `Authorization: Bearer <token>`
- `X-MCP-Token: <token>`
- `?token=<token>`
## 工具清单
只读(始终可用):
| 工具 | 作用 |
|---|---|
| `verify_list_apps` | 应用列表(id / app_key / 状态 / 心跳配置) |
| `verify_list_versions` | 按应用分页列版本,含 `edit_gap_seconds`(判断是否被编辑过) |
| `verify_get_version` | 单版本详情 + 文件清单 + `manifest_hash` + `content_stored` |
| `verify_simulate_check_update` | **模拟客户端 check-update**,直接回答"这个版本的客户端会收到什么" |
| `verify_list_cards` | 卡密分页查询 |
| `verify_app_stats` | 用户数 / 设备数 / 在线设备数 / 卡密状态分布 / 版本数 |
| `verify_list_devices` | 设备分页列表 |
| `verify_list_logs` | 最近日志 |
写操作(需 `mcp.allow_write: true`,默认 `dry_run=true` 只预演):
| 工具 | 作用 |
|---|---|
| `verify_publish_version` | 发布 draft/deprecated 版本;forced 策略会 supersede 更早版本 |
| `verify_deprecate_version` | 废弃已发布版本并恢复被它取代的版本 |
写操作会往 `logs` 表写一条审计(`action` 以 `mcp.` 开头)。
## 为什么要有 `verify_simulate_check_update`
版本更新判定的规则是「按版本号字符串匹配记录」+「与最高 ID 的已发布版本比较 ID」。
这带来一个反直觉后果:**在同一个版本号上重新上传文件,客户端不会被判为需要更新**。
`simulate_check_update` 用与线上 handler 相同的规则算出结果,能提前发现"传了新包但客户端不来拿"。
## 客户端配置示例(Hermes)
```yaml
mcp_servers:
verify:
url: "https://<面板域名>/api/v1/mcp"
headers:
Authorization: "Bearer <token>"
```
## 注意
- 该端点复用准备容器同一条 HTTP 通道,请只在内网或带 TLS 的反代后暴露。
- 所有查询都有分页上限(默认 20,最大 100),避免一次拉爆上下文。
- 工具实现复用 `app.BuildManifest`,与面板/客户端清单口径一致,避免两套逻辑漂移。