mcpField
E
enterprise-mcp-gateway

enterprise-mcp-gateway

本地服务
github.com/BenjaminJ安全12 周前更新

关于 enterprise-mcp-gateway

enterprise-mcp-gateway 是用 Go 编写的网关,将 MCP 客户端请求路由到企业后端。它结合基于角色的工具权限、响应脱敏、基于 OpenAPI 的工具注册和结构化审计日志。

主要功能

  1. 01对响应中的个人信息和密钥脱敏
  2. 02按角色控制工具可见性与权限
  3. 03从 OpenAPI 或 Swagger 规范注册工具
  4. 04生成结构化 JSON 审计日志
  5. 05支持 stdio 和 HTTP SSE 传输

适用场景

  1. 01在结果交给大模型前遮蔽敏感数据
  2. 02按调用者角色限制企业工具
  3. 03将 OpenAPI 描述的服务接入为 MCP 工具
  4. 04通过结构化审计记录检查工具调用

MCP 相关

作为 MCP 客户端与企业后端之间的网关,将配置的后端操作提供为工具。支持通过 stdio 和 HTTP Server-Sent Events 传输 JSON-RPC。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Enterprise MCP Gateway

CI 状态 最后提交 Go 版本 MCP 版本 Glama 评分 安全性 许可证

基于 Go 构建的生产级高性能 Model Context Protocol(MCP)网关。
安全、经过审计且已清理 PII 的桥接层,连接 AI Agent(Claude Desktop、Cursor、Antigravity、LangGraph)与企业后端(OpenAPI、Java/Spring Boot、Go 微服务、关系型数据库)。

enterprise-mcp-gateway Glama 卡片

Enterprise MCP Gateway 实时演示
实时演示:AI Agent 查询 CRM 时,对传输中的 PII 和卡号进行脱敏(左侧);与此同时,网关实时输出结构化 JSON 审计日志(右侧)。


🚀 主要功能

  • ⚡ 极速轻量: 单个静态 Go 二进制文件(常驻内存占用 <25MB、路由开销低于 1 毫秒、无需外部运行时依赖)。
  • 🛡️ 高性能 PII 和密钥脱敏: 在工具响应到达大模型之前,实时对数据流和 JSON 键进行掩码处理(信用卡号通过 Luhn 校验和验证、SSN、电子邮件、电话号码、AWS 密钥、JWT、GitHub PAT,以及自定义正则表达式规则)。
  • 🔐 基于角色的工具治理(RBAC): 将令牌解析为角色,限制 tools/list 中可见的工具,并在 tools/call 执行时强制执行权限。
  • 🔌 动态 OpenAPI / Swagger 连接器: 无需编写后端胶水代码,即可直接从 OpenAPI 3.0/Swagger YAML 或 JSON 规范中即时注册经过验证的 MCP 工具。
  • 📜 结构化 JSON 审计日志: 输出防篡改的结构化 JSON 日志,其中包含调用者身份、调用的工具、经过 SHA-256 哈希处理的参数、执行延迟以及 PII 脱敏指标。
  • 🔄 双传输模式支持: 完全符合 JSON-RPC 2.0 的引擎,同时支持标准 stdio(用于 Claude Desktop / Cursor)和 HTTP Server-Sent Events(SSE),适用于分布式微服务。

🏗️ 架构

┌────────────────────────────────────────────────────────┐
│           AI Client (Claude / Cursor / Agent)          │
└──────────────────────────┬─────────────────────────────┘
                           │ JSON-RPC 2.0 (stdio or SSE)
                           ▼
┌────────────────────────────────────────────────────────┐
│           Enterprise MCP Gateway (Single Go Binary)    │
│                                                        │
│  1. Transport Layer (pkg/mcp/transport)                │
│     - Stdio & HTTP-SSE Transceivers                    │
│  2. Security & Auth Guard (pkg/governance/rbac)        │
│     - Token authentication & least-privilege filtering │
│  3. Router & Tool Registry (pkg/mcp/protocol)          │
│     - JSON-RPC 2.0 & MCP handshake engine              │
│  4. Backend Dispatcher (pkg/connector/openapi)         │
│     - Dynamic OpenAPI 3.0 path/query/body mapper       │
│  5. Sanitization Engine (pkg/sanitizer/pii)            │
│     - Zero-alloc PII, secret, & JSON key redactor      │
│  6. Structured Audit Logger (pkg/audit)                │
│     - Cryptographic JSON event trail for SIEM          │
└──────────────────────────┬─────────────────────────────┘
                           │ Authorized & Sanitized Calls
                           ▼
┌────────────────────────────────────────────────────────┐
│      Internal Enterprise Services (Java / Go / DBs)    │
└────────────────────────────────────────────────────────┘

📦 快速开始

1. 从源代码构建

请确保已安装 Go 1.24+:

# Clone the repository
git clone https://github.com/BenjaminJ/enterprise-mcp-gateway.git
cd enterprise-mcp-gateway

# Build gateway and mock backend server
go build -o bin/mcp-gateway ./cmd/gateway
go build -o bin/mockserver ./cmd/mockserver
2. 运行模拟企业后端(终端 1)
./bin/mockserver --port 8081
3. 使用示例配置运行网关(终端 2)
选项 A:Stdio 模式(默认)
./bin/mcp-gateway --config ./examples/config.yaml --token "agent-support-key"
选项 B:HTTP Server-Sent Events(SSE)模式
./bin/mcp-gateway --config ./examples/config.yaml --transport sse --port 8080
4. 实时输出审计日志(终端 3)

在工具执行时,跟踪并格式化结构化审计记录:

PowerShell(Windows):

Get-Content -Path .\audit.log -Wait -Tail 10 | ForEach-Object {
    if ($_ -match '^\s*\{') {
        $e = $_ | ConvertFrom-Json
        $time = ([DateTime]$e.timestamp).ToLocalTime().ToString("HH:mm:ss")
        $statusColor = if ($e.status -eq "SUCCESS") { "Green" } else { "Red" }
        $redactColor = if ($e.pii_redacted_count -gt 0) { "Yellow" } else { "DarkGray" }
        Write-Host "[$time] " -NoNewline -ForegroundColor DarkGray
        Write-Host "[$($e.status)] " -NoNewline -ForegroundColor $statusColor
        Write-Host "$($e.tool) " -NoNewline -ForegroundColor Cyan
        Write-Host "(Role: $($e.role), Latency: $($e.duration_ms)ms, Redacted: $($e.pii_redacted_count))" -ForegroundColor $redactColor
    }
}

Bash / Linux / macOS(jq):

tail -f audit.log | jq -c '{time: .timestamp, status: .status, tool: .tool, role: .role, latency_ms: .duration_ms, redacted: .pii_redacted_count}'

🔍 使用 Anthropic 官方 MCP Inspector 进行验证

你可以使用 Anthropic 官方的 @modelcontextprotocol/inspector 测试和检查网关:

通过 Stdio 测试:
npx @modelcontextprotocol/inspector ./bin/mcp-gateway --config ./examples/config.yaml --token agent-support-key
通过 SSE 测试:
  1. 以 SSE 模式启动网关:
    ./bin/mcp-gateway --config ./examples/config.yaml --transport sse --port 8080
    
  2. 打开 Inspector 并指定 SSE 端点:
    npx @modelcontextprotocol/inspector http://localhost:8080/sse
    

💻 Claude Desktop 集成

要通过 enterprise-mcp-gateway 将 Claude Desktop 连接到企业系统:

  1. 打开 Claude Desktop 配置文件:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. 将 enterprise-mcp-gateway 添加到 mcpServers 对象中:

{
  "mcpServers": {
    "enterprise-gateway": {
      "command": "/absolute/path/to/enterprise-mcp-gateway/bin/mcp-gateway",
      "args": [
        "--config",
        "/absolute/path/to/enterprise-mcp-gateway/examples/config.yaml",
        "--token",
        "agent-support-key"
      ]
    }
  }
}
  1. 重启 Claude Desktop。企业工具(listCustomers、getCustomerDetails、createSupportTicket 等)将以锤子图标显示在提示词界面中。

⚙️ 配置指南(config.yaml)

server:
  name: "enterprise-mcp-gateway"
  version: "1.0.0"
  transport: "stdio"       # "stdio" or "sse"
  host: "0.0.0.0"
  port: 8080

governance:
  enabled: true
  default_role: "support_agent"
  tokens:
    "agent-ro-secret": "readonly_agent"
    "agent-support-secret": "support_agent"
    "admin-master-secret": "admin"
  roles:
    readonly_agent:
      allowed_tools:
        - "list*"
        - "get*"
    support_agent:
      allowed_tools:
        - "list*"
        - "get*"
        - "createSupportTicket"
    admin:
      allowed_tools:
        - "*"

sanitizer:
  enabled: true
  mask_card_numbers: true  # Luhn-verified Credit Card masking
  mask_ssn: true           # US SSN masking
  mask_secrets: true       # Private keys, AWS keys, JWTs, PATs
  sensitive_keys:
    - "password"
    - "secret"
    - "token"
    - "apiKey"
    - "ssn"
    - "creditCard"
  custom_regex:
    - name: "Internal Employee ID"
      pattern: "\\bEMP-[0-9]{6}\\b"
      replacement: "[REDACTED-EMP-ID]"

audit:
  enabled: true
  log_path: "stdout"       # "stdout" or path to file e.g. "/var/log/mcp-audit.log"
  hash_inputs: true        # SHA-256 hashes tool arguments for compliance

connectors:
  - name: "enterprise-crm"
    type: "openapi"
    spec_file: "./examples/crm-openapi.yaml"
    base_url: "http://localhost:8081"
    headers:
      Authorization: "Bearer backend-secret-token"
      X-Gateway-Source: "enterprise-mcp-gateway"
    timeout_seconds: 15

🧪 测试

运行所有单元测试和端到端集成测试:

# Run all unit and integration tests
go test -v ./...

# Run tests with the Go race detector enabled
go test -race ./...

🐳 Docker 部署

# Build lightweight Docker image
docker build -t enterprise-mcp-gateway:latest .

# Run container in SSE mode
docker run -d -p 8080:8080 -p 8081:8081 enterprise-mcp-gateway:latest --transport sse --port 8080

📄 许可证

MIT 许可证。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。