MCP Gateway

MCP Gateway

Lightweight Model Context Protocol gateway that exposes one entry point for multiple downstream MCP services, enabling efficient tool discovery and routing.

Category
访问服务器

README

English | 简体中文

MCP Gateway

MCP Gateway is a lightweight Model Context Protocol gateway that exposes one small MCP entry point for multiple downstream MCP services.

Instead of flattening every downstream tool into the client at startup, the gateway exposes a fixed discovery and routing API. Agents can list services, inspect tools for one service, fetch one schema, and then forward the actual tool call.

Features

  • One MCP entry point for multiple downstream MCP services.
  • Token-efficient discovery through a small fixed gateway tool surface.
  • Stdio and Streamable HTTP downstream transports.
  • Optional inbound Streamable HTTP endpoint enabled by CLI flags.
  • Hot reload for service-pool config changes.
  • Stops removed, disabled, or replaced downstream services during reload.
  • Restarts failed downstream processes up to three times before marking them unavailable.
  • Atomic config reload that keeps the previous valid config when a new config is invalid.
  • Optional newline-delimited JSON file logging that never writes operational logs to MCP stdout.
  • Version reporting through --version or -v.

Why Use It

  • Keep agent-side MCP configuration small: every agent connects to the gateway, while downstream services are managed in one config file.
  • Reduce initial tool context: agents discover only the service, tool, and schema needed for the current task.
  • Keep service lifecycle control centralized instead of duplicating command paths, environment variables, and secrets across multiple clients.

Quick Start

Install globally:

npm install -g @jadchene/mcp-gateway-service

Create a local config:

cp config.example.json config.json

Start the stdio gateway:

mcp-gateway-service --config ./config.json

Start with inbound Streamable HTTP:

mcp-gateway-service --config ./config.json --http --host 127.0.0.1 --port 3100 --path /mcp

Use stateless JSON responses for HTTP clients that expect direct JSON-RPC responses from POST:

mcp-gateway-service --config ./config.json --http --port 3100 --path /mcp --json-response

Check the installed version:

mcp-gateway-service --version
mcp-gateway-service -v

Configuration

Pass the config file by CLI argument:

mcp-gateway-service --config ./config.json

Or by environment variable:

MCP_GATEWAY_CONFIG=./config.json mcp-gateway-service

If neither is provided, the service tries config.json in the current working directory.

Config example:

{
  "logging": {
    "enable": false,
    "path": "./logs/mcp-gateway.log"
  },
  "services": [
    {
      "serviceId": "demo-echo",
      "enable": true,
      "name": "Demo Echo Service",
      "description": "Sample echo MCP service.",
      "transport": {
        "type": "stdio",
        "command": "node",
        "args": [
          "--experimental-strip-types",
          "examples/echo-service.ts"
        ]
      }
    },
    {
      "serviceId": "remote-http",
      "enable": false,
      "name": "Remote Streamable HTTP Service",
      "description": "Example downstream MCP service over Streamable HTTP.",
      "transport": {
        "type": "http",
        "url": "http://127.0.0.1:3200/mcp",
        "headers": {
          "Authorization": "Bearer ${MCP_TOKEN}"
        },
        "enableJsonResponse": false
      }
    }
  ]
}

Configuration notes:

  • logging.enable defaults to false.
  • logging.path is required only when logging.enable is true.
  • Relative logging.path values are resolved from the config file directory.
  • Service enable defaults to true; setting it to false skips that service.
  • cwd and env are optional for stdio services.
  • Stdio transport.framing may be line or content-length. When omitted, the gateway tries line and then content-length.
  • HTTP downstream services use transport.type: "http" and transport.url.
  • HTTP transport.headers provides static request headers.
  • HTTP transport.enableJsonResponse enables stateless JSON response mode for that downstream service.

Inbound Streamable HTTP

Inbound HTTP is enabled only with --http. Passing --host, --port, --path, or --json-response without --http does not start an HTTP listener.

The HTTP endpoint uses the same path for GET and POST:

  • GET /mcp opens the SSE read channel and returns the session in the Mcp-Session-Id response header.
  • POST /mcp sends JSON-RPC messages. New clients should bind the session through the Mcp-Session-Id request header.
  • Query-string sessionId is accepted for compatibility.
  • The endpoint SSE event advertises the single path, such as /mcp.

Gateway Tools

The gateway exposes six public tools:

Tool Purpose
gateway_list_services List all downstream MCP services managed by the gateway, including each serviceId, description, and availability.
gateway_get_service Return one service summary, runtime state, recent errors, and cached metadata. Use this for diagnostics.
gateway_list_tools List tools exposed by one downstream service. Optional toolName filters by one or more name fragments.
gateway_get_tool_schema Return the input and output schema for one downstream tool.
gateway_manage_service Reconnect a service or persistently enable/disable it in the config file.
gateway_call_tool Call one downstream tool through the gateway and return the downstream MCP result.

Default token-efficient workflow:

  1. Call gateway_list_services once.
  2. Call gateway_list_tools(serviceId) only when a service is needed. Use toolName to filter large tool lists by name.
  3. Call gateway_get_tool_schema(serviceId, toolName) before first use of a tool.
  4. Call gateway_call_tool to execute the downstream tool.
  5. Use gateway_get_service only for diagnostics.
  6. Use gateway_manage_service only to reconnect, enable, or disable a service.

gateway_manage_service actions:

  • reconnect: retry the current downstream lifecycle without modifying config.
  • enable: persist enable: true for the service and reload config.
  • disable: persist enable: false for the service and reload config.

Skill Integration

This repository includes a public gateway skill:

  • Skill path: skills/mcp-gateway/SKILL.md

Use it when your agent supports skills. It keeps discovery token-efficient and routes downstream calls through the minimal gateway contract.

MCP Client Configuration

Codex:

[mcp_servers.gateway]
command = "mcp-gateway-service"
args = ["--config", "./config.json"]

Gemini CLI:

{
  "mcpServers": {
    "gateway": {
      "type": "stdio",
      "command": "mcp-gateway-service",
      "args": ["--config", "./config.json"]
    }
  }
}

Claude Code:

{
  "mcpServers": {
    "gateway": {
      "type": "stdio",
      "command": "mcp-gateway-service",
      "args": ["--config", "./config.json"]
    }
  }
}

Streamable HTTP mode:

Start one shared HTTP gateway process first:

mcp-gateway-service --config ./config.json --http --host 127.0.0.1 --port 3100 --path /mcp

Then point MCP clients at the HTTP endpoint.

Codex:

[mcp_servers.gateway]
url = "http://127.0.0.1:3100/mcp"

Gemini CLI:

{
  "mcpServers": {
    "gateway": {
      "httpUrl": "http://127.0.0.1:3100/mcp"
    }
  }
}

Claude Code:

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

Use the same URL for every client that should share the gateway service pool. Use --json-response only when your HTTP client expects stateless JSON-RPC responses directly from POST requests.

Development

npm install
npm run dev

Build and test:

npm run build
npm test

Run the built server:

node dist/index.js --config ./config.json

License

MIT. See LICENSE.

推荐服务器

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

官方
精选