Skip to content

Configuration

All configuration is through environment variables, so the server runs cleanly as a sidecar. The compose examples keep them in an env file next to the compose file.

Variable Default Purpose
PAPERLESS_URL required Base URL of the Paperless-ngx instance, as this container reaches it.
MCP_TOOLSETS (unset = defaults) Comma-separated toolsets to expose, or all. default stands for the default toolsets, so default,mail_rules adds to them. See Tools.
PAPERLESS_SPEC_WAIT 60 Seconds to wait for Paperless to serve the spec at startup.
MCP_HOST 0.0.0.0 Interface the MCP server binds to.
MCP_PORT 8081 Port the MCP server listens on.
MCP_ALLOWED_HOSTS (unset = any) Comma-separated Host allowlist (DNS-rebinding protection). Unset accepts any Host; set it to restrict. See Security.
MCP_PROXY_HOPS 1 How many reverse proxies stand in front of the server (2 for a CDN before your own proxy). Wrong logins are limited per client address, read from X-Forwarded-For that many entries from the end; too low and everyone counts as one address, which the log warns about once.
MCP_BASE_URL required Public URL clients reach this server at, e.g. https://paperless-ngx-mcp.example.com. The OAuth issuer: HTTPS, or plain http for localhost.
MCP_OAUTH_SECRET required Encrypts the OAuth store at /data/oauth (mount a volume at /data, writable for user 10001). Changing it logs everyone out.

The OpenAPI spec

Paperless-ngx serves its own OpenAPI spec at /api/schema/ (the page at /api/schema/view/ is the Swagger UI for it). At startup the Paperless-ngx MCP server downloads it from PAPERLESS_URL and generates the tools from it, so they match the Paperless version you run. The container log names the source:

OpenAPI spec: http://webserver:8000/api/schema/
  • Paperless still booting. Connection errors and 5xx answers are retried for PAPERLESS_SPEC_WAIT seconds, which covers both containers starting together.
  • Download fails. The server falls back to the snapshot bundled in the image and says so in the log. The tools then describe the Paperless version the image was built against, which may be newer or older than yours. Fix the URL and restart.
  • After a Paperless update. Restart the Paperless-ngx MCP server to pick up the new spec; it is read once, at startup.
  • Another spec, other tools, other texts. Everything but these variables is in config/sesamcp.yaml. Mount your own copy at /config/sesamcp.yaml, with the files it names beside it; Sesamcp's documentation explains every key.

The API version is read from the spec too. Paperless writes its version as 2.20.3 (9); the number in brackets is sent as Accept: application/json; version=9, so responses come in the shapes the spec describes. Without it Paperless answers in its oldest shapes.

OAuth details

Clients that support the MCP authorization spec need only the URL. On first connect they open a login page served by this server, you enter your Paperless username and password, and the server asks Paperless for your API token (POST /api/token/). Paperless creates the token at that moment if you don't have one yet.

  • The password goes to Paperless once and is never stored. What is stored, encrypted, is the API token.
  • Accounts with two-factor authentication enter their code on the same page.
  • Accounts without a password (single sign-on) paste their API token on the login page instead.
  • Raw API tokens in the Authorization header work next to it (Authorization: Bearer <token>).
  • Mount a volume at /data (see the compose examples) so logins survive the container being recreated, for example on an image update.
  • Paperless allows five login attempts a minute, counted per client address. Every login through the Paperless-ngx MCP server arrives from the sidecar's address, so that budget is shared by all its users. The login page shows Paperless's "try again in N seconds" when it is used up; raise it with Paperless's PAPERLESS_TOKEN_THROTTLE_RATE if you need to.
  • A login link stops working after five wrong passwords; the client starts a new login.

Upgrading

From 0.4.x to 0.5.0

0.5.0 is Sesamcp 0.3.2 with this repository's config, not the Python server of 0.4.x (ADR 0006).

  • Everyone signs in again. OAuth tokens now start with sesamcp_ instead of pmcp_, and the store has another salt, so no connector login of 0.4.x is read. Reconnect each connector. A raw API token in the Authorization header (Bearer <token>) keeps working.
  • MCP_BASE_URL and MCP_OAUTH_SECRET are required. OAuth and raw API tokens are always on; MCP_AUTH_MODE is gone.
  • Gone: MCP_PATH (always /mcp), PAPERLESS_API_SPEC and PAPERLESS_API_VERSION (mount your own /config/sesamcp.yaml instead). PAPERLESS_URL has no default any more.
  • New: MCP_PROXY_HOPS, see above.
  • The container runs as user 10001, no longer as root. A volume at /data from 0.4.x belongs to root: give it to that user (chown -R 10001 <volume>), or start with an empty volume, since its logins aren't read anyway.
  • The Authorization header takes Bearer <token> (or the bare token). Paperless's own Token <token> form is no longer accepted.
  • Bulk operations answer at once with their task_id instead of waiting for the task; the tools tell the model to check tasks_list.
  • Answers over 10 MB are refused, text as well as files.