Configuration
Every supported environment variable, CLI flag, and configuration field for OpenZIM MCP.
Source of truth: openzim_mcp/config.py and openzim_mcp/defaults.py. If this page disagrees with code, code wins — please file an issue.
How configuration is loaded#
OpenZIM MCP is a pydantic-settings BaseSettings model. Every field can be set three ways, in priority order:
- CLI flag (where one is wired through
main.py— currently--mode,--transport,--host,--port) - Environment variable, prefixed with
OPENZIM_MCP_ - Default value from the field’s own declaration — many nested defaults (
cache.*,content.*,meta.*,search.*,rate_limit.*) come from the shared constants in defaults.py, while the server-level fields (transport,host,port,tool_mode,server_name,logging.*, and the watcher/subscription knobs) are declared inline in config.py.
Nested fields use a double-underscore separator: OPENZIM_MCP_CACHE__MAX_SIZE, OPENZIM_MCP_RATE_LIMIT__BURST_SIZE, etc.
A bad value raises OpenZimMcpConfigurationError at startup with a human-readable message — pydantic’s raw ValidationError dump is wrapped before it reaches the operator.
Tool mode#
# Default: simple — exposes one natural-language tool (zim_query)
# Set to advanced for the full 8-tool advanced surface
export OPENZIM_MCP_TOOL_MODE=advanced
Or via CLI:
openzim-mcp --mode advanced /path/to/zim/files
| Mode | Tool surface | When to use |
|---|---|---|
simple (default) | 1 tool: zim_query (NL intent router) | small/local LLMs, MCP hosts that struggle with large tool catalogs |
advanced | 8 tools: zim_query, zim_search, zim_get, zim_get_section, zim_browse, zim_metadata, zim_links, zim_health (see API reference) | hosts that handle a richer tool surface, scripting, fine-grained control |
The advanced surface is 8 consolidated tools — collapsed from the prior 22-tool v1 surface. The advanced-mode wire footprint is ~23.8KB (24,359 bytes, held under a hard 25,600-byte budget by tests/test_phase_f_schema_budget.py), down from ~36KB, clearing the MCP Tax pain band (25–50KB schema) for small-model dispatch. See the v1 → v2 migration table if you’re upgrading.
Transport#
# Default: stdio (no network)
# Other values: http (streamable HTTP), sse (legacy, localhost-only, deprecated — removed in 4.0.0)
export OPENZIM_MCP_TRANSPORT=http
export OPENZIM_MCP_HOST=127.0.0.1 # default 127.0.0.1
export OPENZIM_MCP_PORT=8000 # default 8000
export OPENZIM_MCP_AUTH_TOKEN="$(openssl rand -hex 32)" # required for non-localhost
export OPENZIM_MCP_CORS_ORIGINS='["https://app.example"]' # JSON list; "*" rejected
| Field | Env var | Default | Notes |
|---|---|---|---|
auth_token | OPENZIM_MCP_AUTH_TOKEN | unset | Bearer token for streamable HTTP. Stored as SecretStr; never logged. Set via env only — never put it in a file. |
cors_origins | OPENZIM_MCP_CORS_ORIGINS | [] | JSON list of allowed origins. Wildcard "*" is rejected at startup (whitespace-padded " * " too). |
host | OPENZIM_MCP_HOST | 127.0.0.1 | Bind address. Non-loopback hosts require auth_token for http; sse always rejects non-loopback. |
port | OPENZIM_MCP_PORT | 8000 | 1-65535. |
stateless_http | OPENZIM_MCP_STATELESS_HTTP | false | http only. Serves clients on the initialize handshake without sessions: no Mcp-Session-Id is issued, every POST is answered on its own, and every other method on /mcp gets 405 with Allow: POST (with CORS origins set, a preflight is still answered by the CORS layer). Replicas then need no session affinity. The cost: a handshake-era notifications/cancelled is ignored, so a client cancels a call by closing that call’s connection. Set it on all of them or none, and see Scaling considerations before switching a running fleet. 2026-07-28 clients are unaffected. |
transport | OPENZIM_MCP_TRANSPORT | stdio | One of stdio/http/sse. sse has no auth middleware and is loopback-only, and is deprecated — it warns on every start and is removed in 4.0.0. |
Safe-default startup check — the server refuses to bind if either:
transport=http+ non-loopback host + noauth_token→OpenZimMcpConfigurationError: HTTP transport bound to {host} requires authentication.transport=sse+ non-loopback host →OpenZimMcpConfigurationError: SSE transport bound to {host} is not allowed.
Exception: setting OPENZIM_MCP_INSECURE_DISABLE_AUTH=1 lets http bind a non-loopback host without a token — intended for closed networks (Docker bridge, Tailscale-only, isolated LAN). The server logs a WARNING naming the bound host; the SSE refusal has no escape hatch. Behind a Host-preserving reverse proxy, also set OPENZIM_MCP_ALLOWED_HOSTS to the public hostname(s). Loopback Host values are always accepted, and every entry in OPENZIM_MCP_ALLOWED_HOSTS is added on top of them on any bind (a bare entry also gets a :* wildcard-port form, so a proxy’s Host: mcp.example.com:443 matches); on a bind-all host (0.0.0.0, ::) with an empty allow-list the server turns DNS-rebinding Host validation off and warns, since any allow-list would 421 every direct-IP client — setting OPENZIM_MCP_ALLOWED_HOSTS turns it back on. The Origin check stays on either way: a browser request from an origin outside OPENZIM_MCP_CORS_ORIGINS gets 403.
For full HTTP deployment guidance see HTTP and Docker Deployment.
Resource subscriptions#
Polling-based mtime watcher. A .zim appearing in or disappearing from an allowed directory publishes notifications/resources/list_changed; a .zim replaced in place publishes notifications/resources/updated for that archive’s zim://{name}. Both reach clients that opted in via subscriptions/listen, and only under the HTTP transport.
export OPENZIM_MCP_SUBSCRIPTIONS_ENABLED=true # default true
export OPENZIM_MCP_WATCH_INTERVAL_SECONDS=5 # default 5, range 1-60
export OPENZIM_MCP_RESOURCE_CACHE_TTL_SECONDS=3600 # default 3600, range 0-86400
Setting OPENZIM_MCP_SUBSCRIPTIONS_ENABLED=false skips the polling task and withholds the capability: resources.subscribe and the listChanged flags read false, and subscriptions/listen fails with method-not-found instead of acknowledging a stream that would never fire. Tune OPENZIM_MCP_WATCH_INTERVAL_SECONDS upward for low-priority watching, downward (to a floor of 1s) for faster detection.
Read caching#
Results carry the 2026-07-28 ttlMs/cacheScope hints, which tell a client how long it may reuse an answer instead of asking again. OPENZIM_MCP_RESOURCE_CACHE_TTL_SECONDS sets that window for the zim://{name} overview, where it pays off most: a ZIM file is sealed, so the overview changes only when the file itself is replaced, and each read costs three blocking archive opens. Per-entry reads (zim://{name}/entry/{path}) stay on the watcher-bounded TTL — no resources/updated is ever published for an entry URI, so a longer promise could not be invalidated.
zim://files is deliberately excluded. It is a live scan of the allowed directories, so it stays bounded by OPENZIM_MCP_WATCH_INTERVAL_SECONDS and a cached copy is never staler than the server’s own detection latency.
The trade-off is staleness after a replacement. A client on an open subscriptions/listen stream is told immediately and re-reads, so the TTL costs it nothing. A client that is not subscribed — anything on stdio, or an HTTP client that never opened a stream — can keep serving the old overview for up to the TTL. If you hot-swap archives in place and cannot rely on subscribers, lower it, or set 0 to turn the override off entirely and put overview reads back on the same watcher-bounded TTL as zim://files.
Cache#
Single LRU+TTL cache shared by all tools and the smart-retrieval path-mapping store.
export OPENZIM_MCP_CACHE__ENABLED=true # default true
export OPENZIM_MCP_CACHE__MAX_SIZE=100 # default 100, range 1-10000
export OPENZIM_MCP_CACHE__TTL_SECONDS=3600 # default 3600, range 60-86400
export OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED=false # default false
export OPENZIM_MCP_CACHE__PERSISTENCE_PATH="$HOME/.cache/openzim-mcp" # default
export OPENZIM_MCP_CACHE__LIBZIM_CLUSTER_CACHE_MAX_SIZE_BYTES=16777216 # default unset (libzim 16 MiB)
export OPENZIM_MCP_CACHE__LIBZIM_DIRENT_CACHE_MAX_COUNT=512 # default unset (libzim 512)
| Field | Default | Range |
|---|---|---|
cache.enabled | true | bool |
cache.max_size | 100 | 1-10000 |
cache.persistence_enabled | false | bool |
cache.persistence_path | ~/.cache/openzim-mcp | normalized to absolute path; falls in a predictable location even when CWD is unpredictable (containers, systemd) |
cache.ttl_seconds | 3600 | 60-86400 (1 min - 24 h) |
cache.libzim_cluster_cache_max_size_bytes | unset (libzim default 16 MiB) | 0 – 4 GiB, bytes; process-global (libzim’s cluster cache) |
cache.libzim_dirent_cache_max_count | unset (libzim default 512) | 0 – 10,000,000, count of dirents; per-archive |
These last two are independent of the response cache above: they size libzim’s own reader caches. Leave them unset to keep libzim’s defaults. The cluster cache is sized in bytes and is process-global; the dirent cache is a count of directory entries applied per opened archive. See Performance optimization for tuning guidance.
Cache stats surface inside zim_health under .health.cache_performance — there are no explicit warm_cache/cache_stats/cache_clear tools. Restarting flushes the cache only when CACHE__PERSISTENCE_ENABLED is off; with persistence on it is saved at exit and reloaded at start.
Persistence note: when
persistence_enabled=true,cache.set()validates that the value is JSON-serializable at write time and raisesOpenZimMcpValidationErrorif not (no silentstr()coercion). Internal callers always pass JSON-safe values (strings, dicts, lists, numbers, bools), so this only matters if you’ve patched in a custom caller that stashes aPath,datetime, or other non-JSON object. Pure in-memory caches (persistence off) still accept arbitrary Python objects.
Content#
export OPENZIM_MCP_CONTENT__MAX_CONTENT_LENGTH=100000 # default 100000, min 100
export OPENZIM_MCP_CONTENT__SNIPPET_LENGTH=3000 # default 3000, min 100
export OPENZIM_MCP_CONTENT__DEFAULT_SEARCH_LIMIT=10 # default 10, range 1-100
The config field content.max_content_length must be >= 100; a lower value fails pydantic validation and aborts startup as an OpenZimMcpConfigurationError, never as a tool response. The separate per-call max_content_length argument — accepted only by zim_get and zim_query — is validated independently and only has to be >= 1; below that the call returns a ToolErrorPayload, {"error": true, "operation": "invalid_max_content_length", "message": "..."}, which the server delivers as JSON text with isError: true.
Logging#
export OPENZIM_MCP_LOGGING__LEVEL=INFO # default INFO; one of DEBUG/INFO/WARNING/ERROR/CRITICAL
export OPENZIM_MCP_LOGGING__FORMAT="%(asctime)s - %(name)s - %(levelname)s - %(message)s" # default
Only level and format are configurable — there is no separate JSON-mode toggle. To emit JSON, supply a JSON format string (or wrap stdout with a JSON-converting handler in your deployment).
Rate limiting#
Token-bucket limiter; global + per-operation acquire is atomic (one pass, no transient over-consumption).
The budget is denominated in work units, not requests. Most operations cost 1, searches cost 2, and a binary fetch costs 3 — so requests_per_second is really “work units per second”. Size any override against the cost of the operation you are limiting, or it will admit fewer calls than the number suggests.
export OPENZIM_MCP_RATE_LIMIT__ENABLED=true # default true
export OPENZIM_MCP_RATE_LIMIT__REQUESTS_PER_SECOND=20.0 # default 20.0 (work units/s)
export OPENZIM_MCP_RATE_LIMIT__BURST_SIZE=40 # default 40, max 1000
# Per-operation limits (nested dict, JSON):
export OPENZIM_MCP_RATE_LIMIT__PER_OPERATION_LIMITS='{"search": {"requests_per_second": 4, "burst_size": 8}}'
Per-internal-operation cost defaults are defined in defaults.RATE_LIMIT_COSTS. The v2 tools dispatch internally; each branch resolves to a specific operation key the limiter charges against.
Note on key vocabulary. The internal operation keys below are stable pydantic-validated identifiers — they happen to share their string form with the v1 tool names, but they are config keys, not v1 tool surfaces. The keys remained stable through the v1 → v2 tool collapse so that existing
PER_OPERATION_LIMITSoverrides in production deployments did not need to be rewritten when the wire-level tool surface changed.
| v2 tool call | Internal operation key (literal) | Cost |
|---|---|---|
zim_search(mode="fulltext") | "search" | 2 |
zim_search(mode="title") | "find_entry_by_title" | 2 |
zim_search(mode="fulltext") with namespace/content_type | "search_with_filters" | 2 |
zim_search(mode="suggest") | "suggestions" | 1 |
zim_get(entry_path=...) | "get_entry" | 1 |
zim_get(entry_paths=[...]) | "get_zim_entries" (×N per-entry) | 1 |
zim_get(binary=True) | "get_binary_entry" | 3 |
zim_get(view="structure") / view="toc" / view="summary") | "get_structure" | 1 |
zim_browse(...) | "browse_namespace" | 1 |
zim_metadata(...) | "get_metadata" | 1 |
zim_links(direction="outbound") | "extract_article_links" | 2 |
zim_links(direction="inbound") | "get_inbound_links" | 1 |
zim_links(direction="related") | "get_related_articles" | 2 |
zim_health / zim_get_section / zim_query | "zim_health" / "zim_get_section" / "zim_query" (bucket keyed on the tool name; the cost falls back to the default cost) | 1 |
resources/read of zim://{name}/entry/{path} | "get_entry" | 1 |
resources/read of zim://{name} (archive overview) | "get_metadata" | 1 |
resources/read of zim://files | "zim_files" (keyed on its own name; the cost falls back to the default cost) | 1 |
zim_get(entry_paths=[...]) charges per-entry so a batch does not trivially bypass the per-second limit. The charge is min(len(entry_paths), 50) units — MAX_BATCH_SIZE is 50 — taken as two debits: one unit up front, before validation, and the remainder after, clamped to the bucket’s capacity. An over-size batch is rejected after the first unit, so it costs 1 rather than a full bucket.
mode wins over the filter arguments when the bucket key is resolved: zim_search(mode="title", namespace=...) keys on "find_entry_by_title", not "search_with_filters". Rejected calls are charged before they are rejected, deliberately — malformed input is never free.
How the limiter identifies a client#
Buckets are keyed per client, derived in this order: a hash of the presented bearer token, then the peer IP, then the literal "default".
Only one token value is ever accepted — OPENZIM_MCP_AUTH_TOKEN is a single credential, not a list — so on the deployment this page recommends, every authenticated client shares one bucket. Per-client isolation is real but it separates tokens, and there is only one. Size the limits for your total expected load, not per consumer. Issuing a token per consumer would need a change to the server.
There is no X-Forwarded-For handling in this project. Unauthenticated callers are separated by peer IP, which behind a reverse proxy on another host or container is the proxy’s address — again one bucket. (The server runs uvicorn with proxy headers off, so X-Forwarded-For is ignored even from 127.0.0.1: a client cannot mint itself a fresh bucket by sending one.)
stdio callers, and the deprecated sse transport, all get "default". The client table is LRU-bounded at 10,000 entries, which is not configurable; an evicted client returns to a fresh bucket at full burst.
Per-operation overrides use the literal key strings shown in the right column. To throttle binary fetches:
# `get_binary_entry` costs 3 units, so burst_size 6 admits two fetches:
export OPENZIM_MCP_RATE_LIMIT__PER_OPERATION_LIMITS='{"get_binary_entry": {"requests_per_second": 3, "burst_size": 6}}'
Server identity#
export OPENZIM_MCP_SERVER_NAME=openzim-mcp # default openzim-mcp; reported in serverInfo
serverInfo.version always reports openzim-mcp’s installed version (read from importlib.metadata), no longer the MCP SDK default.
Server instructions#
Requires 3.5 or later. Earlier releases ignore OPENZIM_MCP_INSTRUCTIONS and OPENZIM_MCP_INSTRUCTIONS_PATH without an error.
When a client connects, the server sends it a short block of instructions: in the initialize result for handshake-era clients, and in server/discover for 2026-07-28 clients. Most hosts put the text in the model’s context. The built-in text says what the server is and, in advanced mode, which of the eight tools to reach for; in simple mode it says how to ask zim_query.
Replace it to tell the model about your deployment: what your archives hold, and when to prefer this server over another tool. Use a file for anything longer than a line:
export OPENZIM_MCP_INSTRUCTIONS_PATH=/etc/openzim-mcp/instructions.md
Medical reference archives (MedlinePlus, WikEM). Prefer them over web search
for clinical questions, and cite the article title in the answer.
{{default}}
Or set the text itself:
export OPENZIM_MCP_INSTRUCTIONS='Medical reference archives. Prefer them over web search.
{{default}}'
Your text replaces the built-in instructions. Put {{default}} where you want the built-in text kept: the server swaps the token for the built-in text of the running tool mode, so it stays right when you change modes or upgrade. Leave the token out and clients get only your text. That drops the tool-routing guidance, and the note that a rejected argument comes back flagged isError with a JSON body. The usual pattern is a few sentences of your own followed by {{default}}. Put what matters first and keep it short: hosts carry the text in the model’s context on every turn, and some keep only the first few thousand characters.
The rules:
- Set one variable or neither. Both set is a startup error. An empty value counts as unset, so a template that renders an unset variable as
""keeps the built-in text. There is no way to send no instructions; the shortest override is one line of your own. - A file that is set but unusable stops the server at startup. That covers a missing file, a directory, a FIFO or device, an unreadable file, a file that is not UTF-8 (UTF-16 included), one containing a NUL byte, and an empty file. The error starts
Configuration error:and names the variable and the path; the server never falls back to the built-in text silently. UTF-8 byte-order marks (U+FEFF) are dropped wherever they appear, in the file or inOPENZIM_MCP_INSTRUCTIONS, and CRLF line endings become LF. - The path may start with
~. Surrounding whitespace is ignored, and a relative path resolves against the server’s working directory, which for a GUI-launched host is rarely the one you expect: use an absolute path. - Inline text is sent as written. A
\ninside single quotes is two characters, not a newline: use a file, the shell’s$'…'quoting, or your YAML or JSON’s own newline escapes. Text that is not valid UTF-8 is a startup error. - Every
{{default}}expands, inside code fences too, and there is no escape for a literal one. Leading and trailing whitespace is trimmed and the text ends with a single newline, so{{default}}on its own is exactly the built-in text. - The limit is 16 KiB (16384 bytes) of what clients receive: after
{{default}}expands, and counting the final newline. A file over the limit, or text that expands past it, stops startup. The built-in text is larger in advanced mode, so a file near the limit can fit in simple mode and not in advanced. - The text is read once, at startup. Restart the server to apply a change.
Checking what clients receive#
Every start logs one line saying which text is in effect, at INFO on stderr. Under stdio the host captures stderr; Claude Desktop, for example, writes it to its MCP server log files.
Server instructions: built-in, for simple mode (547 bytes)
Server instructions: custom, from OPENZIM_MCP_INSTRUCTIONS_PATH='/etc/openzim-mcp/instructions.md' (691 bytes, 687 characters); the built-in simple-mode guidance is included via {{default}}
Server instructions: custom, from OPENZIM_MCP_INSTRUCTIONS (80 bytes, 80 characters); the built-in guidance is not included (no {{default}} token)
The first is the default; the second is the example file above in simple mode; the third is text set without the token. The line never contains the text itself. At the default log level, a start that logs no Server instructions: line at all is running a release that predates the setting and ignores both variables. OPENZIM_MCP_LOGGING__LEVEL=WARNING or higher hides the line, and ERROR or higher hides the warnings below as well; the checks that follow work at any level. Startup also logs a warning, without refusing to start, when:
- your text names a tool the running mode does not register (simple mode registers only
zim_query), or something close to a tool name, such aszim_serach; - it contains a near-miss of the token, such as
{{ default }}or{default}, which is sent to clients as written; the token with extra braces or a$against it, such as{{{default}}}, which expands but keeps them; or one of the template escapes below in a file no template engine rendered, which expands inside the escape; - an environment variable looks like this setting but is not one, such as
OPENZIM_MCP_INSTRUCTIONS_FILEorOPENZIM_MCP_INSTRUCTIONS__PATH, and is ignored; OPENZIM_MCP_INSTRUCTIONSlooks like a file path, which clients would receive as the text. That is one line that names an existing file; one word ending in.md,.markdownor.txt, such asnotes.mdorconfig/notes.md(except in Chinese, Japanese or Thai, where one word can be a whole sentence); a line that starts like a path and has no spaces or one of those endings; or a$(cat …),$(< …)or backquotedcat …that no shell ran, such as$(cat /config/instructions.md). Quotes around the value, straight or curly, are ignored. A path starts with/,~/,./,../, a drive (C:\orC:/), a share (\\server), or a variable that was never expanded, such as$HOME/or%USERPROFILE%\. SetOPENZIM_MCP_INSTRUCTIONS_PATHto load the file.
To see exactly what a client receives, ask the server. A stdio server answers on stdin; run it with the deployment’s environment and tool mode, since the text depends on both (the CLI defaults to simple mode, the published image to advanced):
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
| openzim-mcp /srv/zim 2>/dev/null \
| python3 -c 'import json, sys; sys.stdout.write(json.loads(sys.stdin.readline())["result"]["instructions"])'
The same pipe works with docker run -i --rm … (and the image’s usual mounts and -e flags) in place of openzim-mcp /srv/zim. Over HTTP, ask the running service itself, so its own environment answers; $TOKEN holds its OPENZIM_MCP_AUTH_TOKEN. Keep the MCP-Protocol-Version and Mcp-Method headers: without the first, the request is read as a handshake-era one, and the second must name the method in the body.
curl -sS -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: server/discover" \
-d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
| python3 -c 'import json, sys; sys.stdout.write(json.load(sys.stdin)["result"]["instructions"])'
If either check prints a Python traceback instead of the text, run it without the final python3 stage, and the stdio one without 2>/dev/null, to see what happened. The stdio server prints its own Configuration error:. An HTTP service that refused to start is not listening, so curl reports that it could not connect, and the error is in the service’s own log (docker logs, or journalctl under systemd). An unauthorized reply means the token is wrong, and an error about a missing session or the Mcp-Method header means a header is.
When a change reaches clients#
The server reads the text once, at startup, so restart it after editing. Clients matter too: most hosts read the instructions once per connection, so reconnect the client or start a new conversation. Over HTTP, sessionless clients see no disconnect when the server restarts. Every 2026-07-28 client is one, and the server/discover result tells it that it may cache the result for up to an hour, so it can keep the previous text that long. Handshake-era clients are sessionless only when OPENZIM_MCP_STATELESS_HTTP is set, and get no such limit: they keep the text from their initialize until they reconnect. On Kubernetes, editing a ConfigMap updates the mounted file but restarts nothing: run kubectl rollout restart deployment/openzim-mcp.
Deployment examples#
Docker. Mount the file read-only, outside /data (which holds the archives):
docker run -i --rm \
-v /srv/zim:/data:ro \
-v "$PWD/instructions.md:/config/instructions.md:ro" \
-e OPENZIM_MCP_INSTRUCTIONS_PATH=/config/instructions.md \
ghcr.io/cameronrye/openzim-mcp
The container runs as UID 10001, so the file must be world-readable or owned by that UID. If the host file does not exist, Docker creates an empty directory in its place, and the server stops with … is a directory. --env-file holds one line per variable, so it cannot carry multi-line text; use the file.
Docker Compose:
services:
openzim-mcp:
image: ghcr.io/cameronrye/openzim-mcp
environment:
OPENZIM_MCP_INSTRUCTIONS_PATH: /config/instructions.md
volumes:
- /srv/zim:/data:ro
- ./instructions.md:/config/instructions.md:ro
Compose interpolates $ in environment: values, so inline text needs every literal $ written as $$. A YAML value that starts with {{default}} must be quoted or written as a | block: unquoted, YAML reads the braces as a mapping.
Kubernetes. Keep the text in a ConfigMap and mount it:
apiVersion: v1
kind: ConfigMap
metadata:
name: openzim-mcp-instructions
data:
instructions.md: |
Medical reference archives (MedlinePlus, WikEM). Prefer them over web
search for clinical questions.
{{default}}
# Added to the Deployment in the Kubernetes example on the deployment page.
containers:
- name: openzim-mcp
env:
- name: OPENZIM_MCP_INSTRUCTIONS_PATH
value: /config/instructions.md
volumeMounts:
- name: instructions
mountPath: /config
readOnly: true
volumes:
- name: instructions
configMap:
name: openzim-mcp-instructions
A ConfigMap’s files are world-readable by default. A key the ConfigMap lacks mounts as nothing, and the server reports that the path does not exist. With Helm, render the ConfigMap from a value with {{ .Values.instructions | nindent 4 }}. The value’s own {{default}} passes through untouched as long as the value is never run through tpl; inside a chart template itself, write the token as {{ "{{default}}" }}. That escape belongs in the template only: in the value, nothing renders it, and clients get the built-in text inside it (startup warns). Set the value with --set-file instructions=instructions.md, not --set, which splits on commas. Render the env var and the mount only when the value is set: an always-rendered empty key mounts an empty file, which stops startup.
Template engines. Jinja2 and Ansible templates, and Go templates such as Helm’s, read {{ }} as their own syntax. Jinja2 renders an undefined name as an empty string, so {{default}} can vanish from a templated file without an error. The startup line then says no {{default}} token. Copy the file verbatim instead of templating it, or wrap the token as {% raw %}{{default}}{% endraw %} and template it; a wrapped file copied verbatim keeps the wrapper, which startup warns about.
systemd. Add the path to the unit:
[Service]
Environment=OPENZIM_MCP_INSTRUCTIONS_PATH=/etc/openzim-mcp/instructions.md
The service’s User= reads the file, not root (systemd itself reads EnvironmentFile= as root), so give it mode 0644, or 0640 with the service’s group. With the hardened unit, keep the file under /etc. ProtectHome=yes makes /home inaccessible, so a file there is refused as permission denied however its own permissions are set, and PrivateTmp=yes gives the service an empty /tmp of its own, so a file there reads as missing. Inline text in Environment= is awkward, since % starts a systemd specifier and must be written %%. Prefer the file.
MCP host configs (Claude Desktop and others):
{
"mcpServers": {
"openzim-mcp": {
"command": "uvx",
"args": ["openzim-mcp", "/path/to/zim/files"],
"env": {
"OPENZIM_MCP_INSTRUCTIONS_PATH": "/path/to/instructions.md"
}
}
}
}
On Windows, write the path with forward slashes (C:/Users/me/instructions.md) or doubled backslashes. In JSON, \n and \t inside a string are a newline and a tab, so "C:\new\temp.md" is not the path it looks like. With "command": "docker", the env block sets the environment of the docker command, not the container’s: pass -e OPENZIM_MCP_INSTRUCTIONS_PATH=… and the -v mount in args instead. The .mcpb bundle does not expose this setting.
Keep secrets out#
The instructions go to every client that can connect: on HTTP that is every token holder, anyone at all on a loopback bind with no token, and anyone who can reach the port when OPENZIM_MCP_INSECURE_DISABLE_AUTH is set. Hosts place them in the model’s context, so they also end up in transcripts and in model-provider logs. Never put credentials or internal-only details in them. They also speak with the server’s authority to every connected model, so mount the file read-only and limit who can edit it, through file permissions or ConfigMap RBAC.
Allowed directories#
ZIM file directories. Pass on the CLI:
openzim-mcp /srv/zim /home/user/zim-files
At least one directory is required; each is canonicalized (resolves symlinks and ..) and verified to exist and be a directory at startup. Paths in MCP error responses are redacted to a ...filename.zim form so the canonical layout is never leaked.
Complete reference table#
A nested field’s environment variable joins its levels with __, so cache.max_size is OPENZIM_MCP_CACHE__MAX_SIZE. The specialized groups named below the thread-pool table are not listed here.
| Field | Env var | Default | Notes |
|---|---|---|---|
allowed_hosts | OPENZIM_MCP_ALLOWED_HOSTS | [] | JSON list of extra accepted Host header values (HTTP). Loopback values are always accepted and these entries are added on top of them on any bind; leaving this empty on a bind-all host (0.0.0.0, ::) disables Host validation with a warning. Set it behind Host-preserving reverse proxies. An entry of exactly * is rejected at startup; a :* port suffix is allowed |
auth_token | OPENZIM_MCP_AUTH_TOKEN | unset | SecretStr, never logged, env-only |
cache.enabled | OPENZIM_MCP_CACHE__ENABLED | true | bool |
cache.max_bytes | OPENZIM_MCP_CACHE__MAX_BYTES | 64 MiB | approximate byte cap on cached values; 0 disables |
cache.libzim_cluster_cache_max_size_bytes | OPENZIM_MCP_CACHE__LIBZIM_CLUSTER_CACHE_MAX_SIZE_BYTES | unset (libzim 16 MiB) | 0 – 4 GiB, bytes, process-global |
cache.libzim_dirent_cache_max_count | OPENZIM_MCP_CACHE__LIBZIM_DIRENT_CACHE_MAX_COUNT | unset (libzim 512) | 0 – 10,000,000, count, per-archive |
cache.max_size | OPENZIM_MCP_CACHE__MAX_SIZE | 100 | 1-10000 |
cache.persistence_enabled | OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED | false | bool |
cache.persistence_path | OPENZIM_MCP_CACHE__PERSISTENCE_PATH | ~/.cache/openzim-mcp | normalized absolute |
cache.ttl_seconds | OPENZIM_MCP_CACHE__TTL_SECONDS | 3600 | 60-86400 |
content.default_search_limit | OPENZIM_MCP_CONTENT__DEFAULT_SEARCH_LIMIT | 10 | 1-100 |
content.max_content_length | OPENZIM_MCP_CONTENT__MAX_CONTENT_LENGTH | 100000 | min 100 |
content.snippet_length | OPENZIM_MCP_CONTENT__SNIPPET_LENGTH | 3000 | min 100 |
content.table_row_threshold | OPENZIM_MCP_CONTENT__TABLE_ROW_THRESHOLD | 8 | min 1; tables with more rows collapse in compact mode |
content.table_char_threshold | OPENZIM_MCP_CONTENT__TABLE_CHAR_THRESHOLD | 600 | min 50; char size past which a table collapses |
content.infobox_kv_limit | OPENZIM_MCP_CONTENT__INFOBOX_KV_LIMIT | 30 | 1-200; key/value pairs kept from an infobox |
cors_origins | OPENZIM_MCP_CORS_ORIGINS | [] | JSON list; * rejected |
host | OPENZIM_MCP_HOST | 127.0.0.1 | non-loopback requires auth (http) or refuses (sse) |
insecure_disable_auth | OPENZIM_MCP_INSECURE_DISABLE_AUTH | false | escape hatch: allows token-less non-loopback HTTP with a WARNING (closed networks only) |
instructions | OPENZIM_MCP_INSTRUCTIONS | unset | (3.5+) replaces the server instructions; {{default}} keeps the built-in text — rules. Not with instructions_path |
instructions_path | OPENZIM_MCP_INSTRUCTIONS_PATH | unset | (3.5+) UTF-8 file holding the instructions, read once at startup; a set but unusable file stops startup |
logging.format | OPENZIM_MCP_LOGGING__FORMAT | %(asctime)s - %(name)s - %(levelname)s - %(message)s | logging format string |
meta.footer_enabled | OPENZIM_MCP_META__FOOTER_ENABLED | true | Append the one-line _meta footer to simple-mode responses. Turning it off does not remove _meta itself — see the _meta envelope |
logging.level | OPENZIM_MCP_LOGGING__LEVEL | INFO | DEBUG/INFO/WARNING/ERROR/CRITICAL |
port | OPENZIM_MCP_PORT | 8000 | 1-65535 |
presets_override_path | OPENZIM_MCP_PRESETS_OVERRIDE_PATH | unset | TOML file deep-merged over the bundled archive-type presets — format and the confidence gate |
rate_limit.burst_size | OPENZIM_MCP_RATE_LIMIT__BURST_SIZE | 40 | 1-1000 (work units) |
rate_limit.enabled | OPENZIM_MCP_RATE_LIMIT__ENABLED | true | bool |
rate_limit.per_operation_limits | OPENZIM_MCP_RATE_LIMIT__PER_OPERATION_LIMITS | {} | nested JSON dict |
rate_limit.requests_per_second | OPENZIM_MCP_RATE_LIMIT__REQUESTS_PER_SECOND | 20.0 | positive float (work units/s) |
resource_cache_ttl_seconds | OPENZIM_MCP_RESOURCE_CACHE_TTL_SECONDS | 3600 | 0-86400; 0 disables |
server_name | OPENZIM_MCP_SERVER_NAME | openzim-mcp | reported in serverInfo |
stateless_http | OPENZIM_MCP_STATELESS_HTTP | false | http only: handshake-era clients get no session, so replicas need no affinity |
subscriptions_enabled | OPENZIM_MCP_SUBSCRIPTIONS_ENABLED | true | watcher master switch |
tool_mode | OPENZIM_MCP_TOOL_MODE | simple | simple or advanced |
transport | OPENZIM_MCP_TRANSPORT | stdio | stdio/http/sse (sse deprecated, removed in 4.0.0) |
watch_interval_seconds | OPENZIM_MCP_WATCH_INTERVAL_SECONDS | 5 | 1-60 |
Thread-pool sizing (env-only)#
Two knobs are read straight from the environment rather than through the config
model, so they have no openzim_mcp.config field and do not appear above. They
bound the worker pools that back timed-out libzim and regex work — a timed-out
worker cannot be killed, so the cap is what makes sustained timeouts show up as
rising queue depth instead of OS-thread exhaustion. Garbage values fall back to
the default with a warning.
| Environment variable | Default | Notes |
|---|---|---|
OPENZIM_MCP_TIMEOUT_MAX_WORKERS | 16 | I/O pool; sized for a typical 4–8 vCPU server |
OPENZIM_MCP_REGEX_MAX_WORKERS | 8 | Regex pool |
The /readyz probe has its own dedicated single-slot pool, which is not
configurable — sharing the I/O pool let repeated probes against a wedged mount
burn workers that every MCP tool call also needs.
Further nested groups exist for specialized tuning — search.* (e.g. OPENZIM_MCP_SEARCH__SEARCH_ALL_TOTAL_TIMEOUT_SECONDS), query_rewrite.*, synthesize.*, meta.*, and ml.reranker.* (documented on Search reranking). Their fields and defaults live in openzim_mcp/config.py.
Archive-type presets#
The server classifies each archive — wikipedia, wiktionary, stackexchange, ted or
generic — and tunes retrieval for it. OPENZIM_MCP_PRESETS_OVERRIDE_PATH points at a TOML file
that is deep-merged over the bundled presets, per key, so you override one value without
restating the rest. The bundled file ships presets for wikipedia and stackexchange only.
# Adjust a bundled preset — the other keys stay as shipped.
[preset.wikipedia]
snippet_length = 1200
# Add one for a type that has none.
[preset.ted]
summary_style = "first_section"
max_paragraphs = 2
# Pin one specific archive. The table key is the archive's M/Name metadata
# value, NOT its filename.
[archive.wikipedia_en_climate_change]
type = "stackexchange"
snippet_length = 900
Three fields, all optional; a missing one inherits the global default:
| Field | Type | Constraint |
|---|---|---|
snippet_length | integer | ≥ 100 |
max_paragraphs | integer | ≥ 1 |
summary_style | string | "first_section" or "q_and_a" — those two only |
[archive.*] tables take those three plus type, which forces a classification.
The load-bearing rule is the confidence gate. Detection returns a confidence of high,
medium or none. A type preset applies only at high; at medium or none the archive
gets generic behaviour, however well the type matched. A per-archive pin applies at every
confidence level — so pinning is how you force behaviour onto an archive the classifier will
not commit to. A pin also merges over its type’s preset rather than replacing it.
Two things to know before you write one:
- The pin key is
M/Name, not the filename. Forwikipedia_en_climate_change_mini_2024-06.zimthe key iswikipedia_en_climate_change. A table keyed on the filename matches nothing and fails silently — you get the type preset, and no warning. Read the value back withzim_metadata, undermetadata.Name. - A broken override never stops the server. An unreadable file, invalid TOML, or an unknown key logs a warning and falls back to the bundled defaults. That is deliberate — a typo in an operator file must not take the server down — but it does mean a silently ineffective override looks exactly like a working one. Check the startup log.
Profiles#
These are the canonical deployment profiles; Performance optimization explains which knob to move for a given symptom and links back here for the recipes. Every setting is an environment variable, so the same names and values carry into a systemd EnvironmentFile or a container’s environment: block — drop the export keyword there. Each comment names the code default, so you can see what the line is actually changing.
Local development (stdio)#
export OPENZIM_MCP_LOGGING__LEVEL=DEBUG
export OPENZIM_MCP_CACHE__MAX_SIZE=50 # default 100
export OPENZIM_MCP_CACHE__TTL_SECONDS=1800 # default 3600
openzim-mcp ~/zim-files
Single-user desktop (stdio, e.g. Claude Desktop)#
The defaults already fit this shape — one client, one archive set. Reach for these only if you keep a lot of articles hot and want the cache to survive a restart:
export OPENZIM_MCP_CACHE__MAX_SIZE=500 # default 100
export OPENZIM_MCP_CACHE__TTL_SECONDS=14400 # default 3600
export OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED=true # default false; survives restarts
export OPENZIM_MCP_CONTENT__MAX_CONTENT_LENGTH=200000 # default 100000
openzim-mcp /srv/zim
Production HTTP service#
export OPENZIM_MCP_TRANSPORT=http # default stdio
export OPENZIM_MCP_HOST=127.0.0.1 # default 127.0.0.1
export OPENZIM_MCP_PORT=8000 # default 8000
export OPENZIM_MCP_AUTH_TOKEN="$(openssl rand -hex 32)"
export OPENZIM_MCP_CORS_ORIGINS='["https://app.example.com"]'
# The code default is simple mode, which exposes zim_query alone. A service
# whose clients call zim_get / zim_search / zim_health directly needs the
# advanced surface. (The published Docker image already sets this.)
export OPENZIM_MCP_TOOL_MODE=advanced
export OPENZIM_MCP_LOGGING__LEVEL=INFO
export OPENZIM_MCP_CACHE__MAX_SIZE=1000 # default 100
export OPENZIM_MCP_CACHE__TTL_SECONDS=14400 # default 3600
export OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED=true
# Set this explicitly. Left unset, the server appends a config fingerprint and
# a .json suffix to the default path, so the file lands at
# ~/.cache/openzim-mcp-<12 hex>.json — a sibling of ~/.cache/openzim-mcp, not a
# file inside it, and a volume mounted at that directory captures nothing.
export OPENZIM_MCP_CACHE__PERSISTENCE_PATH=/var/lib/openzim-mcp/cache.json
export OPENZIM_MCP_CONTENT__MAX_CONTENT_LENGTH=200000 # default 100000
# Defaults are 20/s with a burst of 40. Raise them for a multi-client service —
# but note every request carrying the bearer token shares one bucket, because
# the limiter keys on a hash of the token before falling back to peer IP.
export OPENZIM_MCP_RATE_LIMIT__REQUESTS_PER_SECOND=40
export OPENZIM_MCP_RATE_LIMIT__BURST_SIZE=80
# Subscriptions stay on, polled less often for less I/O churn (default 5).
export OPENZIM_MCP_WATCH_INTERVAL_SECONDS=15
openzim-mcp /srv/zim
Front it with a TLS-terminating reverse proxy (Caddy, nginx, traefik) — there is no built-in TLS.
Read-heavy single archive#
One large archive, mostly repeat reads. Spend the memory on cache residency:
export OPENZIM_MCP_CACHE__MAX_SIZE=2000 # default 100
export OPENZIM_MCP_CACHE__TTL_SECONDS=28800 # default 3600 (8 h)
export OPENZIM_MCP_CACHE__PERSISTENCE_ENABLED=true
export OPENZIM_MCP_CONTENT__DEFAULT_SEARCH_LIMIT=20 # default 10
openzim-mcp /srv/zim
MAX_SIZE counts entries, not bytes, and OPENZIM_MCP_CACHE__MAX_BYTES (64 MiB) bounds the store independently — on an archive of long articles the byte cap is what binds, so raising MAX_SIZE alone buys less than the number suggests.
Memory-constrained (e.g. small VPS, RPi)#
export OPENZIM_MCP_CACHE__MAX_SIZE=25 # default 100
export OPENZIM_MCP_CACHE__TTL_SECONDS=900 # default 3600
export OPENZIM_MCP_CONTENT__MAX_CONTENT_LENGTH=50000 # default 100000
export OPENZIM_MCP_CONTENT__SNIPPET_LENGTH=500 # default 3000
export OPENZIM_MCP_WATCH_INTERVAL_SECONDS=30 # default 5
export OPENZIM_MCP_SUBSCRIPTIONS_ENABLED=false # default true
openzim-mcp ~/zim-files
Validating configuration#
There is no offline --validate flag. Two options:
- Start the server with stdio. Bad config raises
OpenZimMcpConfigurationErrorimmediately. The error message names the offending field. - Call
zim_health— but only on the advanced surface. It is not registered in simple mode, which is the default, so this needs--mode advanced,OPENZIM_MCP_TOOL_MODE=advanced, or the published Docker image.
zim_health()
On a default simple-mode install the nearest equivalent is asking zim_query for "list available ZIM files", which confirms the allowed directories resolved and each archive is readable but reports no configuration. Phrasing it as a request for health or configuration does not reach zim_health: there is no health intent in simple mode, so the words are treated as a search topic.
The zim_health() response includes (abbreviated):
.health— server status, uptime, cache performance, health checks, warnings, recommendations.configuration— resolved values (no secrets;server_pidand directory paths redacted over HTTP/SSE, shown on local stdio).loaded_archives— list of every ZIM file in the allowed directories
Setting environment variables#
Linux / macOS:
echo 'export OPENZIM_MCP_CACHE__MAX_SIZE=200' >> ~/.bashrc
source ~/.bashrc
Windows (PowerShell):
$env:OPENZIM_MCP_CACHE__MAX_SIZE = "200"
[Environment]::SetEnvironmentVariable("OPENZIM_MCP_CACHE__MAX_SIZE", "200", "User")
systemd unit:
[Service]
Environment=OPENZIM_MCP_TRANSPORT=http
Environment=OPENZIM_MCP_HOST=127.0.0.1
# Holds OPENZIM_MCP_AUTH_TOKEN
EnvironmentFile=/etc/openzim-mcp/secrets.env
ExecStart=/usr/local/bin/openzim-mcp /srv/zim
Docker: see HTTP and Docker Deployment.
Stale env vars (not in code)#
The following env-var namespaces appeared in pre-1.0 / early-v2 documentation and do not exist in the current codebase. If a tool or example tells you to set them, the source is stale:
OPENZIM_MCP_INSTANCE__*— multi-instance conflict tracking was removed entirely.OPENZIM_MCP_SECURITY__*— there is noSecurityConfig. Path validation, input sanitization, and limits are all controlled by the values listed above.OPENZIM_MCP_SMART_RETRIEVAL__*— smart retrieval shares the global cache; there are no dedicated knobs.OPENZIM_MCP_METRICS__*andOPENZIM_MCP_MONITORING__*— no first-party metrics endpoint; use/healthz,/readyz, andzim_healthinstead.OPENZIM_MCP_SERVER__MAX_CONCURRENT,OPENZIM_MCP_SERVER__REQUEST_TIMEOUT,OPENZIM_MCP_SERVER_DESCRIPTION,OPENZIM_MCP_SERVER__ENABLE_MONITORING— never existed.OPENZIM_MCP_CONTENT__CONVERT_HTML,OPENZIM_MCP_CONTENT__PRESERVE_FORMATTING— content processing is unconditional.OPENZIM_MCP_LOGGING__JSON,OPENZIM_MCP_LOGGING__SECURITY_EVENTS— onlylevelandformatare configurable.
Tuning? See Performance Optimization. Deploying over HTTP? See HTTP and Docker Deployment.
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.