MCP Gateway

MCP Gateway

A service orchestration layer for the Model Context Protocol. Manages multiple MCP services through a single unified interface — spawn, supervise, and route tool calls across all your services.

Category
访问服务器

README

MCP Gateway

A service orchestration layer for the Model Context Protocol. Manages multiple MCP services through a single unified interface — spawn, supervise, and route tool calls across all your services.

Key Feature: Lazy Activate

By default, services activate in lazy mode — the process spawns and tool list is fetched, but zero tool schemas are injected into the LLM context. This means you can have hundreds of tools across dozens of services with no token overhead.

activate({name: "google-workspace"})     → 281 tools ready, 0 context tokens
tools({service: "google-workspace"})     → browse available tools
call({service: "...", tool: "...", args}) → call any tool directly

Features

  • Lazy activate — spawn services with 0 context tokens, browse with tools(), call with call()
  • Service orchestration — spawn, stop, restart child MCP services
  • On-demand tool browsingtools({service, filter}) returns tool descriptions as conversation text (not system prompt)
  • Direct routingcall() routes to child connections without needing schema registration
  • Environment variable expansion — use $VAR or ${VAR} in config for secrets
  • Dynamic management — add/remove services at runtime without restarting
  • Health monitoring — built-in ping/health checks
  • Any command — supports bun, node, npx, ssh, or any executable

Quick Start

# Install
bun install

# Create your config from the example
cp gateway.config.example.json gateway.config.json

# Edit gateway.config.json with your services
# Then start the gateway
bun run start

Configuration

gateway.config.json defines your services:

{
  "services": [
    {
      "name": "my-service",
      "command": "bun",
      "args": ["run", "/path/to/service/index.ts"],
      "env": { "API_KEY": "$MY_API_KEY" },
      "autoActivate": false
    }
  ]
}
Field Required Default Description
name yes Unique service identifier
command yes Executable to run (bun, node, npx, ssh, ...)
args no [] Command arguments
env no {} Environment variables (supports $VAR expansion)
autoActivate no false Start automatically on gateway launch
keepAlive no false Always-on: respawn with exponential backoff on crash; never GC'd when idle
groups no Named tool subsets for full-mode activation, e.g. {"gmail": ["send", "search"]}

Environment Variables

Config values support $VAR and ${VAR} syntax, resolved from process.env at load time:

{
  "env": { "API_KEY": "$MY_SECRET_KEY" },
  "args": ["--config", "${HOME}/.config/my-service.json"]
}

This keeps secrets out of your config file. Pass them through your MCP client config (see below).

Built-in Tools

Once running, the gateway exposes these management tools:

Tool Description
services List all services with status, mode (lazy/full), tool count, uptime
activate Start a service. Default lazy (0 context tokens). Set lazy=false for full schema registration
tools List available tools for an active service. Supports filter for keyword search
deactivate Stop a service and clean up
restart Kill and respawn a service (preserves lazy/full mode)
health Ping all active services
add Register a new service dynamically (persists to config)
remove Remove a service from config
call Call any tool on any active service

Workflow

1. activate({name: "my-service"})                        → spawn process, 0 tokens
2. tools({service: "my-service"})                        → see all tools
3. tools({service: "my-service", filter: "search"})      → filter by keyword
4. call({service: "my-service", tool: "...", args: {}})   → call a tool
5. deactivate({name: "my-service"})                      → stop when done

Full Mode (optional)

If you want tool schemas injected into the LLM context (traditional MCP behavior):

activate({name: "my-service", lazy: false})              → register all schemas
activate({name: "my-service", lazy: false, groups: ["gmail", "drive"]})  → register specific groups

HTTP Daemon Mode (always-on, shared)

Set GATEWAY_HTTP_PORT to run the gateway as a long-lived Streamable HTTP daemon instead of per-client stdio:

GATEWAY_HTTP_PORT=8770 bun run start
  • Endpoint: http://127.0.0.1:8770/mcp (Streamable HTTP, Mcp-Session-Id per client)
  • Health: GET /health returns JSON with session count and per-service status/pid
  • Shared processes, isolated views: child services are spawned once and shared by every connected client; each session keeps its own tool registry, so one agent's full-mode activation never leaks into another's context
  • Session GC: sessions idle longer than the TTL are swept automatically (clients often exit without sending DELETE). Tune with GATEWAY_SESSION_TTL_MS (default 60 min) and GATEWAY_SESSION_SWEEP_MS (default 5 min)
  • Safe boot: GATEWAY_NO_AUTOACTIVATE=1 skips autoActivate services (e.g. when stateful singletons are already running elsewhere)

A systemd unit is provided in deploy/mcp-gateway.service.

Point Claude Code (or any MCP client) at the daemon:

{
  "mcpServers": {
    "gateway": { "type": "http", "url": "http://127.0.0.1:8770/mcp" }
  }
}

Using with Claude Code

Add to your Claude Code MCP config (~/.claude/config.json or project settings). API keys go in the env block — they're passed to the gateway process and expanded in gateway.config.json via $VAR syntax:

{
  "mcpServers": {
    "gateway": {
      "command": "bun",
      "args": ["run", "/path/to/mcp-gateway/src/index.ts"],
      "env": {
        "GEMINI_API_KEY": "your-gemini-key",
        "EXA_API_KEY": "your-exa-key"
      }
    }
  }
}

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选