MCP安全防护工具

MCP Shield是一款专为MCP服务器设计的安全防护工具,提供JWT认证、速率限制和审计日志等功能,确保MCP部署的安全性。

  • by bcornish1797
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 bcornish1797/mcp-shield

使用说明

MCP屏蔽

MCP服务器的SSL实验室——在一个命令中对MCP部署进行评分、保护和管理。

为 MCP&AI代理黑客马拉松2026 --保护和管理MCP轨道。

MCP服务器通常作为零安全性的直接stdio进程运行。MCP Shield扫描您现有的IDE配置,生成生产就绪 代理网关 使用JWT身份验证、速率限制和审计日志进行设置,并将所有MCP服务器联合到一个安全端点后面。

问题

大多数MCP部署如下:

[MCP Client (any IDE)]
     |        |        |
[filesystem] [memory] [github]   ← No auth, no limits, no logging
  • 无需认证 --任何具有端点访问权限的人都可以调用任何工具
  • 无速率限制 --流氓代理会耗尽资源
  • 无审计追踪 --无法了解正在调用哪些工具
  • 无联盟 --每个服务器都是一个单独的连接来管理

解决方案

[MCP Client (any IDE)]
          |
    [agentgateway]  ← JWT auth + rate limiting + audit logging
     /    |    \
[filesystem] [memory] [github]

MCP Shield自动生成所有配置。

快速开始

# Install
npm install -g mcp-shield

# Score your current security posture
mcp-shield score

# Scan your MCP setup
mcp-shield scan

# Generate a secured configuration
mcp-shield secure

# Publish to agentregistry
mcp-shield publish

# Start the gateway
mcp-shield start

# Verify security is working
mcp-shield verify

命令

mcp-shield score

在9个维度上使用A-F字母等级评估MCP部署的安全态势。

mcp-shield score
mcp-shield score -f my-config.json

评分维度 (共100分):

尺寸 重量 检查内容
身份验证 25 JWT/OAuth令牌验证
速率限制 15 令牌桶保护
审计日志记录 15 请求/响应日志记录
端点联合 10 单网关端点
传输安全 10 TLS/stdio隔离
输入验证 10 工具参数清理
CORS策略 5 跨源控制
OAuth发现 5 .众所周知的元数据
服务器隔离 5 每台服务器RBAC

mcp-shield scan

从IDE配置文件(游标、VS代码等)中发现MCP服务器配置。

# Auto-detect
mcp-shield scan

# Specify a config file
mcp-shield scan -f ~/.config/claude/claude_desktop_config.json

mcp-shield secure

生成具有企业级安全策略的代理网关配置。

# Basic (JWT auth, strict mode)
mcp-shield secure

# With rate limiting
mcp-shield secure --rate-limit 60

# Custom port and auth mode
mcp-shield secure --port 8080 --auth optional

# Specify config file and output directory
mcp-shield secure -f my-config.json -o ./my-gateway

选项:

  • --auth <mode> — strict (默认), optional,或 permissive
  • --rate-limit <rpm> --每分钟请求数限制
  • --port <port> --网关端口(默认值:3000)
  • -o, --output <dir> --输出目录(默认: ./mcp-shield-output)

mcp-shield start

使用生成的配置启动agentgateway。

mcp-shield start
mcp-shield start --gateway-bin /path/to/agentgateway

mcp-shield verify

测试网关是否正确保护。

mcp-shield verify
mcp-shield verify --url http://localhost:8080

生成什么

mcp-shield-output/
├── gateway-config.yaml          # agentgateway configuration
├── claude_desktop_config.json   # Updated client config (points to gateway)
└── keys/
    ├── pub-key                  # JWKS public key (for agentgateway)
    └── priv-key.pem             # Private key (for signing tokens)

安全特性

特性 描述
JWT身份验证 所有MCP端点上的OAuth2/JWT令牌验证
速率限制 每个端点的令牌桶速率限制
跨域资源共享 可配置的跨源资源共享
联邦 单个安全端点后面的多个MCP服务器
每台服务器隔离 每个MCP服务器的单独端点(/mcp/<name>)
OAuth发现 标准 /.well-known/oauth-protected-resource 元数据

支持的配置格式

  • 克劳德桌面版 — claude_desktop_config.json
  • 光标 — .cursor/mcp.json
  • VS Code — .vscode/settings.json
  • 自定义 --任何JSON servers 数组

需求

构建于

许可证

麻省理工学院