An r/opencodeCLI thread documented 35 npm processes and 4 GB of RAM serving MCP servers across pi, VS Code, and opencode. The fix is a single MCP daemon. This tutorial walks the setup.
Prerequisites
- Node 20+
- Claude Desktop / Cursor / opencode (any combination)
Walkthrough
Step 1: Pick a gateway implementation
FastMCP and @modelcontextprotocol/server-everything are the common starting points.
npm install -g @modelcontextprotocol/server-gatewayStep 2: Define the upstream MCP fleet
Single config lists all servers the daemon proxies.
{
"upstreams": {
"scavio": { "url": "https://mcp.scavio.dev/mcp", "headers": { "x-api-key": "${SCAVIO_API_KEY}" } },
"playwright": { "command": "npx", "args": ["@playwright/mcp"] },
"shadcn": { "command": "npx", "args": ["@shadcn/mcp"] }
}
}Step 3: Run the daemon as a single process
HTTP mode lets agents connect remotely.
mcp-gateway --config gateway.json --http --port 8765 &Step 4: Point each agent at the daemon
All agents see the same fleet.
// .cursor/mcp.json AND ~/.config/Claude/claude_desktop_config.json AND opencode config
{
"mcpServers": {
"gateway": { "url": "http://localhost:8765/mcp" }
}
}Step 5: Verify the consolidation
Check process count + RAM before vs after.
ps aux | grep -E 'mcp|npm exec' | wc -l
# Before: 35+. After: 1.Python Example
# This tutorial is config-driven; no Python sample needed.JavaScript Example
// See JSON config blocks above.Expected Output
Process count drops from 35+ to 1. RAM drops from ~4 GB to ~200 MB. Schema-load tokens drop from 50K to under 500.