One shared instance of each stdio MCP server, served to every agent over streamable HTTP.
Coding agents (Claude Code, OpenCode, Codex, Grok, Cursor) start a fresh copy of every stdio MCP server for every session. Run a few agents in parallel and the same server is running ten or twenty times. On the machine this was written for that was 66 processes and 8 GB of RAM for servers that were idle most of the day.
mcp-hub runs each server once, lazily, and hands it to every session over the MCP streamable-HTTP transport that all of those harnesses already support:
- one child per server, spawned on the first request, shared by every session
- idle reaping: a child with no requests for
idleMinutesis killed; a client's session survives that, the next call respawns the child transparently - per-root pooling for servers that index their working directory (one child per root)
GET /statustells you what is alive, its pid, RSS, sessions and idle time
git clone https://github.com/andrebrov/mcp-hub && cd mcp-hub && npm install cp examples/mcp-hub.example.json ~/.config/mcp-hub.json # edit node hub.mjs # or: node hub.mjs /path/to/config.json
Requires Node 20+. The only dependency is @modelcontextprotocol/sdk.
~/.config/mcp-hub.json (or $MCP_HUB_CONFIG, or the first argument):
{
"port": 7900,
"idleMinutes": 20,
"requestTimeoutMinutes": 20,
"servers": {
"context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"] },
"github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "..." } },
"codegraph": { "command": "codegraph", "args": ["serve", "--mcp", "-p", "{root}"],
"cwd": "{root}", "perRoot": true }
}
}Each server becomes http://127.0.0.1:7900/<name>/mcp. Children inherit the hub's
environment plus env. For perRoot servers the client passes ?root=/abs/path or an
X-Root header, and {root} in args/cwd is replaced with it.
Claude Code (.mcp.json in the project, or claude mcp add --transport http):
{ "mcpServers": { "context7": { "type": "http", "url": "http://127.0.0.1:7900/context7/mcp" } } }OpenCode (~/.config/opencode/opencode.json). {env:PWD} gives per-root servers the
session's own directory:
{ "mcp": {
"context7": { "type": "remote", "url": "http://127.0.0.1:7900/context7/mcp", "enabled": true },
"codegraph": { "type": "remote", "url": "http://127.0.0.1:7900/codegraph/mcp",
"headers": { "X-Root": "{env:PWD}" }, "enabled": true }
} }Codex (~/.codex/config.toml) and Grok (~/.grok/config.toml):
[mcp_servers.context7] url = "http://127.0.0.1:7900/context7/mcp"
Grok also imports Cursor's and Claude's MCP lists by default; turn that off with
[compat.cursor] mcps = false / [compat.claude] mcps = false or you get both copies.
macOS: examples/com.example.mcp-hub.plist goes in ~/Library/LaunchAgents (edit the paths),
then launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.mcp-hub.plist.
After editing the hub: launchctl kickstart -k gui/$(id -u)/com.example.mcp-hub.
Linux: examples/mcp-hub.service is a systemd user unit
(systemctl --user enable --now mcp-hub).
node check.mjs http://127.0.0.1:7900/context7/mcp # handshake + tool list node check.mjs http://127.0.0.1:7900/github/mcp search_repositories '{"query":"mcp"}' curl -s http://127.0.0.1:7900/status | jq
- Isolation between sessions. All sessions on a child share that child's state, and a notification the child emits (tool list changed, log message) reaches every session. That is right for tool servers; do not put a server that keeps secret per-session state behind the hub.
- Auth. It binds to 127.0.0.1 only and has no authentication. Do not expose the port.
- Requests that outlive the idle window. The reaper only looks at when the last request
started, so a single tool call longer than
idleMinutescan be cut off. RaiseidleMinutesfor servers with very long calls; the next request spawns a fresh child.
MIT