
Router
STDIOPython-based unified gateway for multiple MCP servers with web management and intelligent routing
Python-based unified gateway for multiple MCP servers with web management and intelligent routing
MCP Router is a Python-based unified gateway for multiple Model Context Protocol (MCP) servers. It provides a web interface for managing servers, intelligent routing with hierarchical tool discovery, and sandboxed execution environments for any programming language.
# Clone the repository git clone https://github.com/locomotive-agency/mcp-router.git cd mcp-router # Run the setup script (installs Docker and sets up the project) chmod +x setup.sh ./setup.sh # Edit configuration nano .env # Add your ANTHROPIC_API_KEY and set ADMIN_PASSCODE # Start the web interface source venv/bin/activate python -m mcp_router.web # Open in browser open http://localhost:8000
We provide a setup script that handles Docker installation and project setup:
chmod +x setup.sh ./setup.sh
The script will:
Install Docker
Clone and Install
git clone https://github.com/locomotive-agency/mcp-router.git cd mcp-router # Create virtual environment python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install package pip install -e . # Create data directory mkdir -p data # Copy environment template cp env.example .env
Configure Environment
Edit .env
file with your settings:
# Required for security ADMIN_PASSCODE=your-secure-passcode-here # Required for repository analysis ANTHROPIC_API_KEY=your-api-key-here # Optional customizations MCP_PYTHON_IMAGE=python:3.11-slim MCP_NODE_IMAGE=node:20-slim
MCP Router includes a simple passcode-based authentication system to protect the admin interface when hosted remotely.
Set a strong passcode in your .env
file:
ADMIN_PASSCODE=your-secure-passcode-here
First-time login:
Security Notes:
Start Web Interface
source venv/bin/activate python -m mcp_router.web
Access at: http://localhost:8000
First time: You'll be prompted to log in with your passcode.
Add MCP Servers
Control MCP Server
~/Library/Application Support/Claude/claude_desktop_config.json
):
{ "mcpServers": { "mcp-router": { "command": "/path/to/venv/bin/python", "args": ["-m", "mcp_router.server"] } } }
from fastmcp import Client from fastmcp.client.auth import BearerAuth # Connect to HTTP transport async with Client( "http://localhost:8001/mcp/", auth=BearerAuth(token="your-api-key") ) as client: # List available providers providers = await client.call_tool("list_providers") print(f"Available servers: {providers}") # List tools from a specific provider tools = await client.list_tools(provider="github-mcp-server") # Call a tool result = await client.call_tool( "search_repositories", provider="github-mcp-server", query="mcp servers" )
docker-compose up --build
┌─────────────────┐ ┌─────────────────┐
│ Claude Desktop │ │ Web Browser │
│ (stdio) │ │ (Admin UI) │
└────────┬────────┘ └────────┬────────┘
│ │
│ stdio │ HTTP
│ │
┌────────┴───────────────────────┴────────┐
│ MCP Router Service │
│ ┌─────────────┐ ┌──────────────┐ │
│ │ Flask Web │ │ FastMCP │ │
│ │ Interface │ │ Proxy Router │ │
│ └─────────────┘ └──────────────┘ │
│ ┌─────────────┐ ┌──────────────┐ │
│ │ Claude │ │ Container │ │
│ │ Analyzer │ │ Manager │ │
│ └─────────────┘ └──────────────┘ │
└─────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
│ │ │
┌───▼────┐ ┌────▼────┐ ┌────▼────┐
│ NPX │ │ UVX │ │ Docker │
│(Node.js)│ │(Python) │ │ (Any) │
└────────┘ └─────────┘ └─────────┘
The router implements a two-step discovery pattern to prevent overwhelming LLMs:
python_sandbox
and list_providers
visiblelist_providers()
returns available serverstools/list(provider="server_name")
shows server-specific toolsprovider
parameter for routingThis design maintains a clean, stateless architecture while providing intuitive navigation.
Create a .env
file with:
# Flask Configuration FLASK_PORT=8000 FLASK_ENV=development SECRET_KEY=your-secret-key-here # Authentication (REQUIRED for security) ADMIN_PASSCODE=your-secure-passcode-here # Claude API (Required for GitHub analysis) ANTHROPIC_API_KEY=sk-ant-... # Docker Configuration DOCKER_HOST=unix:///var/run/docker.sock # Linux/Mac # DOCKER_HOST=tcp://localhost:2375 # Windows # Container Images (Optional) MCP_PYTHON_IMAGE=python:3.11-slim # For Python servers MCP_NODE_IMAGE=node:20-slim # For Node.js servers # MCP Server Configuration (Set via UI) MCP_TRANSPORT=http # stdio, http, or sse MCP_HOST=127.0.0.1 MCP_PORT=8001 MCP_PATH=/mcp MCP_API_KEY=auto-generated-if-not-set
Runtime | Command | Use Case | Base Image |
---|---|---|---|
npx | npx @org/package | Node.js/TypeScript servers | node:20-slim |
uvx | uvx package | Python servers | python:3.11-slim |
docker | docker run ... | Any language/custom setup | User specified |
source venv/bin/activate pytest -v
mcp-router/
├── src/mcp_router/ # Main package
│ ├── app.py # Flask application
│ ├── auth.py # Authentication system
│ ├── server.py # MCP server with FastMCP
│ ├── container_manager.py # Docker container lifecycle
│ ├── claude_analyzer.py # GitHub repo analysis
│ ├── middleware.py # Provider filter middleware
│ ├── models.py # SQLAlchemy models
│ ├── server_manager.py # MCP server processes
│ ├── templates/ # Jinja2 templates
│ └── static/ # CSS, JS assets
├── tests/ # Test suite
├── data/ # SQLite database
├── docker-compose.yml # Container orchestration
├── setup.sh # Automated setup script
└── .env.example # Environment template
Smart Image Management
Container Lifecycle
Efficient Routing
Docker not running
# Linux sudo systemctl start docker # macOS # Start Docker Desktop from Applications
Permission denied errors
# Add user to docker group (Linux) sudo usermod -aG docker $USER # Log out and back in
NPM idealTree errors
docker system prune
Port already in use
# Change port in .env file FLASK_PORT=8080 MCP_PORT=8002
Login issues
This is an MVP project with a focused 4-week timeline. Contributions should align with the roadmap in project.md
.
[License information to be added]