A drop-in Python scaffold with auth, rate limiting, structured logs, sandbox-safe reference tools (DB / HTTP / FS), Docker + Fly.io deploy, and 43 regression tests proving each guard works.
../../etc/passwd)~50%Source: protodex.io โ an index of public MCP servers with security scores. This boilerplate fixes all five out of the box, with regression tests proving each guard works.
A single Python package. Read it in one sitting. No framework lock-in, no magic, no telemetry phoning home.
mcp-server-boilerplate/ โโโ src/ โ โโโ server.py # FastMCP entry โ wire everything together โ โโโ auth.py # API key + JWT auth, constant-time compare โ โโโ rate_limit.py # Token-bucket limiter (in-memory or Redis) โ โโโ logging.py # Structured JSON logs via structlog โ โโโ errors.py # Self-describing tool error envelopes โ โโโ tools/ โ โโโ database.py # Read-only Postgres tool (allow-list + READ ONLY tx) โ โโโ http_api.py # External API wrapper (allow-list + SSRF guards + cache) โ โโโ filesystem.py # Sandboxed read/write (path-traversal proof) โโโ tests/ # 43 passing tests โ auth, rate-limit, tool validation โโโ deploy/ โ โโโ Dockerfile # Multi-stage, slim, non-root โ โโโ fly.toml # Fly.io deploy config (free-tier compatible) โ โโโ deploy.sh # One-command deploy โโโ examples/ โ โโโ client.py # Sample MCP client to test against the server โ โโโ claude_config.json # Claude Desktop config snippet โโโ docs/ โโโ INSTALL.md # Zero-to-running in 10 minutes โโโ DEPLOY.md # Fly.io + Docker, hardening checklist โโโ ARCHITECTURE.md # Threat model, design choices, extension points
Constant-time key comparison via hmac.compare_digest. Keys from env var or JSON file. Optional JWT with role claim. Role-gating decorator for admin-only tools.
Per-key + server-wide buckets. In-memory by default; flip to Redis with an env var (atomic Lua script โ safe across replicas).
Regex allow-list (SELECT only) + denied keyword set (INSERT/UPDATE/DELETE/DROP/CREATE/ALTER/TRUNCATE/GRANT/INTO/...). Every query wrapped in READ ONLY transaction. Statement timeout + row cap.
Explicit domain allow-list (with subdomain support). Private-IP / loopback / link-local blocked. Auth headers redacted in logs. 5-minute response cache. 3-retry exponential backoff.
Path-traversal proof via Path.resolve() + relative_to(). Extension allow-list. Binary file detection. Atomic writes (tempfile + rename, no partial files).
structlog with trace IDs per request. Every gate decision logged. Auth headers + secrets redacted at the log layer (not at the call site โ so you can't accidentally leak).
Multi-stage Dockerfile (slim runtime, non-root user). fly.toml tuned for the free tier (256MB, auto-stop). deploy.sh deploys + polls /health, fails loudly if the deploy didn't take.
Every guard has a test that proves it works โ and a sibling test that proves the guard correctly rejects the bypass attempt. Path traversal, SSRF, SQL injection, rate-limit burst/refill, the lot.
cd mcp-server-boilerplate
python3.11 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest # 43 passed in 1.7s
MCP_API_KEYS="dev:alice:admin" python -m src.server
cd deploy
export MCP_API_KEYS="prod:alice:admin"
./deploy.sh first-deploy # Fly.io free tier โ $0/month
Subsequent deploys: ./deploy.sh. Health-check polled automatically; deploy fails if /health doesn't return 200.
A starting point for engineers who need an MCP server that runs longer than a weekend without falling over. Small enough to read in one sitting. Patterns extracted from the auditing 9,640+ public MCP servers.
A framework. A SaaS. A multi-tenant control plane. A replacement for actual security review of your specific deployment. If your threat model is nation-state, hire a real auditor.
$79 one-time. Lifetime updates. Email support to buyers.
Get the boilerplate โ