Skip to main content
Glama

MCPGate

轻量级 MCP 网关 — 聚合、过滤并观察您的 MCP 工具。

MCPGate 位于您的 MCP 客户端(Claude Desktop、Claude Code、Cursor、VS Code)与多个 MCP 服务器之间。它提供了一个统一的 MCP 端点,同时让您可以精细控制哪些工具被暴露。

功能特性

  • 工具聚合 — 连接多个 MCP 服务器,通过一个端点暴露所有工具

  • 工具过滤 — 通过简单的 YAML 配置,按服务器允许/阻止特定工具

  • 工具前缀 — 自动命名空间(如 github.create_issue)以避免冲突

  • Web 仪表板 — 实时状态页面,显示服务器、工具和请求日志

  • 双重传输 — Stdio(适用于 Claude Desktop)或 HTTP/SSE(适用于远程客户端)

  • 审计跟踪 — 记录每个工具调用的耗时;支持可选的 PostgreSQL 持久化

  • 自托管 — 可部署在 Railway、Docker 上,或在本地运行

快速开始

本地(Stdio — 适用于 Claude Desktop)

npx mcp-gate start --config mcpgate.yaml

添加到您的 claude_desktop_config.json 中:

{
  "mcpServers": {
    "mcpgate": {
      "command": "npx",
      "args": ["-y", "mcp-gate", "start", "--config", "/path/to/mcpgate.yaml"]
    }
  }
}

本地(HTTP — 带仪表板)

npx mcp-gate start --config mcpgate.yaml
# Dashboard at http://localhost:3000
# MCP endpoint at http://localhost:3000/mcp

Docker

docker compose up
# Dashboard at http://localhost:3000
# Includes PostgreSQL for persistent audit trail

或独立运行:

docker run -p 3000:3000 \
  -e MCPGATE_CONFIG=$(cat mcpgate.yaml | base64 -w 0) \
  -e GITHUB_TOKEN=$GITHUB_TOKEN \
  ghcr.io/mprezz/mcpgate

Railway

Deploy on Railway

添加 PostgreSQL 插件以实现持久化审计跟踪 — MCPGate 会自动检测 DATABASE_URL

配置

创建一个 mcpgate.yaml

gateway:
  name: "my-gateway"
  transport: "stdio" # stdio | http | both
  port: 3000
  toolPrefix: true # prefix tools with server name

servers:
  - name: "github"
    transport: "stdio"
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      GITHUB_TOKEN: "${GITHUB_TOKEN}"
    tools:
      allow:
        - "create_issue"
        - "search_repos"

  - name: "filesystem"
    transport: "stdio"
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/home/user"]
    tools:
      block:
        - "write_file"
        - "delete_file"

logging:
  level: "info"

查看 mcpgate.example.yaml 获取完整参考。

工具过滤

每个服务器支持 allowblock(互斥):

  • allow — 仅暴露这些工具(白名单)

  • block — 暴露除这些工具之外的所有工具(黑名单)

  • 都不设置 — 暴露所有工具

身份验证

添加 Bearer Token 以保护 HTTP 传输:

gateway:
  auth:
    token: "${MCPGATE_AUTH_TOKEN}"

配置身份验证后:

  • 所有端点都需要 Authorization: Bearer <token> 请求头

  • /health 保持公开(用于 Railway/Docker 健康检查)

  • MCP 客户端通过其传输配置中的自定义请求头传递 Token

若未配置身份验证,所有端点均为开放状态(适用于本地/私有使用)。

环境变量插值

在 YAML 中使用 ${VAR}${VAR:-default} 来引用环境变量:

env:
  GITHUB_TOKEN: "${GITHUB_TOKEN}"
  API_URL: "${API_URL:-https://api.example.com}"

仪表板

在 HTTP 模式下运行时,MCPGate 在根 URL 提供 Web 仪表板:

  • / — 状态页面,包含上游服务器、工具和请求日志

  • /api/status — 用于程序化访问的 JSON API

  • /health — 健康检查端点(用于 Railway/Docker)

  • /mcp — MCP 协议端点(可流式传输的 HTTP)

存储

MCPGate 记录每个工具调用的耗时和错误信息。

  • 默认 — 内存存储(无需设置,重启后丢失)

  • PostgreSQL — 设置 DATABASE_URL 环境变量(自动创建表)

# Local development with Docker Compose
docker compose up postgres -d
export DATABASE_URL=postgresql://mcpgate:mcpgate@localhost:5432/mcpgate
npx mcp-gate start --config mcpgate.yaml

环境变量

变量

必需

默认值

描述

PORT

3000

HTTP 端口(Railway 会自动设置)

MCPGATE_CONFIG

Base64 编码的 YAML 配置(用于 Railway/Docker)

DATABASE_URL

PostgreSQL 连接字符串(启用持久化审计跟踪)

LOG_LEVEL

info

debug / info / warn / error

MCPGATE_AUTH_TOKEN

用于 HTTP 认证的 Bearer Token(在 YAML 中通过 ${MCPGATE_AUTH_TOKEN} 引用)

开发

git clone https://github.com/mprezz/mcpgate.git
cd mcpgate
npm install

npm run dev          # development with hot reload
npm run build        # compile TypeScript
npm run test         # run tests (vitest)
npm run lint         # eslint
npm run typecheck    # tsc --noEmit

架构

Client (Claude, Cursor)
    │
    ▼ stdio or HTTP/SSE
┌──────────────────────────────┐
│         MCPGate              │
│                              │
│  ┌─────────────────────┐     │
│  │   Tool Registry     │     │  ← filters + namespaces tools
│  └─────────────────────┘     │
│  ┌─────────────────────┐     │
│  │   Tool Router       │     │  ← routes calls to correct server
│  └─────────────────────┘     │
│  ┌─────────────────────┐     │
│  │  Upstream Manager   │     │  ← manages server connections
│  └─────────────────────┘     │
│  ┌─────────────────────┐     │
│  │   Storage           │     │  ← memory or PostgreSQL
│  └─────────────────────┘     │
└──────────────────────────────┘
    │           │           │
    ▼           ▼           ▼
 Server A    Server B    Server C
 (GitHub)  (Filesystem)  (Custom)

许可证

Apache 2.0 — 参见 LICENSE

-
security - not tested
A
license - permissive license
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/martin-santiago/mcpgate'

If you have feedback or need assistance with the MCP directory API, please join our Discord server