Skip to main content
Glama

MCP Airlock

CI License: MIT Python

用于 MCP 工具的零信任安全网关。 MCP Airlock 将每一次工具调用转化为具有防篡改来源证明的、短期且上下文绑定的能力决策。

为什么存在这个项目

智能体工具生态系统在一个痛苦的边界上失败了:从不可信的提示词文本到特权工具执行的跨越。

当前的模式通常是以下之一:

  • 静态允许列表(智能体可以调用工具 X)

  • 弱正则表达式过滤

  • 没有完整性保证的事后日志

当提示词注入在会话期间改变意图时,它们就会失效,从而导致静默的权限提升或数据泄露。

MCP Airlock 通过为 MCP 提供一个缺失的原语解决了这个问题:

  • 能力租约 (Capability Leases):短期、已签名、上下文绑定的权限(会话 + 意图 + 工具范围 + 约束)

  • 上下文感知策略:每次调用时的动态授权(风险评分 + 工具约束 + 租约检查)

  • 防篡改来源证明:所有允许/拒绝决策的仅追加哈希链

Related MCP server: mcp-permission-server

核心创新

上下文绑定能力租约 (CBCL)

每个工具调用都根据已签名的租约进行授权:

  • 绑定到 session_id

  • 绑定到 intent_hash

  • 限定于特定工具

  • 有时间限制

  • 可选约束(例如:允许的域名、最大风险值)

如果提示词注入试图改变意图或跳出工具范围,执行将被拒绝。

架构

flowchart LR
    A[Agent / MCP Client] -->|tools/call| B[MCP Airlock Server]
    B --> C[Risk Engine]
    B --> D[Capability Verifier]
    B --> E[Policy Engine]
    E -->|allow| F[Tool Adapter Layer]
    E -->|deny| G[Policy Deny Response]
    F --> H[External APIs / Internal Services]
    B --> I[Provenance Ledger Hash Chain]

信任边界

flowchart TB
    subgraph Untrusted
      U1[Prompt Content]
      U2[Agent Reasoning Trace]
    end

    subgraph Trusted Control Plane
      T1[MCP Airlock]
      T2[Policy + Lease Validation]
      T3[Signed Provenance Ledger]
    end

    subgraph External Targets
      X1[Public APIs]
      X2[Internal APIs]
    end

    U1 --> T1
    U2 --> T1
    T1 --> T2
    T2 --> X1
    T2 --> X2
    T1 --> T3

关键特性

  • 与 initialize、tools/list、tools/call 兼容的 MCP stdio 服务器

  • 能力颁发工具:airlock_issue_capability

  • 智能体/API 使用分析工具:airlock_usage_stats

  • API 暴露度测量工具:airlock_exposure_report

  • 具有各工具风险阈值的策略执行中间件

  • 提示词注入签名评分

  • 抗 SSRF 的 HTTP 工具适配器 (http_get_json)

  • 真实 API 集成示例 (weather_hourly)

  • 防篡改来源日志 + 验证命令

  • 智能体 API 安全的沙箱加固指南

  • 用于服务/演示/颁发/验证/统计/暴露度的 CLI

2 分钟快速入门

git clone https://github.com/lara-muhanna/mcp-airlock
cd mcp-airlock
python -m pip install -e .
python -m mcp_airlock --config examples/airlock.config.json demo

你将看到:

  • 对人类友好的摘要(握手、能力、允许/拒绝、审计完整性)

  • 被拒绝的恶意调用及其通俗易懂的原因

  • 已签名的来源证明

单命令本地演示(无需安装)

python -m mcp_airlock --config examples/airlock.config.json demo --city Austin --state Texas

演示期间的完整 JSON 负载:

python -m mcp_airlock --config examples/airlock.config.json demo --raw

作为 MCP 服务器运行

python -m mcp_airlock --config examples/airlock.config.json serve

MCP 客户端设置示例:

CLI

# Issue a capability directly
python -m mcp_airlock --config examples/airlock.config.json issue \
  --session-id sess-123 \
  --subject agent:planner \
  --tools weather_hourly,http_get_json \
  --intent "Plan safe outdoor activities" \
  --ttl-seconds 900 \
  --constraints '{"allowed_domains":["api.open-meteo.com"],"max_risk":0.6}'

# Verify audit integrity
python -m mcp_airlock --config examples/airlock.config.json verify-log

# API usage stats by agent
python -m mcp_airlock --config examples/airlock.config.json stats --lookback-hours 24

# API exposure measurement
python -m mcp_airlock --config examples/airlock.config.json exposure --lookback-hours 24

智能体集成示例

运行:

python examples/agent_integration.py

此脚本:

  • 通过 stdio 启动 Airlock

  • 协商 MCP 初始化/列表

  • 颁发租约

  • 运行正常的工具调用

  • 运行被拦截的注入调用

配置模板

examples/airlock.config.json

{
  "secret_key": "dev-secret-change-this-before-production",
  "provenance_log": "./airlock-provenance.log",
  "max_ttl_seconds": 1800,
  "default_risk_threshold": 0.55,
  "tools": {
    "weather_hourly": {
      "require_capability": true,
      "risk_threshold": 0.7
    },
    "http_get_json": {
      "require_capability": true,
      "risk_threshold": 0.45,
      "allowed_domains": ["api.open-meteo.com", "geocoding-api.open-meteo.com"]
    }
  }
}

安全模型摘要

  1. 智能体通过 airlock_issue_capability 请求租约。

  2. 租约经过 HMAC 签名,包含 session、intent_hash、tool_scope、expiry。

  3. 每个 tools/call 请求都包含 _capability 和 _context。

  4. Airlock 执行:

    • 租约有效性 + 签名

    • 会话和意图的连续性

    • 风险阈值

    • 特定工具的约束(例如:域名允许列表)

  5. 决策 + 证据被哈希链接到来源日志中。

项目结构

mcp-airlock/
  mcp_airlock/
    cli.py
    server.py
    policy.py
    capability.py
    risk.py
    provenance.py
    config.py
    tool_ids.py
    tools/
      http_json.py
      weather.py
  examples/
    airlock.config.json
    agent_integration.py
  docs/
    CLIENT_SETUP.md
    SANDBOXING_AGENTIC_APIS.md

路线图

  • 上游 MCP 代理模式(透明地包装现有的 MCP 服务器)

  • OPA/Rego 策略后端

  • OpenTelemetry 追踪 + SIEM 接收器

  • 托管能力代理 + 密钥轮换

  • 用于事件响应的已签名重放包

社区

许可证

MIT

Available Tools

4 tools
airlock_audit_tailC

Read recent signed provenance events.

Inputs: limit.

airlock_issue_capabilityC

Issue a short-lived capability lease bound to session+intent.

Inputs: session_id (required), subject (required), tools (required), intent (required), +2 more.

http_get_jsonA

Fetch JSON from a public HTTPS API endpoint.

Inputs: url (required), query.

weather_hourlyA

Resolve US city/state and fetch hourly weather from Open-Meteo.

Inputs: city (required), state (required), hours.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 4 tools

    Disambiguation4/5

    Each tool targets a distinct function (provenance auditing, capability issuance, generic HTTP fetching, and weather retrieval) with minimal overlap. An agent can easily distinguish when to use each based on the task requirements.

    Naming Consistency3/5

    Mixed naming patterns: two tools use 'airlock_' prefix with verbs (issue, audit_tail), while others use 'http_' prefix or no prefix (weather_hourly). The weather tool breaks the verb-first convention used by others, using a noun-adjective pattern instead.

    Tool Count3/5

    Four tools is acceptably compact but the set suffers from scope confusion, mixing core Airlock security functions with unrelated utility tools (weather, HTTP). This feels like two different servers merged together rather than a cohesive toolset.

    Completeness2/5

    The Airlock domain (capability management) is severely underdeveloped, offering only issuance and audit tail reading without revocation, validation, or capability listing. The utility tools (weather, HTTP) are also minimal, offering only hourly forecasts and GET requests without parameter customization.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables secure interaction between LLMs and MCP tools by applying zero-trust security controls, including sensitive data masking, file system protection, and policy enforcement.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables LLM agents to enforce security policies by authorizing tool calls, scanning for prompt injection, checking memory writes, redacting PII, and accessing audit trails through MCP.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables production-hardened MCP tool serving with OAuth 2.1 audience-restricted tokens, purpose-bound tools, human-in-the-loop approvals, containment, and audit trails for AI agents.
      Apache 2.0