/ 目录 / 演练场 / mcp-gateway
● 社区 lasso-security ⚡ 即开即用

mcp-gateway

作者 lasso-security · lasso-security/mcp-gateway

在 MCP 服务器前部署安全网关——隐藏密钥、脱敏 PII、阻止提示注入、记录每个工具调用。

Lasso 的 mcp-gateway 是一个基于 Python 的多 MCP 服务器编排器,配备护栏插件系统:基础密钥隐藏、Presidio PII 脱敏、Lasso 的 LLM 感知提示注入检测、Xetrack 追踪和服务器信誉扫描。

为什么要用

核心特性

实时演示

实际使用效果

gateway.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "gateway": {
      "command": "uvx",
      "args": [
        "mcp-gateway"
      ],
      "_inferred": true
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "gateway": {
      "command": "uvx",
      "args": [
        "mcp-gateway"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "gateway": {
      "command": "uvx",
      "args": [
        "mcp-gateway"
      ],
      "_inferred": true
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "gateway": {
      "command": "uvx",
      "args": [
        "mcp-gateway"
      ],
      "_inferred": true
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "gateway",
      "command": "uvx",
      "args": [
        "mcp-gateway"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "gateway": {
      "command": {
        "path": "uvx",
        "args": [
          "mcp-gateway"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add gateway -- uvx mcp-gateway

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: mcp-gateway

向 Claude 公开内部 MCP 而不泄露 PII

👤 企业安全团队、平台团队 ⏱ ~45 min advanced

何时使用: 你的内部工具(postgres、CRM)直接使用会将客户名称/邮箱/身份证号泄露到 LLM 上下文中。

前置条件
  • pip install mcp-gateway[presidio] — presidio extra 会拉取 spaCy 模型
步骤
  1. 通过网关连接上游 MCP
    使用上游 postgres MCP 配置 mcp-gateway;启用 Presidio 插件,对 EMAIL、PHONE、US_SSN 进行脱敏。✓ 已复制
    → 包含插件链的配置文件
  2. 测试脱敏效果
    运行返回客户邮箱的查询;确认网关在发送给 LLM 前已将其替换为 <EMAIL> 占位符。✓ 已复制
    → Claude 只看到占位符

结果: LLM 可用的工具访问,而不会让原始 PII 跨越边界。

注意事项
  • 过度脱敏导致下游查询失败 — 使用一致的伪名称(Presidio 支持基于哈希的方案),这样 LLM 仍能在脱敏字段之间进行推理
搭配使用: postgres

阻止来自工具输出的提示注入攻击

👤 有安全意识的代理构建者 ⏱ ~30 min advanced

何时使用: 你的代理使用 fetch/web-browsing MCP——工具输出可能包含'忽略之前的指令'这类的恶意负载。

前置条件
  • Lasso API key — 在 lasso.security 注册
步骤
  1. 启用 Lasso 插件
    在网关配置中启用 Lasso 插件并设置 LASSO_API_KEY。将 fetch MCP 放在它后面。✓ 已复制
    → 插件已激活;输出正在被扫描
  2. 测试
    让 Claude 获取包含已知提示注入测试字符串的 URL;验证它在到达模型前已被中和。✓ 已复制
    → 注入被阻止或标记

结果: 防御来自工具输出的注入攻击。

注意事项
  • 假阳性阻止合法内容 — 先用'warn'模式,审查日志后再切换到'block'
搭配使用: fetch · firecrawl

记录所有 MCP 工具调用用于合规审计

👤 合规/安全审计团队 ⏱ ~20 min intermediate

何时使用: 你需要 SOC2 风格的证据来证明 LLM 对工具的所有调用。

步骤
  1. 启用 Xetrack 插件
    启用 Xetrack 并将目标设置为 SQLite。将所有 MCP 通过网关路由。✓ 已复制
    → mcp_calls.db 正在被写入
  2. 查询审计日志
    显示过去 24 小时内工具名称包含'delete'或'drop'的所有工具调用。✓ 已复制
    → 破坏性操作的审计追踪

结果: 可查询的审计数据库用于合规验证。

注意事项
  • 日志数据库无限增长 — 每月轮换和归档

组合

与其他 MCP 搭配,撬动十倍杠杆

gateway + postgres + fetch

数据库 + 网络访问,带 PII + 注入防护

将 postgres 和 fetch 放在 mcp-gateway 后面,启用 presidio + lasso 插件;从 Claude 正常使用。✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
<upstream tools> Depends on upstream MCP 网关是透明的——你像平时一样调用上游工具 upstream cost + plugin overhead

成本与限制

运行它的成本

API 配额
Lasso 插件需要 Lasso API key(付费版本)
每次调用 Token 数
插件开销约 50-200ms/次调用;脱敏会减少 token 数量
费用
网关本身免费。Lasso 插件:参见 lasso.security 定价。
提示
免费运行基础 + presidio 插件;仅在需要高级注入检测时添加 Lasso。

安全

权限、密钥、影响范围

凭据存储: 插件 API 密钥存储在环境变量中(LASSO_API_KEY 等)
数据出站: 因插件而异:基础 + presidio 是本地的;Lasso 会将样本发送到 Lasso 云进行分析

故障排查

常见错误与修复

Presidio 插件加载失败

安装额外依赖:pip install 'mcp-gateway[presidio]' 并下载 spaCy 模型:python -m spacy download en_core_web_lg

上游 MCP 不通过网关响应

先直接测试上游;然后验证网关 mcp.json 的命令/参数完全匹配。

性能下降

插件链的顺序很重要——将成本最低的(基础掩码)放在首位,Lasso 放在最后。

替代方案

mcp-gateway 对比其他方案

替代方案何时用它替代权衡
Claude 的内置输出过滤器你只使用 Claude 并信任其自有脱敏无法自定义,无审计追踪
Concierge SDK你想要一个用于编写 MCP 的框架,而不是安全代理解决的是不同的问题

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills