Skip to main content
Glama
paperless-mcp

paperless-mcp

by dtbell91
README.md
# paperless-mcp

A deliberately minimal [MCP](https://modelcontextprotocol.io) server for a personal
[Paperless-ngx](https://docs.paperless-ngx.com) instance: one ~250-line file and two dependencies
([FastMCP](https://gofastmcp.com) and [httpx](https://www.python-httpx.org)).

> **Personal and unsupported.** This is written to be small enough to read in one sitting
> and audit yourself. Fork it rather than depending on it. Issues and feature requests are
> unlikely to be acted on, and it won't be published to PyPI or MCP directories.

## Why another one?

The existing Paperless MCP servers aim to cover the whole Paperless API (45–100+ tools).
That's useful, but it's a lot of code to trust with sensitive documents. This one does only
what an assistant needs day to day (find, read, file) and leaves administration to the
Paperless UI.

## Tools

| Tool | Kind | What it does |
|---|---|---|
| `search_documents` | read | Full-text search plus filters by tag, correspondent, type and date range, using names. Returns metadata and a highlighted match, never OCR text. |
| `get_document` | read | Metadata, notes and OCR text: 4,000 characters by default, at most 20,000 per call, with an offset to read on. |
| `find_in_document` | read | Passages around each match of a word or phrase in one document, for specific questions about long documents. |
| `list_labels` | read | Tags, correspondents or document types, with document counts. |
| `update_document` | write | Title, date, correspondent, type, add/remove tags. |
| `bulk_edit` | write | The same tag/correspondent/type change on many documents. |
| `create_label` | write | New tag, correspondent or document type. |
| `add_note` | write | Add a note to a document. |

Write tools are registered only when `PAPERLESS_MCP_READ_ONLY=false` (it defaults to `true`).
**There are no delete tools.** Every tool carries MCP read-only/destructive annotations, so clients
can auto-approve reads and confirm writes.

## Security model

- **Paperless enforces permissions.** Run the server with the API token of a dedicated Paperless
  user (e.g. `claude`) that has view permissions, and later change/add permissions, but no delete
  or admin rights. Note that Paperless hides documents owned by other users unless they're shared
  with this user, so grant it access to existing documents and use a workflow to share new ones.
- **The HTTP endpoint requires a bearer token.** The server refuses to start over HTTP without
  `PAPERLESS_MCP_AUTH_TOKEN`.
- **No internet access.** `compose.yml` puts the server on an `internal: true` Docker network
  shared only with Paperless and a Tailscale sidecar, so it has nowhere to send data even if a
  dependency were compromised. It also runs as non-root, with a read-only filesystem and no
  Linux capabilities.
- **Context-friendly by design.** Search results never include OCR text, and document reads
  are capped and chunked.

## Running it

Written for Paperless-ngx v3 (REST API v10). [`compose.yml`](compose.yml) assumes the Paperless
service is called `webserver`, as in the official compose files.

1. **Create the Paperless user.** In Settings → Users & Groups, add a user such as `claude`: not
   superuser or staff, with view/add/change on documents, tags, correspondents and document types,
   view/add on notes, view on tasks (so bulk edits can report failures), and no delete permissions. Log in as it once and generate an API token.
2. **Share documents with it.** Select your documents, open Permissions, add the user under Edit and
   tick Merge. Do the same for tags, correspondents and document types it should see. For new
   documents, add a workflow: trigger *Document Added*, action *Assignment*, edit permission for the user.
3. **Let the server reach Paperless.** It connects to `http://webserver:8000`, so add `webserver` to
   `PAPERLESS_ALLOWED_HOSTS` in Paperless's environment, or Paperless rejects the requests as
   `DisallowedHost`. Setting `PAPERLESS_ALLOWED_HOSTS` replaces the list `PAPERLESS_URL` gives,
   so list your usual hostname too:
   ```sh
   PAPERLESS_ALLOWED_HOSTS=paperless.your-tailnet.ts.net,webserver
   ```
4. **Add this repo and configure it.** Clone it into the folder holding your Paperless compose file,
   then add the lines from [`.env.example`](.env.example) to the `.env` there. `COMPOSE_FILE` merges
   this repo's `compose.yml` into the Paperless project, so plain `docker compose` commands manage
   both and the clone needs no local edits. (`include:` won't work: it can't add a network to
   `webserver`.) The Tailscale auth key needs a tag listed under `tagOwners` in your tailnet policy.
   ```sh
   cd ~/paperless && git clone https://github.com/dtbell91/paperless-mcp
   ```
5. **Start it.**
   ```sh
   docker compose up -d --build
   ```

The Tailscale sidecar serves it at `https://paperless-mcp.<tailnet>.ts.net/mcp`. For Claude Code:

```sh
claude mcp add --transport http paperless https://paperless-mcp.<tailnet>.ts.net/mcp \
  --header "Authorization: Bearer <PAPERLESS_MCP_AUTH_TOKEN>"
```

For local use without Docker, set `MCP_TRANSPORT=stdio` and run `python server.py` from your MCP client.

### Configuration

| Variable | Default | Purpose |
|---|---|---|
| `PAPERLESS_URL` | required | Paperless base URL as the server reaches it |
| `PAPERLESS_TOKEN` | required | Paperless API token |
| `PAPERLESS_PUBLIC_URL` | `PAPERLESS_URL` | Base URL for the document links shown to you (`compose.yml` reads `PAPERLESS_MCP_PUBLIC_URL` from `.env`) |
| `PAPERLESS_API_VERSION` | `10` | Paperless REST API version (10 is the default in Paperless-ngx v3) |
| `PAPERLESS_MCP_READ_ONLY` | `true` | Set to `false` to register write tools (`compose.yml` reads it from `.env`) |
| `PAPERLESS_MCP_AUTH_TOKEN` | — | Bearer token for the HTTP endpoint (required for HTTP) |
| `MCP_TRANSPORT` | `http` | `http` or `stdio` |
| `MCP_PORT` | `8000` | HTTP port |

## Limitations

- Claude in the browser and the mobile apps connect from Anthropic's servers and need OAuth,
  which this doesn't do yet. FastMCP's OAuth providers make that a small change.
- No upload tool: documents come in through Paperless's own email, app and consume-folder routes.

## Development

```sh
pip install -r requirements.txt
python test_server.py   # runs against a mock Paperless API
```

Dependabot proposes dependency and base image updates weekly, and CI runs the tests and a Docker build.

## License

MIT