Metadata-Version: 2.5
Name: swissdocai-mcp
Version: 0.2.0
Summary: MCP server for SwissDocAI: OCR, classification, extraction, layout and redaction of local documents, processed in Switzerland
Project-URL: Homepage, https://swissdocai.ch
Project-URL: Documentation, https://swissdocai.ch/api-dokumentation
Author: SwissDocAI
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: document-processing,mcp,ocr,redaction,switzerland
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing
Requires-Python: >=3.12
Requires-Dist: httpx<1,>=0.28
Requires-Dist: mcp<3,>=2.3
Description-Content-Type: text/markdown

# SwissDocAI MCP server

Use [SwissDocAI](https://swissdocai.ch) from Claude, Cursor, Codex or any other MCP client.
It runs on your computer as a local MCP server (stdio). You give the AI a file path. The
server reads the file itself and sends it to the SwissDocAI API (`https://ocr.swissdocai.ch`).
The AI never has to copy the document into the conversation.

| Tool | What it does | API |
|---|---|---|
| `process_document` | OCR, classification into your workspace's labels and extraction of the label's fields. Optionally splits a PDF of several documents and writes each one as its own PDF. | `POST /v1/upload` with `async=true`, `GET /v1/jobs/{job_id}` |
| `ocr_document` | The text of a document as Markdown, with page markers and tables. | `POST /v1/ocr` |
| `analyze_layout` | Words, lines, paragraphs, tables and checkboxes with their boxes, in the shape of Azure AI Document Intelligence's prebuilt-layout. It writes the result to `<name>.layout.json` (beta). | `POST /v1/layout`; from 11 pages, or while many requests are waiting, `POST /v1/layout/jobs` |
| `redact_document` | Finds personal data and writes a redacted PDF, `<name>.redacted.pdf`, next to the source (beta). | `POST /v1/redact` with `render=true`, `GET /v1/redact/{job_id}` |

The document tools take PDF, PNG and JPEG files. Each page processed costs one page of your
quota, the same as a direct API call.

The label tools manage the labels documents are classified into. They are free of charge,
apart from `classify_text`.

| Tool | What it does | API |
|---|---|---|
| `list_labels`, `get_label` | The workspace's labels with description, examples, fields, file name template and revision. | `GET /v1/labels`, `GET /v1/labels/{label_id}` |
| `create_label` | A new label. | `POST /v1/labels` |
| `update_label` | Changes the fields given; needs the label's current revision. | `PATCH /v1/labels/{label_id}` with `If-Match` |
| `delete_label` | Deletes a label with all its revisions, for good. | `DELETE /v1/labels/{label_id}` with `If-Match` |
| `list_label_revisions`, `restore_label_revision` | Earlier states of a label (the last 50), and going back to one. | `GET .../revisions`, `POST .../revisions/{revision}/restore` |
| `classify_text` | Classifies a text into the labels, to check a change. One page of quota per call. | `POST /v1/classify` |

## Labels

Any token can read labels. To create, change, restore or delete them, the token needs
"Read and write" access to labels, which you choose when you create it in the console.
With a read-only token these tools answer with a clear error.

A typical loop: read a label, change its description or examples, then check it with
`classify_text` on the text of a document you know (run `ocr_document` once and reuse the
text). Every change is kept as a revision, so `restore_label_revision` can undo it.
`update_label` sends the revision it read as `If-Match`; if someone changed the label in the
meantime, it is refused (412) instead of overwriting that change. Deleting a label cannot
be undone. AI clients usually ask before running a tool marked as destructive, as
`delete_label` is, but check the request before you approve it. At most 60 label changes
per minute.

## Where your data goes

**SwissDocAI processes your documents in Switzerland.** But this server hands the results
(text, extracted fields, labels) back to your AI client. From there they go to the client's
provider, for example Anthropic, Cursor or OpenAI, which may process them outside
Switzerland. You decide whether that is allowed for your documents.

To keep a document's content on your computer, pass `output_path`. The server then writes
the full result to that local file and sends only a short summary back to the AI: label,
confidence and page count, no text or fields. `analyze_layout` and `redact_document` always
write their results to a file. By default `redact_document` also leaves out the values it
found (`include_values=false`), because those values are the personal data being removed.

The file name is only sent along with `rename=true`, which needs it for the suggested file
name. Otherwise the document goes out as `document.pdf`. The server logs nothing: no
contents, texts, values or file names.

## Setup

You need:

- An API token from the [console](https://console.swissdocai.ch) (API-Tokens). Processing
  also needs labels; you create them in the console.
- [uv](https://docs.astral.sh/uv/getting-started/installation/), which provides `uvx`.

`uvx swissdocai-mcp` downloads the server and starts it. You never start it yourself: the
AI client does that. Replace `sd_...` with your token in the examples below.

### Claude Code

```bash
claude mcp add --env SWISSDOCAI_API_TOKEN=sd_... --transport stdio swissdocai -- uvx swissdocai-mcp
```

Add `--scope project` to share the server with your team through `.mcp.json`. Then use
`${SWISSDOCAI_API_TOKEN}` instead of the token itself, so the token stays out of the
repository:

```json
{
  "mcpServers": {
    "swissdocai": {
      "command": "uvx",
      "args": ["swissdocai-mcp"],
      "env": { "SWISSDOCAI_API_TOKEN": "${SWISSDOCAI_API_TOKEN}" }
    }
  }
}
```

### Claude Desktop

Quit Claude Desktop completely. Then edit `claude_desktop_config.json`:

- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "swissdocai": {
      "command": "uvx",
      "args": ["swissdocai-mcp"],
      "env": { "SWISSDOCAI_API_TOKEN": "sd_..." }
    }
  }
}
```

### Cursor

In `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project):

```json
{
  "mcpServers": {
    "swissdocai": {
      "command": "uvx",
      "args": ["swissdocai-mcp"],
      "env": { "SWISSDOCAI_API_TOKEN": "sd_..." }
    }
  }
}
```

### Codex

```bash
codex mcp add swissdocai --env SWISSDOCAI_API_TOKEN=sd_... -- uvx swissdocai-mcp
```

Or in `~/.codex/config.toml`. Codex stops a tool after 60 seconds by default, which is too
short for redaction and for long documents, so raise `tool_timeout_sec`. The first start
downloads the server, so give it more time as well:

```toml
[mcp_servers.swissdocai]
command = "uvx"
args = ["swissdocai-mcp"]
startup_timeout_sec = 60
tool_timeout_sec = 1800

[mcp_servers.swissdocai.env]
SWISSDOCAI_API_TOKEN = "sd_..."
```

## Examples

- "Process `~/Scans/invoice-0425.pdf` with SwissDocAI and give me the total and the IBAN."
- "Split `C:\Inbox\batch.pdf` into its documents and save each one as its own PDF."
- "Redact `report.pdf` and keep the clinic's name and address readable."
- "Run OCR on `contract.pdf` and save the text to `contract.md`; don't show me the text."
- "Show my labels. `scan-17.pdf` is a delivery note but comes out as an invoice: improve the
  labels until it is classified right, and tell me what you changed."
- "Add a field `Vertragsende` (date) to the label `contract`."

## Settings

| Environment variable | Default | Meaning |
|---|---|---|
| `SWISSDOCAI_API_TOKEN` | (required) | API token from the console |
| `SWISSDOCAI_BASE_URL` | `https://ocr.swissdocai.ch` | Another endpoint, e.g. an on-premises installation |
| `SWISSDOCAI_JOB_TIMEOUT_SECONDS` | `1800` | How long a tool waits for a job (processing, layout, redaction) |
| `SWISSDOCAI_POLL_INTERVAL_SECONDS` | `2` | How often a running job is checked |

Relative paths are resolved against the server's working directory, which depends on the
client. Absolute paths always work.

## Files the server writes

- Never the source file, and never over an existing file it chose itself: if the name is
  taken, it writes `name (2).ext`. Only a file you name in `output_path` is overwritten.
- `analyze_layout`: `<name>.layout.json` next to the source.
- `redact_document`: `<name>.redacted.pdf`, or with `render=false` the findings with their
  boxes as `<name>.redaction.json`.
- `process_document` with `save_split_pdfs=true`: `<name>_01_p1-2.pdf`, `<name>_02_p3-3.pdf` and so on.

Redaction is automatic: check the redacted PDF before you pass it on. The summary tells you
how many values could not be located on the page (`values_not_located`), and whether the
redacted pages, when read again, still show a value (`verification`).

## Errors

API errors come back as tool errors that say what to do: an invalid token (401), no active
plan (402), a read-only token or team (403), a label ID that already exists (409), a label
changed in the meantime (412), a document too large (413), quota or rate limit reached
(429, with the time to retry), or a busy service (503, nothing charged, try again shortly).

## Development

```bash
uv sync
uv run pytest
uv run ruff check .
uv run swissdocai-mcp   # waits for an MCP client on stdin
```

The tests replace the network with a mock (`httpx.MockTransport`) and never call the API.
To run your local checkout in a client, use `uv run --directory /path/to/mcp-server swissdocai-mcp`
as the command instead of `uvx swissdocai-mcp`.

## License

[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), full text in the `LICENSE` file
that ships with the package. Copyright 2026 SwissDocAI.

The license covers this client only. The SwissDocAI service it calls is not part of the package
and is used under the SwissDocAI terms of service (https://swissdocai.ch/agb).
