MCP 连接指南
Argus 是一个 MCP(Model Context Protocol)Server:Claude Code、Cline、Zed、Claude Desktop 等 AI Agent 连接后,可以用自然语言完成证书查询、签发、续期、吊销、部署等完整生命周期管理。
MCP 是 Anthropic 发起的开放标准。Agent 通过它"发现"Argus 提供的工具(tools),按需调用。
快速开始
在 Argus 服务器本机执行(Claude Code):
claude mcp add argus -- argus mcp --config /etc/argus/config.yaml连接成功后,直接用自然语言提问即可:
列出 30 天内过期的证书 给 todo.example.com 签一张证并部署到 web-prod-01 吊销 legacy.example.com 的证书
两种模式
本地模式(推荐先用这个)
Agent 与 Argus 装在同一台机器,argus mcp 以子进程被 Agent 拉起,直连本机数据库:
argus mcp --config /etc/argus/config.yaml- 无需网络端口、无需 token
- 进程权限 = 运行用户权限(与 CLI 同等信任模型)
- 可用
--scopes收敛工具集(见下文)
远程模式
Agent 在运维电脑上,管理 Argus 服务器。经服务端 REST API 代理:
argus mcp --config /etc/argus/config.yaml \
--server https://cert.example.com \
--token st_xxxxxxxxtoken 也可用环境变量 ARGUS_API_TOKEN 提供(避免出现在 shell 历史里):
export ARGUS_API_TOKEN=st_xxxxxxxx
argus mcp --server https://cert.example.com远程模式下每个工具调用都由服务端强制校验 token 的 scope 与角色,客户端无法绕过。
方式三:HTTP 直连(客户机不装二进制,推荐)
如果客户机不安装 argus 二进制,让服务端直接开放 MCP 的 HTTP 端点:
服务端
config.yaml打开开关:yamlmcp: enabled: true # 开放 /mcp 端点(Streamable HTTP) allow_key_download: false # 是否注册「下载证书」工具(含私钥)重启服务,客户端连
https://cert.example.com/mcp——不需要在客户机装任何东西。
安全性:与 Web/REST 同端口同 TLS,复用 API Token 认证;每个工具调用按 token 的 scope 强制校验 (token 看不到自己无权调用的工具,调用也会被拒);跨源防护自动拦截浏览器跨源请求(DNS rebinding)。
stdio 模式(方式一/二)与 HTTP 模式可同时开:同机 Agent 用 stdio 更省事,远程/免安装客户机用 HTTP。
客户端配置示例
Claude Code
# 本地
claude mcp add argus -- argus mcp --config /etc/argus/config.yaml
# 远程(token 从环境变量读取,见上)
claude mcp add argus-remote -- argus mcp --server https://cert.example.comCline(VS Code)
在 Cline 的 MCP 设置中添加:
{
"mcpServers": {
"argus": {
"command": "argus",
"args": ["mcp", "--config", "/etc/argus/config.yaml"]
}
}
}Zed
settings.json:
{
"context_servers": {
"argus": {
"command": {
"path": "argus",
"args": ["mcp", "--config", "/etc/argus/config.yaml"]
}
}
}
}OpenCode / Codex 等终端 Agent(免安装二进制)
终端 Agent 推荐直接用 HTTP 模式连服务端,客户机不用装 argus。
OpenCode(opencode.jsonc):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"argus": {
"type": "remote",
"url": "https://cert.example.com/mcp",
"oauth": false,
"headers": {
"X-API-Token": "{env:ARGUS_API_TOKEN}"
}
}
}
}
}命令行等价(token 走环境变量,不落配置文件):
export ARGUS_API_TOKEN=st_xxxxxxxx
opencode mcp add argus --url https://cert.example.com/mcp --header 'X-API-Token={env:ARGUS_API_TOKEN}'Codex 及其他支持 Streamable HTTP 的客户端同理:填 URL + 请求头 X-API-Token: <token>。
若客户机能装 argus 二进制,也可用 stdio 模式(同机 Agent 更省事,少一次网络往返):
{
"mcp": {
"servers": {
"argus": {
"type": "local",
"command": ["argus", "mcp", "--server", "https://cert.example.com"],
"environment": { "ARGUS_API_TOKEN": "{env:ARGUS_API_TOKEN}" }
}
}
}
}Claude Desktop
claude_desktop_config.json:
{
"mcpServers": {
"argus": {
"command": "C:\\argus\\argus.exe",
"args": ["mcp", "--config", "C:\\argus\\config.yaml"]
}
}
}工具清单
查询(只读)
| 工具 | 说明 | 所需 scope |
|---|---|---|
list_certificates | 证书列表,支持状态/临期天数/域名关键字过滤 | certificates:read |
get_certificate | 证书详情(SAN/有效期/渠道/状态),按 id 或域名 | certificates:read |
list_deploy_targets | 部署目标列表(通道 × 场景 × 状态) | deploy:read |
list_accounts | 渠道账户列表(SSL 渠道 + DNS 验证账户,凭据脱敏) | accounts:read |
list_agents | Agent 在线状态 | admin:read |
get_task_logs | 最近任务日志(扫描/续期/提醒) | certificates:read |
操作(写入)
| 工具 | 说明 | 所需 scope |
|---|---|---|
issue_certificate | 签发证书(受 CA 速率限制,可能数分钟) | certificates:write |
renew_certificate | 续期证书 | certificates:write |
revoke_certificate | 吊销证书(不可逆) | certificates:write |
import_certificate | 导入既有证书(PEM) | certificates:write |
deploy_certificate | 推送部署到目标 | deploy:write |
test_deploy_target | 测试部署目标连通性 | deploy:write |
敏感操作(默认关闭)
| 工具 | 说明 |
|---|---|
download_certificate | 下载证书打包文件(含私钥)。默认不注册;需在 config.yaml 配置 mcp.allow_key_download: true,且每次调用都会审计 |
工具入参均带 JSON Schema 校验,未知字段会被拒绝。
scope 申请与最小权限
远程模式使用的 API Token 在 系统 → API Token 页面创建。按用途授予最小 scope:
| 用途 | 建议 scope |
|---|---|
| 只读巡检 / 到期报告 | certificates:read、deploy:read |
| 签发 + 部署自动化 | certificates:read、certificates:write、deploy:read、deploy:write |
| 需要下载私钥 | 上述 + certificates:write,并开启 allow_key_download |
本地模式可在启动时收敛工具集(不出现写工具,Agent 也无法调用):
argus mcp --config /etc/argus/config.yaml --scopes certificates:read安全注意事项
- 吊销不可逆:
revoke_certificate会让证书立即失效,依赖它的服务会中断。工具的 description 中已内置警示,Agent 调用前通常会向你确认 - 私钥不出对话:
download_certificate只返回文件名与大小,私钥内容不会进入对话文本 - token 保管:远程模式的 token 等同账号凭证。建议用环境变量传入、定期轮换、可随时在 API Token 页吊销
- 审计:所有写操作走既有审计体系(
certificate.issue/renew/revoke/deploy等 action),可在审计日志页追溯;MCP 调用不产生新 action 类型 - 本地模式进程权限 = 运行用户权限,请以适当的系统用户运行
- HTTP 模式:与 Web 同端口同 TLS,复用 API Token 认证与 scope 强制;已内置跨源防护(拦截浏览器跨源请求与 DNS rebinding)。生产环境务必 HTTPS,并按最小权限授予 token scope
排障
| 现象 | 排查 |
|---|---|
| 连接失败 / Agent 看不到工具 | argus mcp --config <path> 在本机是否能启动;stdout 是否被其他日志污染(MCP 要求 stdout 只有协议帧,Argus 的日志一律走 stderr) |
| 工具调用返回权限不足 | 远程模式检查 token scope(certificates:write 等)与用户角色;本地模式检查 --scopes |
download_certificate 不存在 | 默认不注册;在 config.yaml 设置 mcp.allow_key_download: true 后重启 |
| 签发长时间无响应 | ACME 签发可能耗时数分钟(DNS 传播验证);客户端超时请调大,或先用 get_task_logs 看进度 |
| 提示"证书未绑定部署目标" | deploy_certificate 未指定 target_ids 且证书没有绑定任何目标;显式传 target_ids |
HTTP 模式连不上(/mcp 404) | 服务端 config.yaml 的 mcp.enabled 需为 true 并重启;为 false 时该端点不存在(stdio 子命令不受影响) |
| HTTP 模式返回 401 | 请求头不对:API Token 走 X-API-Token,不要放 Authorization: Bearer(那会按 JWT 校验而失败) |
| HTTP 模式返回 403 权限不足 | token 的 scope 不含该工具所需权限(见上方工具清单);工具根本不出现在列表里即是此因 |
浏览器里打开 /mcp 被拒 | 跨源防护生效中(MCP 端点为程序化客户端设计,不建议从浏览器直接访问) |