Caddy
MCP server for managing Caddy web servers via the admin API
Ask AI about Caddy
Powered by Claude Β· Grounded in docs
I know everything about Caddy. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
@yawlabs/caddy-mcp
Manage Caddy web servers from Claude Code, Cursor, and any MCP client. 18 tools + 4 resources covering every endpoint of Caddy's admin API β config, routes, reverse proxies, TLS, PKI, metrics, snapshots.
Built and maintained by Yaw Labs.
One click adds this to your mcp.hosting account so it syncs to every MCP client you use. Or install manually below.
Why this one?
Other Caddy MCP servers wrap half the admin API and silently swallow errors. This one doesn't.
- Complete admin API coverage β every documented endpoint:
/load,/config/*,/id/*,/stop,/adapt,/pki/ca/*,/reverse_proxy/upstreams,/metrics. No placeholder tools that 404. - Safe concurrent writes β uses ETags (
If-Match) so your changes never silently overwrite someone else's. SurfacesHTTP 412 Precondition Failedas a clear message, not a cryptic error. - Safe-by-default mutations β
caddy_config_setdefaults to idempotentoverwrite(PATCH), notappend(POST). Calling twice doesn't duplicate your route. - Defensive parsing β
caddy_list_routesnever crashes on malformed config, even if routes are null, handlers are strings, or matchers are non-arrays. Regression-tested. - No leaked credentials in errors β if
CADDY_ADMIN_URLcontains a token in the path/query, the connect-failed message shows only the origin. - Fallback error surfacing β when a TLS write PATCH fails and the POST fallback also fails, both error bodies are returned so you know what actually went wrong.
- Tool annotations β every tool declares
readOnlyHint,destructiveHint, andidempotentHint, so MCP clients can skip confirmations for safe ops. - Instant startup β ships as a single bundle with two runtime deps (the MCP SDK + Zod). No 5-minute
node_modulesinstall. - Input hardening β adapter names,
@idvalues, server names, and CA ids are all regex-validated with length caps. Blocks CRLF header injection and ReDoS.
Quick start
1. Enable the Caddy admin API
Caddy ships with the admin API enabled on localhost:2019 by default. If you're running Caddy in Docker or on a remote host, expose it via CADDY_ADMIN_URL.
2. Create .mcp.json in your project root
macOS / Linux / WSL:
{
"mcpServers": {
"caddy": {
"command": "npx",
"args": ["-y", "@yawlabs/caddy-mcp"]
}
}
}
Windows:
{
"mcpServers": {
"caddy": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@yawlabs/caddy-mcp"]
}
}
}
Why the extra step on Windows? Since Node 20,
child_process.spawncannot directly execute.cmdfiles (that's whatnpxis on Windows). Wrapping withcmd /cis the standard workaround. This file is safe to commit β it contains no secrets.
3. Restart and approve
Restart Claude Code (or your MCP client) and approve the Caddy MCP server when prompted.
That's it. Now ask your AI assistant:
"Proxy api.local to localhost:3000"
"What routes are configured on srv0?"
"Show me the Prometheus metrics"
Configuration
| Environment variable | Default | Description |
|---|---|---|
CADDY_ADMIN_URL | http://localhost:2019 | Caddy admin API URL. Set to http://caddy:2019 inside Docker, or an https URL for remote admin. |
CADDY_API_TOKEN | (none) | Optional Bearer token for authenticated admin endpoints. Only needed if you've configured Caddy with auth. |
CADDY_MAX_RETRIES | 2 | Number of retries on transient failures (5xx, network errors). 4xx and 412 never retry. Hard-capped at 5. Set to 0 to disable. |
Alternate MCP clients:
| Client | Config file |
|---|---|
| Claude Code | .mcp.json (project root) or ~/.claude.json (global) |
| Claude Desktop | ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) |
| Cursor | ~/.cursor/mcp.json |
| Windsurf | ~/.codeium/windsurf/mcp_config.json |
| VS Code | .vscode/mcp.json |
Use the same JSON block shown above in any of these.
Tools
Config management (6)
- caddy_config_get β Read config at any JSON path (or the full config).
- caddy_config_set β Write config at a path. Modes:
overwrite(PATCH, default, idempotent),append(POST),insert(PUT, for array positions). - caddy_config_delete β Delete config at a path.
- caddy_config_by_id β Get/set/delete config by
@idtag β much easier than navigating deep paths. - caddy_load β Replace the entire config atomically. 60-second timeout for cert provisioning. Auto-snapshots the prior config.
- caddy_revert β Manage config snapshots for rollback. Actions:
list,save,apply(confirm-gated). In-memory, last 10.
Route operations (4)
- caddy_reverse_proxy β Add a reverse proxy in one call:
from='api.local' to=['localhost:3000']. Pass an optionalidfor idempotent writes β repeat calls replace the route in place instead of duplicating. - caddy_add_route β Add a route with full match/handle control (any Caddy handler).
- caddy_remove_route β Remove a route by
@id(preferred) or by index. Requiresconfirm=true. - caddy_list_routes β Human-readable route summary. Defensive: never crashes on weird config.
TLS & config conversion (2)
- caddy_tls β Check or set TLS settings: ACME email, ACME CA URL. PATCH first; on a fresh install, POSTs a minimal config. On an existing config it deep-merges into the issuer path and PUTs the result back, preserving siblings (custom certs,
on_demand, additional policies). Refuses with a shape-specific error if the existing structure is unexpected β never clobbers. - caddy_adapt β Convert a Caddyfile (or nginx config) to Caddy JSON without applying it. Great for previewing.
Server operations (6)
- caddy_status β Connectivity check + config summary (server count, routes, TLS mode).
- caddy_list_servers β List all HTTP servers with names, addresses, route counts, and TLS status.
- caddy_upstreams β Reverse proxy backend health.
- caddy_metrics β Prometheus metrics (request counts, durations, connections, TLS handshakes). Optional
filter(substring match on metric name, keeps# HELP/# TYPElines for retained metrics) andmax_lines(default 500) keep responses compact on busy servers. - caddy_pki β CA info and certificate chains (default CA:
local). - caddy_stop β Graceful shutdown. Requires
confirm=trueto prevent accidents.
Resources
Browsable read-only data β MCP clients can fetch these directly without a tool call:
caddy://configβ Current full Caddy JSON configuration.caddy://serversβ Summary of all configured HTTP servers.caddy://upstreamsβ Reverse proxy upstream health status.caddy://metricsβ Prometheus metrics (text exposition format).
Examples
Add a reverse proxy
> "Proxy api.example.com to my app on port 3000"
β caddy_reverse_proxy({ from: "api.example.com", to: ["localhost:3000"] })
Idempotent reverse proxy (safe to re-run from automation)
> "Make sure api.example.com points at localhost:3000, with a stable id"
β caddy_reverse_proxy({ from: "api.example.com", to: ["localhost:3000"], id: "api-prod" })
# First call creates the route under @id="api-prod".
# Subsequent calls with the same id REPLACE in place β no duplicate routes.
# Refuses with a clear error if "api-prod" is already in use by a non-route
# config object (TLS issuer, server, etc.) β @ids are config-global in Caddy.
Filter Prometheus metrics
> "Just the HTTP request metrics, please"
β caddy_metrics({ filter: "http_requests" })
# Keeps sample lines whose metric name contains "http_requests",
# plus their `# HELP` / `# TYPE` lines. Drops the rest.
Preview a Caddyfile before applying it
> "Convert this Caddyfile to JSON so I can review it:
example.com {
reverse_proxy localhost:8080
}"
β caddy_adapt({ config: "..." })
Diagnose slow routes
> "Fetch Prometheus metrics and tell me which route is slowest"
β caddy_metrics()
Safely update a route by @id
> "Update the route with @id 'api-v2' to point to the new backend"
β caddy_config_by_id({ id: "api-v2", action: "set", value: {...} })
# Uses ETags β you'll get HTTP 412 if someone else changed it first
Atomic deploy
> "Replace the whole config with this Caddyfile"
β caddy_adapt({ config: "..." }) # validate first
β caddy_load({ config: adaptedJson }) # apply atomically
Troubleshooting
"Cannot connect to Caddy admin API"
- Make sure Caddy is running.
caddy runorsystemctl status caddy. - Check the admin endpoint. Default is
http://localhost:2019. If Caddy is in Docker, use the container hostname. - Set
CADDY_ADMIN_URLin your MCP configenvto match.
"HTTP 412 Precondition Failed"
- Someone (or something) changed the config between your read and your write.
- The cached ETag has been invalidated. Re-read the config and retry.
"HTTP 403" on /load or /config writes
- You have
admin.listenoradmin.originsrestrictions set in your Caddy config, or you're missing anAuthorizationheader. - Set
CADDY_API_TOKENin your MCP config env if Caddy expects a Bearer token.
Windows: MCP server doesn't start
- Use the
cmd /c npx ...pattern from the Quick start section. Node 20+ can't spawn.cmdfiles directly.
Requirements
- Node.js 20+
- Caddy 2.x with admin API enabled (default:
localhost:2019)
Contributing
git clone https://github.com/YawLabs/caddy-mcp.git
cd caddy-mcp
npm install
npm run lint # Biome check
npm run lint:fix # Auto-fix
npm run build # tsup bundle
npm test # Vitest (150 unit tests; +8 live-Caddy integration tests gated by CADDY_MCP_INTEGRATION=1)
npm run typecheck # tsc --noEmit
See CONTRIBUTING.md for the full workflow, including release process.
License
MIT
