feat: add /health endpoint bypassing transport security
All checks were successful
Build and Push Proxmox MCP Docker Image / build (push) Successful in 32s

- Migrate from SSE to HTTP transport using fastmcp>=2.0
- Add /health endpoint for Docker health checks and load balancers
- Remove MCP_ALLOWED_HOSTS (no longer needed with http_app approach)
- Add lifespan handler for proper task group initialization
- Install curl in Docker image for health checks
- Update Makefile with test-health and test-mcp targets
- Update documentation to reflect new endpoint structure

Fixes: Health check fails with 421 Misdirected Request when
MCP_ALLOWED_HOSTS doesn't include localhost
This commit is contained in:
Ben
2025-12-20 23:17:55 +00:00
parent 4b576d40ad
commit 18a8c2e59f
6 changed files with 73 additions and 33 deletions

View File

@@ -52,24 +52,35 @@ All tools accept a `cluster` parameter. If only one cluster is configured, it's
services:
proxmox-mcp:
image: gitea.ext.ben.io/b3nw/proxmox-mcp-custom:latest
environment:
- MCP_ALLOWED_HOSTS=proxmox-mcp.example.io,localhost:*
volumes:
- ./clusters.json:/app/clusters.json:ro
ports:
- "8000:8000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
```
### 3. Connect MCP Client
SSE endpoint: `https://your-host/sse`
MCP endpoint: `https://your-host/mcp`
## Endpoints
| Endpoint | Description |
|----------|-------------|
| `/mcp` | MCP HTTP endpoint |
| `/health` | Health check endpoint for Docker/load balancers |
The `/health` endpoint returns `{"status": "ok"}` (or `{"status": "degraded"}` if no clusters are configured) and is designed for Docker health checks.
## Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `MCP_ALLOWED_HOSTS` | `localhost:*,127.0.0.1:*` | Allowed Host headers |
| `CLUSTERS_CONFIG_PATH` | `/app/clusters.json` | Path to clusters config |
## Local Development
@@ -85,12 +96,12 @@ make dev
# Test
make logs
make test-sse
curl http://localhost:8001/health
make stop
```
## Tech Stack
- Python 3.11+ / FastMCP / proxmoxer
- SSE transport / uvicorn
- Python 3.11+ / FastMCP 2.0+ / proxmoxer
- HTTP transport / uvicorn
- Docker with multi-stage build