🛡️ MCP堡垒安全
模型上下文协议的生产就绪安全框架
  
🚀 10层防御•4通道检测•零知识证明•生产就绪
______________________________________________________________________
🎯 什么是MCP Bastion安全?
MCP Bastion Security是一个专门为模型上下文协议(MCP)设计的综合生产安全框架。与通用安全工具不同,我们实现:
- ✅ 10层纵深防御:从隔离到ZK证明的完整安全管道
- ✅ 4通道检测:语义分析、形式验证、自定义ML、行为GNN
- ✅ 零知识证明:隐私保护安全验证
- ✅ 全面覆盖:针对81多种记录在案的MCP攻击技术的防护
- ✅ 生产性能:\ L1
L1 -->|"✅"| L2 L2 --> L3_6 L3_6 --> L7 L7 -->|"✅"| L8 L8 --> L9 L9 --> L10 L10 --> ZK ZK --> DECISION
DECISION -->|"ALLOW"| ALLOW["✅ Forward to Server"] DECISION -->|"BLOCK"| BLOCK["🚫 Return Error + Proof"]
style START fill:#e3f2fd,stroke:#1976d2,stroke-width:3px style L1 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style L2 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style L3_6 fill:#4caf50,color:#fff,stroke:#2e7d32,stroke-width:3px style L7 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style L8 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style L9 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style L10 fill:#ff9800,color:#fff,stroke:#e65100,stroke-width:2px style ZK fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:3px style DECISION fill:#2196f3,color:#fff,stroke:#0d47a1,stroke-width:3px style ALLOW fill:#4caf50,color:#fff,stroke:#2e7d32,stroke-width:3px style BLOCK fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:3px
**📖 [查看完整的架构文档](ARCHITECTURE.md)**
### 核心创新:4通道检测(第3-6层)
检测引擎执行 **四个平行通道** 从不同角度分析每个MCP呼叫:
______________________________________________________________________
### 🔬 通道1:MCP语义模式分析器
**创新:** 了解MCP协议语义的协议感知语义分析。
**传统方法:**
Generic regex matching
if re.match(r"\.\.\/", path): return BLOCK
**我们的新颖方法:**
MCP-aware semantic analysis
features = extract_mcp_features(call) # Tool permissions, resource scope tool_risk = analyze_tool_context(features) # Understand tool capabilities arg_risk = analyze_argument_semantics(call) # Argument relationships pattern_risk = check_attack_patterns(features) # Attack technique patterns
return aggregate_semantic_risks(tool_risk, arg_risk, pattern_risk)
**主要区别:**
- 了解工具功能和权限
- 分析参数关系(而不仅仅是单个值)
- 情境相关风险评分
- 全面的攻击模式覆盖
______________________________________________________________________
### 🔬 通道2:正式验证引擎
**创新:** MCP安全属性的第一个正式验证系统。
**它的作用:**
- 将MCP调用转换为逻辑公式
- 数学上 **证明** 安全属性保持(或不保持)
- 使用SMT解决方案进行自动验证
- 生成正式证书或反例
**安全属性示例:**
∀ path ∈ arguments: normalized(path) ⊆ workspace_root
Translation: "For all paths in arguments, the normalized path must be within workspace root"
This is PROVEN, not just checked heuristically.
**为什么具有开创性:**
- 提供数学确定性(非概率性)
- 抓住边缘案例启发式失误
- 生成正式证明(审计跟踪)
______________________________________________________________________
### 🔬 通道3:MCP专用变压器
**创新:** 第一个专为MCP协议设计的变压器架构。
**不转移学习** -这是一个专门构建的神经网络:
class MCPTransformer: - MCP structural attention (understands protocol structure) - Tool-context attention (tool-specific features) - Argument relationship attention (parameter dependencies) - Multi-task heads: * Technique classification (which SAFE-T technique) * Severity prediction (LOW, MEDIUM, HIGH, CRITICAL) * Mitigation suggestion (which SAFE-M to apply)
**关键创新:**
- 非通用NLP-专为MCP设计
- 多任务学习(同时3个输出)
- 协议感知注意力机制
______________________________________________________________________
### 🔬 通道4:调用图行为分析器
**创新:** MCP的第一个基于图的行为分析。
**传统方法:** 跟踪请求计数、速率
**我们的方法:** 将会话建模为有向图
Build call graph
graph = build_call_graph(session) ↓ Extract graph features (density, paths, patterns) ↓ Match against known attack graphs: - read_file → encode → send_http (exfiltration) - list_files → read_multiple → external_api (recon + exfil) - read_config → modify_settings → execute (privilege escalation) ↓ Use GNN to detect novel attack patterns
**为什么革命:**
- 检测多阶段攻击(单次呼叫分析未检测到这些攻击)
- 新模式的图神经网络
- 首先将图论应用于MCP安全
### 通道架构深度学习
flowchart TD subgraph CH1["Channel 1: Semantic Pattern Analyzer"] direction TB S1["Extract MCP Features • Tool permissions • Resource scope • Argument semantics"] S2["Analyze Tool Context • Capability analysis • Permission validation"] S3["Check Attack Patterns • 81 techniques • Pattern matching"] S4["Semantic Risk Score 0.0 - 1.0"] S1 --> S2 --> S3 --> S4 end
subgraph CH2["Channel 2: Formal Verification"] direction TB F1["Convert to Logic • First-order logic • Temporal properties"] F2["Generate Security Property • From threat spec • Formal specification"] F3["Automated Proof • SMT solving • Theorem proving"] F4["VERIFIED or VIOLATED + Proof/Counterexample"] F1 --> F2 --> F3 --> F4 end
subgraph CH3["Channel 3: MCP Transformer"] direction TB M1["Encode MCP Call • Tokenization • MCP structure"] M2["Multi-Head Attention • Structural attention • Tool-context attention"] M3["Multi-Task Prediction • Techniques • Severity • Mitigations"] M4["ML Confidence 0.0 - 1.0"] M1 --> M2 --> M3 --> M4 end
subgraph CH4["Channel 4: Call Graph Analyzer"] direction TB B1["Build Call Graph • Nodes = calls • Edges = dependencies"] B2["Extract Graph Features • Density, paths • Patterns"] B3["Match Attack Patterns + GNN Detection"] B4["Behavioral Risk 0.0 - 1.0"] B1 --> B2 --> B3 --> B4 end
style CH1 fill:#fff3e0,stroke:#f57c00,stroke-width:2px style CH2 fill:#e8f5e9,stroke:#388e3c,stroke-width:2px style CH3 fill:#e3f2fd,stroke:#1976d2,stroke-width:2px style CH4 fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
______________________________________________________________________
## 🚀 突破:零知识证明系统
**突破性创新:** ZK证明首次应用于协议级安全。
### 问题
传统检测揭示 **为什么** 有东西被堵住了:
❌ "Blocked: Contains '../' (path traversal pattern)"
**风险:** 攻击者学习检测逻辑并躲避它。
### 我们的解决方案:零知识证明
Generate proof that call is unsafe WITHOUT revealing detection logic
proof = prover.prove_safety(mcp_call, detection_result, witness)
Gateway verifies proof without seeing detection logic
valid = verifier.verify(proof)
**属性:**
- **躲藏:** 证据并不能揭示检测模式
- **声音:** 无法生成虚假证明
- **可验证:** 任何人都可以在没有秘密知识的情况下进行验证
**影响:**
- 防止检测系统的对抗性学习
- 实现隐私保护安全
- 保持竞争优势
- **具有专利价值的基础知识产权**
### ZK验证系统流程
flowchart LR MCP["MCP Call"]
P1["Run Detection 4 Channels"] P2["Generate Witness Private Evidence"] P3["Create Commitment COM witness"] P4["Generate ZK Proof π"]
PROOF["ZK Proof π Decision + Commitment NO evidence revealed"]
V1["Verify Proof π"] V2["Check Public Inputs"] V3["Cryptographic Check"] V4["Accept or Reject"]
ACCEPT["✅ Trust Decision WITHOUT knowing why"] REJECT["❌ Reject Proof"]
MCP --> P1 P1 --> P2 P2 --> P3 P3 --> P4 P4 --> PROOF PROOF --> V1 V1 --> V2 V2 --> V3 V3 --> V4 V4 -->|"Valid"| ACCEPT V4 -->|"Invalid"| REJECT
style P1 fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:2px style P2 fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:2px style P3 fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:2px style P4 fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:2px style PROOF fill:#ffd54f,stroke:#f57c00,stroke-width:3px style V1 fill:#4caf50,color:#fff,stroke:#1b5e20,stroke-width:2px style V2 fill:#4caf50,color:#fff,stroke:#1b5e20,stroke-width:2px style V3 fill:#4caf50,color:#fff,stroke:#1b5e20,stroke-width:2px style V4 fill:#4caf50,color:#fff,stroke:#1b5e20,stroke-width:2px style ACCEPT fill:#4caf50,color:#fff,stroke:#1b5e20,stroke-width:3px style REJECT fill:#f44336,color:#fff,stroke:#b71c1c,stroke-width:3px
______________________________________________________________________
## 📊 技术规格
### 演出
|度量|值|注释|
|--------|-------|-------|
| **延迟(P50)** |35-45ms |网关+检测+转发|
| **延迟(P95)** |\ str:
return open(path).read()发生了什么:
@secure()装饰器拦截调用- 运行新颖的4通道检测
- 如果风险评分>阈值,则阻止
- 对代码透明
部署:
pip install mcp-bastion-sdk
# Add @secure() to your tools
# Deploy normally______________________________________________________________________
模式2:用户保护(CLI)
MCP客户端的一个命令保护:
mcp-bastion protect cursor
✅ Protected Cursor IDE - 3 MCP servers secured这有什么作用:
- 自动发现Cursor的MCP配置
- 用mcp堡垒网关包裹所有服务器
- 通过检测引擎路由流量
- 自动阻止威胁
支持:
- 光标IDE
- 克劳德桌面版
- 自定义MCP客户端
______________________________________________________________________
🔧 快速开始
1.部署平台(5分钟)
git clone https://github.com/mcp-bastion-security/mcp-bastion-security
cd mcp-bastion-security
# Start all services
docker-compose up -d
# Platform ready at:
# - Gateway: http://localhost:8002
# - Detection API: http://localhost:80012.保护您的客户
# Install CLI
pip install mcp-bastion
# Protect Cursor (or Claude Desktop)
mcp-bastion protect cursor
# Verify
mcp-bastion status3.保护您的服务器(开发人员)
from safe_mcp_sdk import secure
@server.tool()
@secure(platform_url="http://localhost:8001")
async def sensitive_operation(data: str):
# Your code here - protected automatically
return process(data)就是这样! 您的MCP基础设施现在受到以下保护:
- 4种新型检测通道
- 零知识证明验证
- 威胁情报数据库
- 生产级性能
______________________________________________________________________
📚 文档
______________________________________________________________________
🤝 贡献
我们欢迎三个层面的贡献:
- 检测方法 (简单):添加MCP攻击技术的模式
- 渠道改进 (中):增强检测算法
- 研究 (高级):新颖的检测方法,机器学习模型
看 贡献.md 了解详情。
______________________________________________________________________
📄 许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
🙏 致谢
- Anthropic:模型上下文协议规范
- 学术启示MITRE ATT&CK,形式化方法研究,ZK证明系统
- MCP安全研究社区:攻击技术研究和威胁情报
______________________________________________________________________
📞 联系
- 项目负责人:Saurabh Yergattikar
- GitHub: mcp堡垒安全
- 领英: Saurabh Yergattikar
______________________________________________________________________
🛡️ 让MCP对每个人都安全🛡️
10层防御•4通道检测•零知识证明•生产就绪
通过创新构建 Saurabh Yergattikar
