mcp-router-local

mcp-router-local

Aggregates multiple MCP servers behind a single local endpoint, letting LLM clients connect to one router that exposes a unified set of tools, resources, and prompts.

Category
访问服务器

README

mcp-router-local

Zero-dependency local Model Context Protocol (MCP) router. Aggregate multiple MCP servers behind a single endpoint so an LLM client (Claude Desktop, Claude Code, Cursor, or any JSON-RPC 2.0 over stdio/SSE client) connects to one router instead of managing many individual server processes.

Built on native Node.js modules only — child_process, readline, fs, path, http. No runtime dependencies, no third-party parsers, nothing to install but the router itself.

Features

  • Single endpoint aggregation — one stdio connection (or one local SSE endpoint) that fronts every configured sub-server.
  • Dynamic config discovery — reads mcp-router.config.json from the current working directory: executable paths, arguments, env vars, and per-server behavior.
  • Protocol aggregation — spawns every sub-server on startup, performs the MCP handshake, and merges tools/list, resources/list, resources/templates/list, and prompts/list into one unified capability manifest.
  • Intelligent routing — tools/call, resources/read, and prompts/get are intercepted, matched to the owning sub-server, forwarded, and the response is safely returned to the client. Tool-name collisions across servers are auto-namespaced.
  • Process safety — a crashing sub-server is logged to a local debug file (never stdout, so the JSON-RPC stream stays clean) and restarted with capped exponential backoff. On exit, all children are terminated gracefully (SIGTERM → SIGKILL).

Requirements

  • Node.js ≥ 18 (ESM)

Install

npm install -g mcp-router-local   # global CLI: mcp-router
# or run without installing:
npx mcp-router-local

Quick start

Create mcp-router.config.json in the directory you'll run the router from:

{
  "servers": [
    {
      "id": "filesystem",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    },
    {
      "id": "db",
      "command": "python",
      "args": ["db_mcp_server.py"],
      "env": { "DATABASE_URL": "postgres://localhost/app" }
    }
  ]
}

Then start the router:

mcp-router

Point your LLM client at it. For a client that spawns servers over stdio, configure the command mcp-router (with --config <path> if needed). For example, Claude Code:

{
  "mcpServers": {
    "all-my-servers": {
      "command": "mcp-router",
      "args": ["--config", "/absolute/path/to/mcp-router.config.json"]
    }
  }
}

The router announces itself as a single server exposing the union of every sub-server's tools, resources, and prompts. From the client's perspective there is only one server.

Configuration reference

Key Type Default Description
name string mcp-router-local Server name sent in the initialize handshake.
version string 0.1.0 Server version sent in the handshake.
transport.type "stdio" | "sse" "stdio" Client-facing transport.
transport.host string 127.0.0.1 SSE bind host.
transport.port number 8765 SSE bind port.
servers[] array — Required. At least one sub-server entry.
timeouts.initialize number (ms) 15000 Handshake timeout per sub-server.
timeouts.list number (ms) 15000 tools/list / resources/list / prompts/list timeout.
timeouts.call number (ms) 60000 tools/call timeout.
timeouts.general number (ms) 30000 resources/read / prompts/get timeout.
debug.enabled boolean false Mirror warnings/errors to stderr.
debug.logFile string ./mcp-router.debug.log Diagnostic log path (resolved next to the config file).

Server entry (servers[])

Key Type Default Description
id string — Required. Unique id used for routing and logs.
command string — Required. Executable to spawn.
args string[] [] Arguments passed to the executable.
cwd string inherit Working directory for the child process.
env object inherit Extra env vars merged over the router's environment.
autoRestart boolean true Restart the child after a crash.
maxRestarts number 5 Restart attempts before giving up.

Transports

stdio (default)

mcp-router reads line-delimited JSON-RPC from stdin and writes responses to stdout. All diagnostics go to the debug file (and optionally stderr) — stdout carries only JSON-RPC, so your client never sees log noise.

SSE

Set transport.type to "sse", then:

  • GET http://host:port/sse — opens the event stream (sends event: endpoint).
  • POST http://host:port/message — accepts JSON-RPC bodies, returns 202, and pushes responses over the open stream. Requests received before a client connects are queued and drained on connect.

Handling tool-name collisions

If two sub-servers expose a tool with the same name, the router keeps the first server's name untouched and renames the later one to <serverId>__<toolName>. A warning is written to the debug log:

Tool "shared" exists on both "alpha" and "beta"; exposed as "beta__shared" to avoid collision

Call the renamed tool exactly as exposed; the router strips the prefix and forwards the original name to the owning sub-server.

Crash handling & restart backoff

When a sub-server exits unexpectedly:

  1. A clean error is written to the debug file (stderr too if debug.enabled).
  2. The router attempts a restart with exponential backoff: 1s, 2s, 4s, 8s, 15s… (capped at 15s), up to maxRestarts.
  3. On each restart the router re-runs the handshake, re-gathers capabilities, and rebuilds its routing indexes.
  4. A server that stays alive for 2 minutes resets its restart counter.

Demo

A self-contained demo ships in demo/ — no real MCP servers needed:

npm run build
node demo/run.mjs

It starts the router against two built-in mock servers (alpha and beta), runs an initialize handshake, lists the merged tools, and calls tools on both — including the collision-renamed beta__shared — then tears everything down. Open demo/mcp-router.config.json to see the shape it uses.

Development

npm install
npm run type-check   # strict TypeScript
npm run build        # tsup -> dist/index.js + dist/index.d.ts

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

官方
精选