HTTP and Docker deployment
How to run OpenZIM MCP as a long-running networked service. Covers the streamable HTTP transport, the published Docker image, operational concerns (TLS, reverse proxy, health probes, systemd), and end-to-end deployment recipes for LAN, Tailscale tailnet, and public VPS topologies.
Notation: examples on this page use JSON-RPC tool-call framing (
{"name": "...", "arguments": {...}}) for protocol-level snippets and shell snippets for environment / HTTP commands. Tool surfaces referenced match the 8-tool advanced surface.
Source of truth: openzim_mcp/http_app.py and the Dockerfile.
If you only want to use OpenZIM MCP locally with Claude Desktop, Cursor, or another MCP client launching it as a subprocess, stay on the Quick start — that path uses stdio transport and doesn’t need any of this.
When to use HTTP vs stdio#
| Transport | Use case |
|---|---|
stdio (default) | Local desktop MCP hosts (Claude Desktop, Inspector, MCP-aware editors). The host owns the process lifetime. |
http (streamable HTTP) | Long-running service. Multiple clients, possibly across the network. Bearer-token auth, CORS, health probes. |
sse (legacy, deprecated) | Older clients that haven’t migrated to streamable HTTP. Loopback only — no auth middleware, and no malformed-frame classification: an unusable JSON-RPC request id is accepted with 202 and then dropped, so the client waits forever (stdio and http both reject it with -32600). Deprecated and removed in 4.0.0 — the server logs a deprecation warning on every SSE start; migrate to http. |
The rest of this page assumes --transport http.
Quick start (no Docker)#
export OPENZIM_MCP_AUTH_TOKEN="$(openssl rand -hex 32)"
openzim-mcp --transport http --host 127.0.0.1 --port 8000 /srv/zim
This binds the loopback interface only. Put a TLS-terminating reverse proxy in front for external access. The server refuses to bind a non-loopback host without an auth token as a safe default.
Quick start (Docker)#
The image defaults to stdio transport (so docker run -i is a local MCP server — see Installation). Opt into the HTTP service explicitly:
docker run --rm -p 8000:8000 \
-v /srv/zim:/data:ro \
-e OPENZIM_MCP_TRANSPORT=http \
-e OPENZIM_MCP_HOST=0.0.0.0 \
-e OPENZIM_MCP_AUTH_TOKEN="$(openssl rand -hex 32)" \
ghcr.io/cameronrye/openzim-mcp
The published image:
- Multi-arch:
linux/amd64,linux/arm64 - Non-root: runs as
appuser(uid 10001, gid 10001) - Default transport:
stdio— setOPENZIM_MCP_TRANSPORT=httpandOPENZIM_MCP_HOST=0.0.0.0(as above) to run the HTTP service - No baked-in healthcheck (the image ships no
curl); define one in your orchestrator/compose probingGET /readyz— see the compose example below - Entrypoint:
python -m openzim_mcp /data(mount your ZIM directory at/data)
Binding a non-loopback host (0.0.0.0) requires OPENZIM_MCP_AUTH_TOKEN as a safe default; the bind is refused without it.
For an end-to-end deployment rather than a one-off docker run — Compose files, TLS, client wiring — see Deployment patterns at the foot of this page.
Tool surface. The image sets
OPENZIM_MCP_TOOL_MODE=advanced, so it registers all 8 tools. That matches the.mcpbbundle and the MCP Registry entry, and it is what directory listings show. The code default elsewhere (a bareuvx openzim-mcp) is stillsimple, the singlezim_queryentry point. Add-e OPENZIM_MCP_TOOL_MODE=simpleto get that narrower surface in a container.
Upgrading an existing HTTP deployment? Earlier images defaulted the container to HTTP, so a token-only
docker run -p 8000:8000 -e OPENZIM_MCP_AUTH_TOKEN=… <image>was enough. The image now defaults to stdio, so that same command starts a stdio server instead — nothing listens on:8000. Add-e OPENZIM_MCP_TRANSPORT=http -e OPENZIM_MCP_HOST=0.0.0.0(as shown above) when you pull the new image.
Authentication#
Bearer-token auth via BearerTokenAuthMiddleware:
- Set
OPENZIM_MCP_AUTH_TOKEN(env only — never put it in a config file). - Stored as a pydantic
SecretStr— value never appears inrepr(), logs, or the configuration view ofzim_health. - Comparison is timing-safe (
hmac.compare_digest). - The attempted token is never logged.
/healthzand/readyzare exempt.OPTIONS /mcpis not exempt from auth — there is no blanket OPTIONS bypass, so a bareOPTIONS(no preflight headers) gets the same401as any other tokenless request and non-browser callers cannot probe the endpoint without a token. The one carve-out is by design: whenOPENZIM_MCP_CORS_ORIGINSis set, a CORS preflight — anOPTIONScarryingOriginandAccess-Control-Request-Methodfrom a listed origin — is answered200by the outermost CORS layer before auth runs, so it is served without a token. Browsers never attachAuthorizationto a preflight; the real request that follows is still authenticated.
Client request format:
POST /mcp HTTP/1.1
Host: openzim-mcp.example
Authorization: Bearer <YOUR_TOKEN>
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
2026-07-28 requests are stateless: there is no initialize handshake, no Mcp-Session-Id (the server issues none), and Mcp-Method must name the same method as the body — tools/call additionally needs Mcp-Name matching the tool name. A client that sends no MCP-Protocol-Version, or one naming a 2025 revision, gets the handshake-era path instead: initialize first, then a server-issued Mcp-Session-Id echoed on every later request. With OPENZIM_MCP_STATELESS_HTTP=1 that path issues no session id either — initialize is still answered, every later POST is answered on its own, and a GET for a stream gets 405 (see Scaling considerations).
On a server with sessions (the default), a handshake-era session ends when its client sends DELETE, or after 30 minutes with no request in flight. An open GET stream counts as a request in flight, so a client that never sends DELETE but keeps its stream open holds its session for as long as that connection lasts. Each process holds at most 10,000 sessions; while that many are open, an initialize that would open another is answered 503. Both limits are the MCP SDK’s defaults. Until the server required mcp 2.3, it ran on an SDK that freed no session before restart, DELETE included (GHSA-84m7-p3x7-pcfv).
Failures return 401 {"error":"unauthorized"} with WWW-Authenticate: Bearer.
Rotate by setting a new value and restarting the container; there is no in-flight rotation.
CORS#
For browser clients, set OPENZIM_MCP_CORS_ORIGINS to an explicit JSON list:
export OPENZIM_MCP_CORS_ORIGINS='["https://app.example.com","https://other.example.com"]'
- Wildcard
"*"is rejected at startup — including whitespace-padded variants like" * ". There is no opt-out. Wildcard CORS combined with bearer-token auth is the canonical recipe for token theft via a malicious site. - The allowed headers cover both protocol eras the endpoint serves.
Mcp-Session-IdandLast-Event-IDare there for browser clients still on theinitializehandshake, which hold a session unless the server runs withOPENZIM_MCP_STATELESS_HTTP=1;Mcp-MethodandMcp-Nameare the headers a 2026-07-28 client must send on every POST.Mcp-Session-Idis also inexpose_headersso a handshake-era browser client can read the id the server issued.Last-Event-IDis accepted so a browser client sending it is not blocked by CORS, but this server keeps no event store and never emits SSEid:fields, so nothing is resumable: the header is stripped and the request opens a fresh stream (on a server runningOPENZIM_MCP_STATELESS_HTTP=1, that GET is answered405instead). - CORS is the outer middleware layer (LIFO add order) so a 401 from auth still carries
Access-Control-Allow-Originheaders — browsers see “401 unauthorized” instead of an opaque CORS error. - Allowed methods:
GET,POST,OPTIONS,DELETE(DELETEis the handshake-era session-termination method; a 2026-07-28 client only POSTs). A server runningOPENZIM_MCP_STATELESS_HTTP=1keeps this list, and the CORS layer still answers preflights with it, but theGETorDELETEa preflight approves is then answered405withAllow: POST— carrying the CORS headers, so a browser client can read it.
If no browser client connects (you’re hitting the endpoint from another server, a CLI client, or a desktop MCP client), leave this unset.
Public hostname allow-list#
Required when openzim-mcp sits behind a reverse proxy (Caddy, nginx) or Tailscale serve and the public hostname differs from the bind interface. The MCP SDK applies DNS rebinding protection by validating the Host header against an allow-list — loopback values (127.0.0.1, localhost, [::1]) are always permitted, but anything else needs to be listed explicitly:
Hostvalidation is off on a bind-all host with no allow-list. IfOPENZIM_MCP_HOSTis0.0.0.0,::or[::]andOPENZIM_MCP_ALLOWED_HOSTSis empty, the server disables DNS-rebindingHostvalidation entirely and logs a warning saying so — because the client-facingHostvaries by reachable IP, so any allow-list would reject every request with 421. TheOrigincheck is not part of that switch: a browser request whoseOriginis outsideOPENZIM_MCP_CORS_ORIGINSstill gets 403, which is what a DNS-rebinding page sends. Beyond that, the bearer token is the access control. SettingOPENZIM_MCP_ALLOWED_HOSTSre-enablesHostvalidation. A bind to a specific non-loopback interface keeps validation on and auto-allows that address.
export OPENZIM_MCP_ALLOWED_HOSTS='["mcp.example.com"]'
Symptom of a missing entry: requests proxied to openzim-mcp return 421 Misdirected Request with body Invalid Host header, and the server log shows Invalid Host header: <hostname>.
Entries can include the :* wildcard-port suffix (mcp.example.com:*) when the proxy preserves a non-default port in the Host header. The wildcard * alone is rejected at startup — the whole point of the allow-list is DNS rebinding protection.
Safe-default startup matrix#
check_safe_startup() refuses to start in two cases:
| Transport | Host | Token | Result |
|---|---|---|---|
http | loopback (127.0.0.1/::1/resolved localhost) | unset | OK |
http | loopback | set | OK |
http | non-loopback | unset | REFUSE — unless OPENZIM_MCP_INSECURE_DISABLE_AUTH=1, which starts anyway with an INSECURE: warning |
http | non-loopback | set | OK |
sse | loopback | (any) | OK |
sse | non-loopback | (any) | REFUSE (no auth middleware in SSE path; INSECURE_DISABLE_AUTH does not apply) |
If host=localhost and /etc/hosts maps localhost away from 127.0.0.1, the server emits a UserWarning and treats the host as public — which then triggers the safe-default refusal.
Health endpoints#
| Endpoint | Purpose | Auth | Response |
|---|---|---|---|
/healthz | Liveness — process is up, event loop responsive | exempt | 200 {"status":"ok"} |
/readyz | Readiness — at least one allowed dir is readable | exempt | 200 {"status":"ready"} or 503 {"status":"not_ready","reason":"no readable allowed directories"} |
Both endpoints are CORS-friendly and safe to wire into Kubernetes probes, Docker and Compose healthchecks, or external uptime monitors. systemd’s WatchdogSec= is not one of them: it waits for sd_notify keep-alives, which the server never sends, so systemd would kill a healthy service at every timeout.
curl -fsS http://localhost:8000/healthz
# {"status":"ok"}
curl -fsS http://localhost:8000/readyz
# {"status":"ready"}
Resource subscriptions over HTTP#
The polling watcher (MtimeWatcher) is started via a wrapped lifespan handler so it works under streamable HTTP (the SDK’s streamable_http_app() supplies its own lifespan; add_event_handler('startup', …) is silently a no-op).
- Clients opt in with one long-lived
subscriptions/listenrequest. A.zimappearing or disappearing publishesnotifications/resources/list_changed; one replaced in place publishesnotifications/resources/updatedforzim://{name}. OPENZIM_MCP_SUBSCRIPTIONS_ENABLED=falseskips the watcher entirely and withholds the capability:resources.subscribeand thelistChangedflags readfalse, andsubscriptions/listenfails with method-not-found rather than acknowledging a stream nothing would ever publish to.OPENZIM_MCP_WATCH_INTERVAL_SECONDS(default 5, range 1–60) controls poll cadence.- Delivery is the SDK’s: each listen stream is buffered independently, concurrent streams and per-stream backlog are both capped, and a stream whose client stops reading is ended. The server adds its own admission bound before a stream is acknowledged — at most 256 subscription URIs per stream, each at most 2048 characters, rejected with
INVALID_PARAMS. There is no replay — a client that loses its stream re-listens and re-reads.
See Resources, prompts and subscriptions for client-side examples.
Reverse proxy / TLS#
There is no built-in TLS. Terminate at a reverse proxy.
Caddy#
openzim-mcp.example.com {
reverse_proxy 127.0.0.1:8000
}
Caddy auto-provisions Let’s Encrypt certs and forwards Authorization, Mcp-Session-Id, and Content-Type by default.
nginx#
server {
listen 443 ssl http2;
server_name openzim-mcp.example.com;
ssl_certificate /etc/letsencrypt/live/openzim-mcp.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/openzim-mcp.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Authorization $http_authorization;
proxy_pass_header Mcp-Session-Id;
proxy_buffering off; # Streamable HTTP is long-poll friendly
proxy_read_timeout 300s;
}
}
nginx will not auto-provision certs, so pair it with Certbot or a similar tool.
Proxying to more than one replica? A handshake-era client’s session lives on the replica that issued it, and its GET stream is held open through nginx for the session’s lifetime. OPENZIM_MCP_STATELESS_HTTP=1 on every replica removes both — see Scaling considerations, including how to switch a running fleet.
Traefik#
http:
routers:
openzim-mcp:
rule: "Host(`openzim-mcp.example.com`)"
entryPoints: [websecure]
tls:
certResolver: letsencrypt
service: openzim-mcp
services:
openzim-mcp:
loadBalancer:
servers:
- url: "http://127.0.0.1:8000"
systemd unit#
[Unit]
Description=OpenZIM MCP
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=openzim-mcp
Group=openzim-mcp
Environment=OPENZIM_MCP_TRANSPORT=http
Environment=OPENZIM_MCP_HOST=127.0.0.1
Environment=OPENZIM_MCP_PORT=8000
Environment=OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED=true
Environment=OPENZIM_MCP_CACHE__PERSISTENCE_PATH=/var/cache/openzim-mcp/cache.json
# Holds OPENZIM_MCP_AUTH_TOKEN, etc.
EnvironmentFile=/etc/openzim-mcp/secrets.env
ExecStart=/usr/local/bin/openzim-mcp /srv/zim
Restart=on-failure
RestartSec=5
# Hardening
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
ReadOnlyPaths=/srv/zim
CacheDirectory=openzim-mcp
ReadWritePaths=/var/cache/openzim-mcp
[Install]
WantedBy=multi-user.target
Kubernetes example#
apiVersion: apps/v1
kind: Deployment
metadata:
name: openzim-mcp
spec:
replicas: 2
selector:
matchLabels: { app: openzim-mcp }
template:
metadata:
labels: { app: openzim-mcp }
spec:
containers:
- name: openzim-mcp
image: ghcr.io/cameronrye/openzim-mcp:3.5.2 # x-release-please-version
ports:
- containerPort: 8000
env:
- name: OPENZIM_MCP_TRANSPORT
value: "http" # the image defaults to stdio
- name: OPENZIM_MCP_HOST
value: "0.0.0.0"
- name: OPENZIM_MCP_AUTH_TOKEN
valueFrom:
secretKeyRef:
name: openzim-mcp-auth
key: token
- name: OPENZIM_MCP_CACHE__MAX_SIZE
value: "500"
- name: OPENZIM_MCP_STATELESS_HTTP
value: "true" # two replicas, no session affinity — see Scaling considerations
volumeMounts:
- name: zim-data
mountPath: /data
readOnly: true
livenessProbe:
httpGet: { path: /healthz, port: 8000 }
periodSeconds: 30
readinessProbe:
httpGet: { path: /readyz, port: 8000 }
periodSeconds: 10
resources:
requests: { memory: "256Mi", cpu: "100m" }
limits: { memory: "1Gi", cpu: "1000m" }
volumes:
- name: zim-data
persistentVolumeClaim:
claimName: zim-archives
The Deployment sets OPENZIM_MCP_STATELESS_HTTP because it runs two replicas behind a plain Service with no session affinity, where a handshake-era client’s follow-ups would otherwise reach a replica that never issued its session. Changing that value on a running Deployment is a mode switch: see Scaling considerations before you roll it. Releases older than the setting ignore the variable without an error and run with sessions; a replica logging at INFO (the default) that prints no Serving handshake-era clients line at startup is one of them.
Each replica has its own in-memory cache. Persistent cache on shared storage is not recommended unless you handle concurrent-writer issues at the storage layer (the on-disk cache uses simple file rewrites).
Clients reaching the pods through a Service/Ingress hostname should have that hostname in OPENZIM_MCP_ALLOWED_HOSTS. Note what the Deployment above does without it: because it binds 0.0.0.0 with an empty allow-list, Host validation is switched off (the Origin check stays on) — add the hostname to turn Host validation back on.
Scaling considerations#
Horizontal scaling works — add replicas and front them with any L7 load balancer that supports HTTP/1.1 keep-alive and forwards Authorization unchanged. A 2026-07-28 client is stateless, so any replica can answer any request; a long-lived subscriptions/listen stream is naturally pinned to the replica holding it, and each replica runs its own watcher over the same directories, so it publishes to its own listeners.
By default, handshake-era clients need session-stickiness: their session state lives in the process that issued it, and a replica that doesn’t recognize the presented Mcp-Session-Id returns 404 Session not found. If any of your clients still use initialize, either run one replica, set OPENZIM_MCP_STATELESS_HTTP=1 on every replica, or forward Mcp-Session-Id unchanged and use affinity that holds a client to one replica from its initialize on: by client IP, by a cookie the balancer sets, or by learning the Mcp-Session-Id from the response that issues it. A plain hash on the request header cannot place the initialize itself, which carries none.
Serving handshake-era clients without sessions#
OPENZIM_MCP_STATELESS_HTTP=1 takes the session off the handshake-era path. What that was measured to buy: every request is answered on its own and leaves nothing behind — a burst of thousands leaves no session and no extra task on the replica — so any replica can answer any request with no affinity at all. With sessions, by contrast, each one a client opens lives in its replica’s memory until the client ends it or it sits idle for 30 minutes, so a client that abandons its sessions rather than ending them leaves each one behind for that long. Nor does a handshake-era client hold a stream open through your proxies: GET /mcp (the session’s server-to-client stream), DELETE /mcp and every other method but POST are answered 405 with Allow: POST — for the GET, the spec’s way of saying the endpoint offers no stream. (With CORS origins set, a browser’s preflight is still answered by the CORS layer; see CORS.) initialize is still answered; it just issues no session id. 2026-07-28 clients, subscriptions/listen included, are unaffected.
The one thing given up is out-of-band cancellation: a handshake-era notifications/cancelled arrives on its own POST and cannot reach a call running on another, so it is ignored, and a client cancels a call by closing that call’s connection instead. Nothing else rides on the session here — the server sends handshake-era clients no requests and no connection-scoped notifications, and offers them no subscriptions in either mode.
Telling the modes apart. Each replica logs its mode once at startup, at INFO, as Serving handshake-era clients statelessly or Serving handshake-era clients with sessions. From outside, a sessionless GET /mcp answers without opening anything — 405 from a stateless replica, 400 (Missing session ID) from one with sessions — so ask each replica directly rather than through the balancer:
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TOKEN" http://<replica>:8000/mcp
With OPENZIM_MCP_ALLOWED_HOSTS set, as recommended above, a request addressed to a replica’s IP fails the Host check first and gets 421 in either mode: a 421 says the Host was refused, nothing about the mode. Add -H "Host: <a name listed in OPENZIM_MCP_ALLOWED_HOSTS>" to the command, or run it through kubectl port-forward against 127.0.0.1, whose loopback Host is always accepted.
Switching a running fleet. Set it on every replica or none: replicas that disagree break handshake-era clients mid-sequence. A client that initialized on a stateless replica holds no session id, so when a later request lands on a replica with sessions it is answered 400 Missing session ID — and session-id affinity cannot steer it back, because there is no id to steer by. (The other direction fails more quietly: a stateless replica serves the POSTs of a client holding another replica’s session id, but answers its DELETE with 405, so that session lingers on the replica that issued it until it has sat idle for 30 minutes.) A switch in either direction therefore has to avoid a mixed window, and that includes the first rollout of a release with the setting turned on, since earlier releases always run with sessions:
- Recreate. Stop every replica, then start them all with the new value. On Kubernetes, use
strategy: { type: Recreate }on the Deployment for that rollout: a short outage instead of a mixed window. - Or hold each client to one replica while the fleet is mixed. Pin clients by something other than the session id until every replica runs the same value, then lift the pin if nothing else needs it.
sessionAffinity: ClientIPon the Service pins only clients that reach the Service directly: an Ingress controller usually routes to the pods itself, bypassing the Service’s affinity, so behind one use the controller’s own affinity (a cookie, with ingress-nginx), or Recreate. Cookie affinity holds only clients that send the cookie back, and the TypeScript SDK client running on Node’s built-infetchkeeps no cookies: if such clients connect, use Recreate.
Going back to sessions cannot be made seamless, whichever way you roll it. Every handshake-era client that initialized while the fleet was stateless holds no session id, so once its requests reach a replica with sessions they are answered 400 Missing session ID — not the 404 Session not found that tells a client to initialize again — and it stays broken until it reconnects on its own (for Open WebUI, a new chat). Use Recreate or pinning all the same, so that a mixed window adds no failures of its own, and roll back when few clients are active.
State that stays per replica, in either mode. Rate limits are enforced by each process with its own token buckets, keyed by the bearer token’s hash — one bucket shared by every authenticated client, since only one token is accepted — or else by the client address as the replica sees it (see how the limiter identifies a client). So N replicas admit up to N times OPENZIM_MCP_RATE_LIMIT__REQUESTS_PER_SECOND and OPENZIM_MCP_RATE_LIMIT__BURST_SIZE between them: divide both by the replica count to hold a fleet-wide budget. Pagination cursors are self-contained, so any replica can serve the next page, but only if every replica mounts the archives at the same absolute path: a cursor carries a hash of its archive’s path, and a replica that sees the archive somewhere else rejects it.
Hardening checklist#
- Bind to a specific interface, not
0.0.0.0, unless behind a reverse proxy that already restricts ingress. - Set
OPENZIM_MCP_AUTH_TOKENto a high-entropy value (openssl rand -hex 32). - Set
OPENZIM_MCP_CORS_ORIGINSto the explicit list of allowed origins (never*). - Terminate TLS at a reverse proxy.
- Run as a non-root user (Docker image already does this).
- Mount ZIM directories read-only.
- Tune
OPENZIM_MCP_RATE_LIMIT__REQUESTS_PER_SECONDfor your client load. - Wire
/healthzand/readyzinto your platform’s health-check tooling. - Subscribe alerting to repo Security Advisories.
For a full security review of the model behind these recommendations, see Security best practices.
Troubleshooting#
Common failure modes:
- Container exits immediately on start. Almost always one of three startup checks: HTTP transport bound to a non-loopback host without
OPENZIM_MCP_AUTH_TOKEN, orOPENZIM_MCP_CORS_ORIGINS/OPENZIM_MCP_ALLOWED_HOSTScontaining an entry that is exactly*(a:*port suffix such asmcp.example.com:*is fine — only the bare wildcard is rejected). The startup error message identifies which. - Clients get 421 Misdirected Request /
Invalid Host header. The proxiedHostheader (e.g.zim.example.com) isn’t inOPENZIM_MCP_ALLOWED_HOSTS. Add it. Loopback (127.0.0.1,localhost,[::1]) is always allowed without configuration; everything else needs an explicit entry. - Clients get 401 Unauthorized. Token mismatch. Verify with
curl -i -H "Authorization: Bearer $TOKEN" http://host:8000/mcp: a wrong token gets401and{"error":"unauthorized"}; any other status means the token was accepted (a bare GET is answered400, or405withOPENZIM_MCP_STATELESS_HTTPset). Don’t paste the token into chat or tickets. - Browser clients get 403 / CORS errors. Either
OPENZIM_MCP_CORS_ORIGINSis unset (and a browser is calling) or the client’s origin isn’t in the allow-list. The browser console shows the offending origin; add it. /readyzreturns 503. None of the configured ZIM directories are readable from inside the container. (With multiple allowed directories, one bad mount is fine — readiness flips only when all of them fail.) Check the volume mount path (host side and/dataside). An empty but readable directory still reports ready —/readyztests readability, not content — so checkzim_healthfor the archives actually loaded. Permissions: the in-container user is UID 10001; the host directory needs to be world-readable or owned by UID 10001.- Subscriptions stop firing. Confirm
OPENZIM_MCP_SUBSCRIPTIONS_ENABLEDisn’t set tofalse— a disabled server refusessubscriptions/listenwith method-not-found, so that misconfiguration is loud. If the listen was acknowledged but nothing arrives, check the acknowledgement’s echoed filter: a client that asked forzim://filesunderresourceSubscriptionsgets an ack and silence, because directory-membership changes are published asnotifications/resources/list_changed(opt in withresourcesListChanged).
Deployment patterns#
The reference above is the surface area. The recipes below are end-to-end deployments for the three topologies most operators land on: LAN host, Tailscale tailnet, and public VPS with TLS.
Recipe 1: Docker Compose on a LAN host#
This recipe puts OpenZIM MCP on a single host over plain HTTP plus a bearer token. As written it publishes the port on loopback only, so start there and check it works; Opening it to the LAN below is a two-line change. There’s no TLS — the bearer token is the only thing protecting the endpoint, so this recipe is appropriate for trusted networks (a home LAN, a Tailscale tailnet) and not for anything reachable from the public internet.
Prerequisites#
- Docker and Docker Compose v2 installed on the host
- A directory of
.zimfiles (download from the Kiwix Library) - A generated bearer token:
openssl rand -hex 32
docker-compose.yml#
services:
openzim-mcp:
image: ghcr.io/cameronrye/openzim-mcp:3.5.2 # x-release-please-version
restart: unless-stopped
ports:
- "127.0.0.1:8000:8000"
volumes:
- /srv/zim:/data:ro
- openzim-cache:/home/appuser/.cache/openzim-mcp
environment:
OPENZIM_MCP_TRANSPORT: "http"
OPENZIM_MCP_HOST: "0.0.0.0"
OPENZIM_MCP_AUTH_TOKEN: "${OPENZIM_MCP_AUTH_TOKEN}"
OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED: "true"
# Explicit path so the cache file lands inside the mounted volume
# (the default path gets a config-fingerprint suffix *next to* it).
OPENZIM_MCP_CACHE__PERSISTENCE_PATH: "/home/appuser/.cache/openzim-mcp/cache.json"
healthcheck:
# The image ships no curl; probe /readyz with the bundled Python.
test:
- "CMD"
- "python"
- "-c"
- "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/readyz').getcode()==200 else 1)"
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
volumes:
openzim-cache:
Still running v1.x? The
ghcr.io/cameronrye/openzim-mcp:1.3.0image (the final v1.x release) stays available, but the v1.x maintenance window closed when v2.5.0 shipped (2026-06-18) — it receives no further fixes. The v2.0.0 advanced tool surface is a breaking rename per CHANGELOG — migrate when convenient.
What’s intentional here:
- Pinned tag (
:3.5.2, not:latest). Upgrades are deliberate —docker compose pullis a thing you do, not a thing that happens to you. - Host port bound to
127.0.0.1. The container listens on all interfaces (OPENZIM_MCP_HOST=0.0.0.0, set in the environment block), but Docker’s port publish restricts external exposure to loopback, so only the host itself can connect. Opening it to the LAN and the Tailscale variant lift this restriction by publishing on a specific interface. - Read-only ZIM mount (
:ro). The server only reads ZIM files; mounting read-only ensures a server compromise can’t damage them. - Token via env, not hard-coded. Put it in a
.envfile next to the compose file (and add.envto.gitignore). The image defaults tostdio, soTRANSPORT=httpandHOST=0.0.0.0are set explicitly in the environment block to select the HTTP service. - Explicit healthcheck block. The image ships no
HEALTHCHECK(it defaults to stdio, where there is no HTTP endpoint to probe), so this block defines one — using the bundled Python rather thancurl, which isn’t installed.
/srv/zim is an example. Adjust to wherever your ZIM files live.
Start it#
echo "OPENZIM_MCP_AUTH_TOKEN=$(openssl rand -hex 32)" > .env
docker compose up -d
Verify#
# Liveness
curl -sf http://127.0.0.1:8000/healthz && echo " healthz ok"
# Readiness (fails if /srv/zim is unreadable; an empty directory still reports ready)
curl -sf http://127.0.0.1:8000/readyz && echo " readyz ok"
# Authed RPC call: list available tools (stateless 2026-07-28 framing —
# a bare POST with no MCP-Protocol-Version header is routed down the
# legacy handshake path and, unless OPENZIM_MCP_STATELESS_HTTP is set,
# rejected with "Missing session ID", which `curl -sf` swallows silently)
TOKEN=$(grep OPENZIM_MCP_AUTH_TOKEN .env | cut -d= -f2)
curl -sf -X POST http://127.0.0.1:8000/mcp \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "MCP-Protocol-Version: 2026-07-28" \
-H "Mcp-Method: tools/list" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
| head -c 500
If tools/list returns a JSON envelope with a result.tools array, you’re up.
Connect a client#
Add OpenZIM MCP to your client’s MCP config. Substitute the host, port, and token. Cursor supports remote HTTP MCP servers natively; Claude Desktop currently does not — it needs the mcp-remote bridge, which translates Claude Desktop’s stdio expectations into HTTP calls.
Cursor (~/.cursor/mcp.json for global, or .cursor/mcp.json for project-local):
{
"mcpServers": {
"openzim-mcp": {
"url": "http://127.0.0.1:8000/mcp",
"headers": {
"Authorization": "Bearer YOUR_TOKEN_HERE"
}
}
}
}
Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows). Requires Node.js on the client host (mcp-remote runs via npx):
{
"mcpServers": {
"openzim-mcp": {
"command": "npx",
"args": [
"-y",
"mcp-remote@^0.1.16",
"http://127.0.0.1:8000/mcp",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Bearer YOUR_TOKEN_HERE"
}
}
}
}
The header value comes from env because Claude Desktop on Windows does not escape spaces inside args when it launches npx, so Bearer YOUR_TOKEN_HERE written there arrives split in two. mcp-remote expands ${AUTH_HEADER} itself, and the form with no spaces around the colon is its documented workaround; it works on every platform. The token still lives in the config file — treat the file as a secret: don’t commit claude_desktop_config.json to a shared repo and keep its filesystem permissions tight (chmod 600 on Unix).
Opening it to the LAN#
To reach the server from other machines on your network, publish the port on the host’s LAN address and name that address in OPENZIM_MCP_ALLOWED_HOSTS:
ports:
- "192.168.1.10:8000:8000" # the host's LAN address
environment:
OPENZIM_MCP_AUTH_TOKEN: "${OPENZIM_MCP_AUTH_TOKEN}"
OPENZIM_MCP_ALLOWED_HOSTS: '["192.168.1.10"]'
Clients then connect to http://192.168.1.10:8000/mcp. The allow-list is what keeps Host validation on: the container binds 0.0.0.0, and on a bind-all host with an empty list the server turns Host validation off and logs a warning saying so (the Origin check stays on either way). With the list set, it accepts loopback and the listed hosts and answers any other Host with 421, so list every name or address your clients use.
Tailscale variant#
To reach the server from your tailnet instead of the LAN, change two lines in docker-compose.yml:
ports:
- "100.x.y.z:8000:8000" # your Tailscale IPv4, from `tailscale ip -4`
environment:
OPENZIM_MCP_AUTH_TOKEN: "${OPENZIM_MCP_AUTH_TOKEN}"
OPENZIM_MCP_ALLOWED_HOSTS: '["<device>.<tailnet>.ts.net"]'
Then make sure the host firewall blocks port 8000 on the public interface (it should already, since you’re not publishing on 0.0.0.0). The bearer token plus tailnet ACLs are your trust boundary; you don’t need TLS because the tailnet itself is encrypted.
OPENZIM_MCP_ALLOWED_HOSTS turns Host validation back on. The container binds 0.0.0.0, and on a bind-all host with an empty list the server disables Host validation (with a startup warning; the Origin check stays on) rather than answer direct-IP clients with 421. Once the list is set, only loopback and the listed hosts are accepted, so list the MagicDNS hostname your clients connect to, and add 100.x.y.z as well if any client uses the raw Tailscale IP.
Recipe 2: VPS with Caddy and automatic TLS#
This recipe puts OpenZIM MCP on a public VPS, fronted by Caddy for automatic Let’s Encrypt TLS. The bearer token is still the auth boundary; TLS prevents a network observer from stealing it in transit.
Prerequisites#
- A VPS with a public IPv4 (and optionally IPv6)
- A domain name with an A record (and optional AAAA) pointing at the VPS
- Ports 80 and 443 open on the VPS firewall (Caddy needs both for the HTTP-01 ACME challenge and TLS service)
- Same bearer token and ZIM directory as Recipe 1
docker-compose.yml#
This is the LAN compose file with three changes: a caddy service is added, the openzim-mcp service no longer publishes a host port (it’s reachable only on the internal Docker network), and OPENZIM_MCP_ALLOWED_HOSTS admits the public hostname Caddy forwards.
services:
openzim-mcp:
image: ghcr.io/cameronrye/openzim-mcp:3.5.2 # x-release-please-version
restart: unless-stopped
expose:
- "8000"
volumes:
- /srv/zim:/data:ro
environment:
OPENZIM_MCP_TRANSPORT: "http"
OPENZIM_MCP_HOST: "0.0.0.0"
OPENZIM_MCP_AUTH_TOKEN: "${OPENZIM_MCP_AUTH_TOKEN}"
OPENZIM_MCP_ALLOWED_HOSTS: '["zim.example.com"]'
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp" # HTTP/3
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- openzim-mcp
volumes:
caddy_data:
caddy_config:
Caddyfile#
zim.example.com {
reverse_proxy openzim-mcp:8000
}
That’s it. Caddy provisions a certificate on first request (and renews automatically), terminates TLS, and forwards the Authorization header to OpenZIM MCP unchanged. Replace zim.example.com with your hostname.
nginx alternative: if you already run nginx and prefer it to Caddy, the only requirements are reverse-proxying
/toopenzim-mcp:8000and forwarding theAuthorizationheader unchanged. See the nginx snippet above; pair it with Certbot or a similar tool for certificate provisioning.
Start it#
echo "OPENZIM_MCP_AUTH_TOKEN=$(openssl rand -hex 32)" > .env
docker compose up -d
# Watch Caddy obtain its certificate (first start only)
docker compose logs -f caddy
The first request triggers ACME issuance; subsequent restarts reuse the cached cert from the caddy_data volume.
Verify#
# TLS chain
curl -vsf https://zim.example.com/healthz 2>&1 | grep -E "subject|issuer|HTTP/"
# Authed RPC call (stateless 2026-07-28 framing; see Recipe 1's Verify note)
TOKEN=$(grep OPENZIM_MCP_AUTH_TOKEN .env | cut -d= -f2)
curl -sf -X POST https://zim.example.com/mcp \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "MCP-Protocol-Version: 2026-07-28" \
-H "Mcp-Method: tools/list" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
| head -c 500
Production hardening checklist (per-recipe)#
- Token rotation. Generate a new token, update
.env, rundocker compose up -dto pick up the change. Distribute the new token to clients out-of-band. - Non-root. The published image already runs as
appuser(UID 10001). Confirm withdocker compose exec openzim-mcp id— output should beuid=10001(appuser). - Log review.
docker compose logs -f openzim-mcpshows auth failures (the attempted token is not logged, but the request and outcome are). A burst of 401s from one client usually means a stale token. - Read-only ZIM mount. Already in the compose (
:ro). Don’t remove it.
Operations#
Upgrades#
# Pull the new image, then recreate containers using it
docker compose pull
docker compose up -d
The image tag in docker-compose.yml is pinned (:3.5.2) — change it to the new version before pulling.
Pinning is deliberate: :latest makes upgrades a surprise, and the release notes for each tag tell you when an upgrade involves a breaking change. The v1.x → v2.0.0 jump is a breaking rename of the advanced-mode tool surface (22 tools → 8). The v2.x → 3.0.0 jump breaks exactly the population this page serves: resources/subscribe/unsubscribe are no longer served (a legacy client gets -32601 and loses change notifications — live updates now mean negotiating 2026-07-28 and calling subscriptions/listen; see Resources, prompts & subscriptions), and link-graph sidecars built by 2.x are rejected on load — rebuild each with openzim-mcp build link-graph --force <archive>.zim, or zim_links(direction="inbound") degrades to inbound_sidecar_unavailable. See the CHANGELOG before bumping.
Watching logs#
docker compose logs -f openzim-mcp
A clean startup logs the bind host/port and the configured allowed directory. An auth failure logs the route, status, and client IP — not the attempted token. Subscription updates are delivered silently; the SDK logs a warning when it ends a listen stream whose client stopped reading and overran its event backlog.
Configuration reference: Configuration. Security model: Security best practices. Performance tuning: Performance optimization.
The v1.x maintenance window closed when v2.5.0 shipped (2026-06-18); only the current major line is supported — see SECURITY.md for the policy. The CHANGELOG carries the v1 → v2 migration table and the v3.0.0 breaking-changes entry.