mcp强化
MCP(模型上下文协议)配置的安全扫描程序。扫描本地MCP设置,查找硬编码机密、不安全权限、命令注入风险和丢失的安全挂钩-完全离线,不需要API密钥。
为什么
43%的MCP实现存在命令注入漏洞(等效研究).虽然工具像 mcp-scan 分析MCP服务器源代码, 没有好的静态扫描仪 用于检查您的本地MCP安装是否已安全配置。
mcp-fortify 答案: “我的MCP设置安全吗?”
快速开始
npx mcp-fortify或全局安装:
npm install -g mcp-fortify
mcp-fortify它扫描什么
自动发现并扫描您计算机上的这些文件:
| 文件 | 位置 |
|---|---|
| 克劳德代码设置 | ~/.claude/settings.json |
| Claude桌面配置 | ~/Library/Application Support/Claude/claude_desktop_config.json |
| MCP服务器配置 | ~/.claude/mcp-servers/*/ (run.sh、.env、server.py等) |
| 项目配置 | .mcp.json 在当前目录中 |
安全规则(8条规则)
| 规则 | 严重性 | 检测内容 |
|---|---|---|
hardcoded-secrets | 任何扫描文件中的关键 | API密钥、令牌、密码 |
plaintext-env | 关键 | JSON配置中的秘密 env 砌块 |
command-injection | 关键 | 启动脚本和配置中的Shell注入向量 |
file-permissions | HIGH | 配置/凭据文件不限于所有者 |
transport-security | HIGH | HTTP(非HTTPS)端点,0.0.0.0绑定 |
missing-hooks | MEDIUM | 克劳德代码中没有用于秘密阻塞的PreToolUse钩子 |
tool-permissions | MEDIUM | 绕过安全检查的通配符工具权限 |
missing-gitignore | .gitignore未覆盖的MEDIUM | .env文件 |
命令
mcp-fortify scan (默认)
扫描MCP配置以查找安全问题。
mcp-fortify # Scan with defaults
mcp-fortify --format json # JSON output for CI
mcp-fortify --format sarif # SARIF for GitHub Security tab
mcp-fortify --format html -o report.html # HTML report
mcp-fortify --severity critical --ci # Fail CI on critical findings
mcp-fortify --rules hardcoded-secrets # Run specific rules only
mcp-fortify --custom-rules ./my-rules.js # Load custom rules
mcp-fortify --verbose # Show all scanned files
mcp-fortify scan /path/to/project # Scan custom pathmcp-fortify init
为Claude Code生成安全挂钩。创建阻止包含机密的文件写入的PreToolUse钩子。
mcp-fortify initmcp-fortify fix
自动修复可修复的问题(文件权限)。
mcp-fortify fix # Fix issues
mcp-fortify fix --dry-run # Preview what would be fixed输出格式
| 格式 | 用例 |
|---|---|
console | 带颜色的终端输出(默认) |
json | CI管道、程序化消费 |
sarif | GitHub安全选项卡,CodeQL集成 |
html | 可共享的报告、审计 |
CLI选项
mcp-fortify [command] [options]
Commands:
scan [path] Scan MCP configurations (default)
init Generate security hooks for Claude Code
fix Auto-fix remediable security issues
Scan Options:
-f, --format Output format: console | json | sarif | html (default: console)
-o, --output Write output to file instead of stdout
-s, --severity Minimum severity to show (critical|high|medium|low|info)
--rules Comma-separated rule IDs to run
--custom-rules
Path to custom rules module (.js)
--no-color Disable colors
--verbose Show all scanned files
--ci Exit code 1 if high+ severity findings
Fix Options:
--dry-run Show what would be fixed without making changes自定义规则
创建一个 .js 导出规则对象数组的文件:
// my-rules.js
export default [
{
id: 'my-custom-rule',
name: 'My Custom Rule',
severity: 'high',
description: 'Checks for something specific',
run(targets) {
const findings = [];
for (const target of targets) {
// Your detection logic here
}
return findings;
},
},
];然后运行: mcp-fortify --custom-rules ./my-rules.js
安全模式(未标记)
mcp-fortify识别安全模式,不会标记它们:
$(secrets get KEY_NAME)--macOS钥匙链参考$(gh auth token)--GitHub CLI身份验证${ENV_VAR}--壳体可变膨胀process.env.KEY--Node.js环境引用- 占位符值(
YOUR_KEY_HERE,changeme等等)
程序化API
import { scan, format } from 'mcp-fortify';
const result = await scan({ format: 'json' });
console.log(result.findings);
// Generate HTML report
const html = format(result, 'html');许可证
麻省理工学院
