Usage — API / Agent / MCP¶
caddy-mcp exposes the same capability three ways: as MCP tools an agent calls,
as a Python API (Api) you import, and as a Pydantic-AI agent. The complete
tool surface is summarized in Overview.
As an MCP server¶
Once deployed, the server registers action-dispatch tools grouped by Caddy Admin API capability:
| Tool | Tag | Actions |
|---|---|---|
caddy_mcp_config |
config |
get_config, post_config, set_config, put_config, patch_config, delete_config, load_config, stop_server, get_id, post_id, put_id, patch_id, delete_id, adapt_config, get_routes |
caddy_mcp_pki |
pki |
get_pki_ca, get_pki_ca_certificates |
caddy_mcp_reverse_proxy |
reverse_proxy |
get_reverse_proxy_upstreams |
Each tool takes an action and a params_json string matching the underlying method
signature. Example agent prompts that map onto these tools:
- "Export Caddy's current configuration" →
caddy_mcp_configwithget_config - "Show the reverse-proxy upstream health" →
caddy_mcp_reverse_proxywithget_reverse_proxy_upstreams - "Return the local PKI CA certificate chain" →
caddy_mcp_pkiwithget_pki_ca_certificates
As a Python API¶
Api (caddy_mcp.api_client) is a requests-based facade over the Caddy Admin API.
Build one directly, or from the environment with get_client().
from caddy_mcp.api_client import Api
api = Api(
base_url="http://localhost:2019",
token="", # optional bearer token
verify=True,
)
# Reads
config = api.get_config() # full live configuration
routes = api.get_routes() # http servers / routes
upstreams = api.get_reverse_proxy_upstreams() # upstream health
ca = api.get_pki_ca("local") # PKI app CA info
Build a client straight from the environment:
from caddy_mcp.auth import get_client
api = get_client() # reads CADDY_URL / CADDY_TOKEN from the environment / .env
Writes¶
Mutating calls drive the live Caddy configuration. The facade supports the full Admin
API surface — load, set, patch, and delete by config path or @id tag:
# Load a complete configuration (JSON or a Caddyfile)
api.load_config(caddyfile_text, config_adapter="caddyfile")
# Set or replace an object at a named config path
api.set_config("apps/http/servers/srv0/routes", route_definition)
# Patch / delete by @id tag
api.patch_id("my_proxy/upstreams", upstreams)
api.delete_config("apps/http/servers/srv0/routes/0")
# Adapt a Caddyfile to Caddy JSON without loading it
api.adapt_config(caddyfile_text, config_adapter="caddyfile")
As an agent¶
The caddy-agent console script starts a Pydantic-AI A2A agent that consumes the MCP
tools and exposes a conversational interface. Point it at a running MCP server:
Provide a model provider and identity with --provider / --model-id (or the
corresponding environment variables). See Deployment for
the Compose service and MCP_URL wiring.