Universal MCP Gateway

Universal MCP Gateway

A self-hosted MCP gateway that aggregates all your MCP servers behind a single Streamable HTTP endpoint, with automatic registry discovery (19,000+ servers), on-demand Docker provisioning, multi-device support via SSH, OAuth2 PKCE authentication, and a workflow engine for saving and replaying multi-step tool sequences.

Category
访问服务器

README

Universal MCP Gateway

A self-hosted Model Context Protocol (MCP) gateway that aggregates all your MCP servers behind a single Streamable HTTP endpoint. Includes automatic registry discovery, on-demand Docker provisioning, and multi-device support.

Features

  • Single Endpoint — All MCP servers exposed via one URL (/all for universal, /mcp for legacy)
  • Registry Auto-Broker — Mirrors the official MCP Registry (19,000+ servers), provisions on demand in isolated Docker containers
  • Multi-Device — Control server, laptop, and Windows PC from one gateway via SSH
  • SSE Keepalive — Prevents Cloudflare/proxy idle timeouts on streaming connections
  • OAuth2 PKCE — Optional OAuth2 authorization code flow with PKCE support
  • Workflow Engine — Save and replay multi-step tool sequences
  • Bearer Auth — Simple token-based authentication

Architecture

                    mcp.yourdomain.com (:8798)
                           │
                    ┌──────▼──────┐
                    │ MCP Router  │  Path-based routing
                    │  router.mjs │  /all → Universal, /mcp → Legacy
                    └──────┬──────┘
                           │
              ┌────────────┼────────────┐
              │            │            │
    ┌─────────▼──┐  ┌─────▼────┐  ┌──▼──────────┐
    │ Universal  │  │ Registry │  │  Child MCPs │
    │ Gateway    │  │ Autobroker│  │ (remote +   │
    │ gateway.mjs│  │ registry- │  │  stdio)     │
    └────────────┘  │ manager   │  └─────────────┘
                    └───────────┘

Quick Start

# Clone
git clone https://github.com/Samuel-Mencke/mcp-gateway.git
cd mcp-gateway

# Install dependencies
npm install

# Configure
cp .env.example .env
# Edit .env — set MCP_PUBLIC_URL and generate a token

# Generate auth token
echo -n "$(openssl rand -hex 32)" > ~/.mcp-gateway/token

# Start the gateway
node gateway.mjs    # Port 8799
# In another terminal:
node router.mjs     # Port 8798 (public-facing)

Configuration

All configuration is via environment variables. See .env.example for all options.

Key Variables

Variable Default Description
MCP_PORT 8799 Universal Gateway listen port
MCP_ROUTER_PORT 8798 Router listen port
MCP_PUBLIC_URL http://localhost:8798 Your public URL (domain/tunnel)
MCP_STATE_DIR ~/.mcp-gateway State directory (registry, tokens, etc.)
MCP_BEARER_TOKEN (from $MCP_STATE_DIR/token) Auth token

Multi-Device (Optional)

Set these to enable SSH-based remote control:

# Windows PC
MCP_PC_HOST=windows-host
MCP_PC_USER=username

# Linux laptop
MCP_LAPTOP_HOST=laptop-host
MCP_LAPTOP_USER=username

Default MCP Servers

The gateway ships with these servers enabled by default:

  • Context7 — Current library documentation
  • Exa — Web search and fetch
  • MCP Docs — Official MCP documentation
  • GitHub — Official GitHub MCP server (requires gh auth)
  • Playwright — Browser automation
  • Chrome DevTools — Debugging and performance
  • Filesystem — Sandboxed file access
  • Memory — Persistent knowledge graph
  • Sequential Thinking — Structured planning

Additional servers can be provisioned on demand from the official MCP Registry via ensure_capability.

Registry Auto-Broker

The gateway mirrors the complete official MCP Registry and can provision any supported server on demand:

Agent: "I need PostgreSQL schema inspection"
Gateway: Searches registry → provisions postgres-mcp → probes handshake → ready

Provisioned servers run in restricted Docker containers:

  • Read-only root filesystem
  • No host mounts
  • Dropped capabilities
  • CPU/RAM/PID limits
  • Blocked private/Tailscale egress

Deployment

systemd

# ~/.config/systemd/user/mcp-router.service
[Unit]
Description=MCP Router
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
WorkingDirectory=%h/mcp-gateway
Environment=MCP_ROUTER_PORT=8798
ExecStart=/usr/bin/node %h/mcp-gateway/router.mjs
Restart=always
RestartSec=5

[Install]
WantedBy=default.target
# ~/.config/systemd/user/mcp-universal.service
[Unit]
Description=MCP Universal Gateway
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
WorkingDirectory=%h/mcp-gateway
EnvironmentFile=%h/mcp-gateway/.env
ExecStart=/usr/bin/node %h/mcp-gateway/gateway.mjs
Restart=always
RestartSec=5
TimeoutStopSec=20

[Install]
WantedBy=default.target

Cloudflare Tunnel

No port-forwarding needed — use a Cloudflare Tunnel:

# ~/.cloudflared/config.yml
ingress:
  - hostname: mcp.yourdomain.com
    service: http://127.0.0.1:8798
    originRequest:
      noTLSVerify: true
      connectTimeout: 30s
      keepAliveConnections: 100
      keepAliveTimeout: 600s

Client Configuration

The gateway works with any MCP-compatible client:

Client Config
Claude Code type: "url", url: "https://mcp.yourdomain.com/all"
OpenAI Codex type: "streamable-http", url: "https://mcp.yourdomain.com/all"
Cursor url: "https://mcp.yourdomain.com/all", transport: "streamable-http"
Hermes Agent type: "streamable-http", url: "https://mcp.yourdomain.com/all"
OpenCode type: "streamable-http", url: "https://mcp.yourdomain.com/all"

All clients need: headers: { Authorization: "Bearer <your-token>" }

Files

File Description
router.mjs Path-based router, OAuth2, SSE keepalive
gateway.mjs Universal MCP gateway server
registry-manager.mjs Registry sync, auto-provisioning, AGENTS.md generation
workflow-store.mjs Durable workflow persistence
server.mjs Legacy ChatGPT connector (admin/SSH tools)
windows-runner.py Windows desktop automation runner

Requirements

  • Node.js >= 18
  • Docker (for registry auto-provisioning)
  • SSH access (for multi-device support)

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选