traefik-hub-mcp
# traefik-hub-mcp
MCP server for managing a local Traefik reverse proxy from Claude Code. Inspect routers, services, and middlewares; manage Docker containers; health-check domains; and configure CORS and middleware -- all without leaving your editor.
## Installation
```bash
# Run directly (recommended for Claude Code)
npx traefik-hub-mcp
# Or install globally
npm install -g traefik-hub-mcp
```
## Prerequisites
- **Node.js** >= 18
- **Docker** running (Docker Desktop or daemon)
- A **Traefik** stack managed via `docker-compose.yml` (see [traefik-hub](https://github.com/dominic-righthere/traefik-hub) for a ready-made setup)
## Environment Variables
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `TRAEFIK_CONFIG_DIR` | Yes | -- | Path to Traefik config directory (contains `traefik.yml` and `dynamic/`) |
| `TRAEFIK_HUB_DIR` | Yes | -- | Path to the Traefik Hub repo root (contains `docker-compose.yml`) |
| `TRAEFIK_API_URL` | No | `http://localhost:8080` | Traefik API base URL |
| `TRAEFIK_DOMAIN_ALIASES` | No | -- | Comma-separated domain suffixes for multi-domain routing (e.g., `local.domlee.dev`) |
## Configuration
### Claude Code
```bash
claude mcp add traefik -e TRAEFIK_HUB_DIR=/path/to/traefik-hub -e TRAEFIK_CONFIG_DIR=/path/to/traefik-hub/traefik -e TRAEFIK_API_URL=http://localhost:8080 -- npx -y traefik-hub-mcp
```
Or add manually to `~/.claude.json` or project `.mcp.json`:
```json
{
"mcpServers": {
"traefik": {
"command": "npx",
"args": ["-y", "traefik-hub-mcp"],
"env": {
"TRAEFIK_HUB_DIR": "/path/to/traefik-hub",
"TRAEFIK_CONFIG_DIR": "/path/to/traefik-hub/traefik",
"TRAEFIK_API_URL": "http://localhost:8080"
}
}
}
}
```
### Cursor
Add to Cursor Settings > MCP Servers:
```json
{
"mcpServers": {
"traefik": {
"command": "npx",
"args": ["-y", "traefik-hub-mcp"],
"env": {
"TRAEFIK_HUB_DIR": "/path/to/traefik-hub",
"TRAEFIK_CONFIG_DIR": "/path/to/traefik-hub/traefik",
"TRAEFIK_API_URL": "http://localhost:8080"
}
}
}
}
```
### VS Code (Copilot)
Add to your VS Code `settings.json`:
```json
{
"mcp": {
"servers": {
"traefik": {
"type": "stdio",
"command": "npx",
"args": ["-y", "traefik-hub-mcp"],
"env": {
"TRAEFIK_HUB_DIR": "/path/to/traefik-hub",
"TRAEFIK_CONFIG_DIR": "/path/to/traefik-hub/traefik",
"TRAEFIK_API_URL": "http://localhost:8080"
}
}
}
}
}
```
### Windsurf
Add to `~/.codeium/windsurf/mcp_config.json`:
```json
{
"mcpServers": {
"traefik": {
"command": "npx",
"args": ["-y", "traefik-hub-mcp"],
"env": {
"TRAEFIK_HUB_DIR": "/path/to/traefik-hub",
"TRAEFIK_CONFIG_DIR": "/path/to/traefik-hub/traefik",
"TRAEFIK_API_URL": "http://localhost:8080"
}
}
}
}
```
### Cline
Add to Cline MCP settings:
```json
{
"mcpServers": {
"traefik": {
"command": "npx",
"args": ["-y", "traefik-hub-mcp"],
"env": {
"TRAEFIK_HUB_DIR": "/path/to/traefik-hub",
"TRAEFIK_CONFIG_DIR": "/path/to/traefik-hub/traefik",
"TRAEFIK_API_URL": "http://localhost:8080"
},
"disabled": false
}
}
}
```
## Tools
### Traefik API
| Tool | Description |
|------|-------------|
| `traefik_status` | Traefik version and component counts |
| `list_routers` | List HTTP routers (optionally filter by provider) |
| `list_services` | List HTTP services (optionally filter by provider) |
| `list_middlewares` | List all HTTP middlewares |
| `get_router` | Get details of a specific router |
### Docker
| Tool | Description |
|------|-------------|
| `list_containers` | List containers on the `traefik-public` network |
| `container_logs` | Get logs from a container |
| `restart_container` | Restart a container |
| `rebuild_service` | Rebuild and recreate a Docker Compose service (`docker compose up -d --build`) |
### Health & Diagnostics
| Tool | Description |
|------|-------------|
| `check_health` | Check if a domain is responding |
| `doctor` | Comprehensive stack health check (Docker, network, container, API, ports, config) |
| `check_update` | Check for newer Traefik versions and whether it's safe to update |
| `check_setup` | Verify MCP env vars and paths are correctly set |
### Stack Management
| Tool | Description |
|------|-------------|
| `start_traefik` | Start the Traefik stack (`docker compose up -d`) |
| `stop_traefik` | Stop the Traefik stack (`docker compose down`) |
| `create_network` | Create the `traefik-public` Docker network |
| `init_stack` | Initialize from scratch (create network + start containers) |
### Configuration
| Tool | Description |
|------|-------------|
| `generate_labels` | Generate docker-compose Traefik labels for a new project |
| `add_middleware` | Add a middleware to `middlewares.yml` (Traefik hot-reloads) |
| `list_middleware_types` | Show available middleware types with example configs |
| `get_cors` | Show current CORS configuration |
| `update_cors` | Add or remove origins from the `cors-dev` middleware |
### Multi-Domain Routing
| Tool | Description |
|------|-------------|
| `add_domain_route` | Add multi-domain route for a service (LAN/Tailscale access) |
| `remove_domain_route` | Remove a multi-domain route |
| `list_domain_routes` | List all multi-domain routes |
## Development
```bash
git clone https://github.com/dominic-righthere/traefik-hub-mcp.git
cd traefik-hub-mcp
npm install
npm run build
npm test
```
## License
MIT
TDQS
Scored across 25 tools
Most tools target distinct resources, but several clusters overlap: traefik_status, doctor, check_health, and check_setup are four different flavors of 'check' that an agent could easily misselect, and init_stack is essentially a superset of create_network plus start_traefik. list_middlewares vs list_middleware_types is also a subtle distinction (configured vs available) that names alone don't clarify.
The dominant pattern is snake_case verb_noun (list_routers, get_router, add_middleware, remove_domain_route), which is applied consistently across most tools. Deviations are minor: noun-first names like traefik_status, container_logs, and the bare doctor break the pattern but remain readable.
At 25 tools this sits at the heavy end of the scale, spanning Traefik API inspection, Docker container ops, stack lifecycle, domain routing, CORS, and middleware config. Each area is legitimate, but the surface is broad enough that some tools (init_stack, check_setup, doctor) feel like conveniences layered on top of already-covered operations.
The server covers inspection and lifecycle well: routers/services/middlewares are readable, stack start/stop/init/create_network exist, containers can be listed/logged/restarted/rebuilt, and CORS/domain routes have full add/remove/get coverage. Gaps remain on the mutation side for middlewares (add but no update/remove single middleware) and no get_service or router create/update, though generate_labels partly compensates.