MCP安全框架

专为Model Context Protocol设计的10层防御安全框架,提供4通道检测和零知识证明,保护AI助手与数据源连接的安全性。

  • by mcp-bastion-security
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 safe-mcp-platform/safe-mcp-platform

使用说明

🛡️ MCP堡垒安全

模型上下文协议的生产就绪安全框架

🚀 10层防御•4通道检测•零知识证明•生产就绪


🎯 什么是MCP Bastion安全?

MCP Bastion Security是一个专门为模型上下文协议(MCP)设计的综合生产安全框架。与通用安全工具不同,我们实现:

  • ✅ 10层纵深防御:从隔离到ZK证明的完整安全管道
  • ✅ 4通道检测:语义分析、形式验证、自定义ML、行为GNN
  • ✅ 零知识证明:隐私保护安全验证
  • ✅ 全面覆盖:针对81多种记录在案的MCP攻击技术的防护
  • ✅ 生产性能:<75ms延迟,水平可扩展,高可用性

专为MCP设计 -不适用于通用安全工具。


🔥 为何这很重要

MCP没有本机安全层。 随着Anthropic将人工智能助手连接到数据源的开放标准被采用(Claude Desktop、Cursor IDE、自定义客户端), 每个工具调用都不受保护.

威胁格局:

  • 81+记录在案的MCP攻击技术
  • 攻击成功率:36.5-96%,具体取决于复杂性
  • 55%的攻击:通过工具描述迅速注入
  • 25%的攻击:对敏感文件的路径遍历

MCP Bastion Security提供全面保护 通过研究验证了防御机制。


🏗️ 建筑

10层纵深防御

MCP Bastion Security实施了全面的 10层安全架构 提供针对MCP攻击的完整保护:

graph TD
    START["MCP Call"]
    
    L1["Layer 1: Execution Isolation<br/>⚡ Capability-based sandboxing<br/>Impact: 60% attacks stopped"]
    
    L2["Layer 2: Obfuscation Detection<br/>⚡ Multi-encoding detection<br/>Impact: 4x bypass resistance"]
    
    L3_6["Layers 3-6: 4-Channel Detection<br/>⚡ Semantic | Formal | ML | GNN<br/>Impact: 85-90% accuracy"]
    
    L7["Layer 7: Information Flow Control<br/>⚡ Taint tracking<br/>Impact: 100% exfil prevention"]
    
    L8["Layer 8: Adaptive Policies<br/>⚡ Context-aware adjustment<br/>Impact: 40% FP reduction"]
    
    L9["Layer 9: Anomaly Detection<br/>⚡ Unknown pattern detection<br/>Impact: Novel attack coverage"]
    
    L10["Layer 10: Resource Monitor<br/>⚡ DoS prevention<br/>Impact: Resource abuse prevention"]
    
    ZK["🔐 ZK Proof Generation"]
    
    DECISION{{"ALLOW or BLOCK"}}
    
    START --> 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

📖 查看完整的架构文档

核心创新: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<br/>• Tool permissions<br/>• Resource scope<br/>• Argument semantics"]
        S2["Analyze Tool Context<br/>• Capability analysis<br/>• Permission validation"]
        S3["Check Attack Patterns<br/>• 81 techniques<br/>• Pattern matching"]
        S4["Semantic Risk Score<br/>0.0 - 1.0"]
        S1 --> S2 --> S3 --> S4
    end
    
    subgraph CH2["Channel 2: Formal Verification"]
        direction TB
        F1["Convert to Logic<br/>• First-order logic<br/>• Temporal properties"]
        F2["Generate Security Property<br/>• From threat spec<br/>• Formal specification"]
        F3["Automated Proof<br/>• SMT solving<br/>• Theorem proving"]
        F4["VERIFIED or VIOLATED<br/>+ Proof/Counterexample"]
        F1 --> F2 --> F3 --> F4
    end
    
    subgraph CH3["Channel 3: MCP Transformer"]
        direction TB
        M1["Encode MCP Call<br/>• Tokenization<br/>• MCP structure"]
        M2["Multi-Head Attention<br/>• Structural attention<br/>• Tool-context attention"]
        M3["Multi-Task Prediction<br/>• Techniques<br/>• Severity<br/>• Mitigations"]
        M4["ML Confidence<br/>0.0 - 1.0"]
        M1 --> M2 --> M3 --> M4
    end
    
    subgraph CH4["Channel 4: Call Graph Analyzer"]
        direction TB
        B1["Build Call Graph<br/>• Nodes = calls<br/>• Edges = dependencies"]
        B2["Extract Graph Features<br/>• Density, paths<br/>• Patterns"]
        B3["Match Attack Patterns<br/>+ GNN Detection"]
        B4["Behavioral Risk<br/>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<br/>4 Channels"]
    P2["Generate Witness<br/>Private Evidence"]
    P3["Create Commitment<br/>COM witness"]
    P4["Generate ZK Proof π"]
    
    PROOF["ZK Proof π<br/>Decision + Commitment<br/>NO evidence revealed"]
    
    V1["Verify Proof π"]
    V2["Check Public Inputs"]
    V3["Cryptographic Check"]
    V4["Accept or Reject"]
    
    ACCEPT["✅ Trust Decision<br/>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) <80ms 99百分位数
吞吐量 412个需求/秒 每个工人
准确度 85-90% 前两名技术(T1102、T1105)
假阳性率 <1.5% 行业领先
可扩展性 线性 水平缩放

探测范围

组件 覆盖范围 实施
框架 81/81技术 配置驱动系统
实现 2种技术(T1102、T1105) 完全可操作
攻击面 80% 前两名覆盖了80%的真实攻击
渠道整合 4/4通道 所有新颖的实现

💡 工作原理:两种集成模式

模式1:开发人员集成(SDK)

MCP服务器开发人员的一线安全:

from safe_mcp_sdk import secure

@server.tool()
@secure()  # That's it! Full 4-channel protection
async def read_file(path: str) -> 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:8001

2.保护您的客户

# Install CLI
pip install mcp-bastion

# Protect Cursor (or Claude Desktop)
mcp-bastion protect cursor

# Verify
mcp-bastion status

3.保护您的服务器(开发人员)

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种新型检测通道
  • 零知识证明验证
  • 威胁情报数据库
  • 生产级性能

📚 文档


🤝 贡献

我们欢迎三个层面的贡献:

  1. 检测方法 (简单):添加MCP攻击技术的模式
  2. 渠道改进 (中):增强检测算法
  3. 研究 (高级):新颖的检测方法,机器学习模型

看 贡献.md 了解详情。


📄 许可证

MIT许可证-请参阅 许可证 了解详情。


🙏 致谢

  • Anthropic:模型上下文协议规范
  • 学术启示MITRE ATT&CK,形式化方法研究,ZK证明系统
  • MCP安全研究社区:攻击技术研究和威胁情报

📞 联系


🛡️ 让MCP对每个人都安全🛡️

10层防御•4通道检测•零知识证明•生产就绪

通过创新构建 Saurabh Yergattikar