使用说明
mcp警卫
MCP服务器的安全linter+策略引擎,具有CI合并阻止和SARIF报告。
它是干什么的?
mcp-guard扫描mcp服务器代码/config/端点以查找有风险的安全模式(路径遍历、命令注入原语、不安全的git/文件操作),运行精心策划的对抗性提示测试,并发出对开发人员友好的输出以及GitHub security的SARIF。在严格模式下,CI无法阻止不安全的合并。
给谁的
- MCP服务器维护人员
- 安全工程师审查人工智能工具供应链
- 管理CI策略门的平台团队
- 需要轻量级、快速安全检查的OSS维护人员
特性
- 跨常用扩展名静态扫描源/配置文件
- YAML中的策略代码(用严重性/消息拒绝规则)
- 精心设计的“邪恶提示”模糊通道,用于快速注射回归
- GitHub代码扫描的SARIF 2.1.0输出
- CI就绪严格模式(
--strict)失败建立在发现的基础上 - 复合GitHub Action包装器
action/ - 快速的本地工作流程
make setup/lint/test/demo/doctor - 跨平台单二进制Go CLI
快速入门
git clone https://github.com/Exmanq/mcp-guard.git
cd mcp-guard
make setup
make doctor
make demo
安装
最终用户
go install github.com/Exmanq/mcp-guard/cmd/mcp-guard@v0.1.0
mcp-guard --version
来源
pipx --version >/dev/null 2>&1 || true # not required; just example tool check
go build -o bin/mcp-guard ./cmd/mcp-guard
./bin/mcp-guard --target . --policies policies/default.yaml
示例输出/屏幕截图
自 make demo (实际生成的文件: examples/output/demo.sarif):
[HIGH] MCP001-path-traversal: Potential path traversal primitive detected. (internal/fixtures/vulnerable_server.go)
[MEDIUM] MCP003-unsafe-git-force: Unsafe git force push pattern found. (internal/fixtures/vulnerable_server.go)
[HIGH] MCP004-unsafe-file-write: Direct file write found; ensure strict path allowlist. (internal/fixtures/vulnerable_server.go)
[HIGH] FUZZ-MCP001-path-traversal: Evil prompt matched deny rule during prompt-injection simulation (fuzz/prompt-corpus)
[CRITICAL] FUZZ-MCP002-command-injection: Evil prompt matched deny rule during prompt-injection simulation (fuzz/prompt-corpus)
Total findings: 5
运作原理
flowchart TD
CLI[mcp-guard CLI] --> P[Load YAML policies]
CLI --> S[Static scan files]
CLI --> F[Fuzz evil prompts]
S --> R[Aggregate findings]
F --> R
R --> O[Terminal output + SARIF]
O --> G[GitHub Security Code Scanning]
CLI首先从YAML加载策略规则并验证所需字段。它递归地扫描源代码/config文件以查找有风险的原语,并跳过重量级目录。并行(逻辑阶段),它对相同的拒绝模式运行确定性对抗提示,以捕捉提示注入回归。结果使用严重性和规则ID进行标准化,打印到stdout,并可选择写入SARIF。CI管道可以运行严格模式,在违反策略时立即使PR失败。看 docs/ARCHITECTURE.md 更深入的细节。
配置
- CLI标志:
--target,--policies,--sarif-out,--strict,--verbose,--version - 策略文件:
policies/default.yaml - 完整参考:
docs/CONFIG.md
故障排除
go: command not found→ 安装Go 1.22+并重新运行make setup- 没有发现,但预期会发出警报 → 在YAML中验证正则表达式策略并运行
make demo - CI在严格模式下失败 → 检查SARIF或控制台输出,修复发现的问题,然后重新运行
- 需要调试详细信息 → add
--verbose用于完整错误上下文
贡献
看 CONTRIBUTING.md 用于本地工作流、提交样式和PR要求。
安全
使用环境变量作为机密;永远不要在策略/测试中硬编码凭据。mcp-guard不记录机密环境值。看 SECURITY.md.
许可证
麻省理工学院——见 LICENSE.
