papra-mcp 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # Virtual environment
2
+ .venv
3
+
4
+ # Python cache
5
+ __pycache__/
6
+
7
+ # Build artifacts
8
+ dist/
9
+
10
+ # Claude / editor local settings
11
+ .claude/
12
+ CLAUDE.md
@@ -0,0 +1,34 @@
1
+ # AGENTS.md
2
+
3
+ ## Required Environment
4
+ `PAPRA_BASE_URL` (valid URL with scheme + host) and `PAPRA_API_KEY` must be set. Optional: `PAPRA_TIMEOUT` (seconds, default 60), `PAPRA_MAX_CONTENT_BYTES` (default 5 MB), `PAPRA_LOG_LEVEL` (default INFO). All are validated at startup; the server exits immediately on a missing or malformed value.
5
+
6
+ ## Commands
7
+ - Install: `pip install -e ".[dev]"`
8
+ - Start server: `python papra_mcp.py` (or `papra-mcp` after install)
9
+ - Run tests: `pytest` (no live Papra instance required, uses mocked HTTP requests)
10
+ - Lint: `ruff check .`
11
+
12
+ ## Architecture
13
+ - Single-file application: all logic in `papra_mcp.py`, built with FastMCP.
14
+ - `httpx.AsyncClient` is initialized once at startup via the lifespan context manager, using env vars for base URL, auth header, timeout, and redirect handling.
15
+ - Every tool is wrapped in `@tool_errors`, which converts exceptions into `ToolError` so MCP flags the result with `isError`. Do not return error strings from a tool.
16
+ - Tools take a single Pydantic model named `params`; validation lives in the model, not the tool body.
17
+
18
+ ## Dependency constraints
19
+ - `mcp[cli]` is pinned to `<2`. MCP SDK 2.0 renamed `mcp.server.fastmcp` to `mcp.server.mcpserver` and `FastMCP` to `MCPServer`, which breaks this server on import. Migrating means updating the import, the `mcp = FastMCP(...)` construction, and the `ToolError` import path.
20
+
21
+ ## Papra API notes
22
+ - The supported target is Papra 0.3.0 at commit `648c223b807500f0258c822e0321d6ef4964f064`; do not claim compatibility with other versions without a new live verification.
23
+ - There is **no** `/documents/search` endpoint. Search runs through `GET /documents` with the `searchQuery` parameter; both `papra_list_documents` and `papra_search_documents` go through `_list_documents`.
24
+ - `GET /documents` also accepts `sortField` (`createdAt`, `updatedAt`, `name`, `documentDate`) and `sortOrder` (`asc`, `desc`).
25
+ - Upload is `multipart/form-data` with a `file` field and optional `ocrLanguages`. Papra takes the document name and file type from the multipart file name, so it must be a real name with an extension.
26
+ - Restore, permanent deletion, trash emptying, and tagging-rule apply are session-only routes at the supported version. Do not register API-key tools for them or add session-cookie fallback. Listing deleted documents supports API keys.
27
+
28
+ ## Tool-Specific Notes
29
+ - `papra_get_document_content` returns: plain text for text MIME types, extracted PDF text, or base64 JSON for binary. Text decoding is strict so mislabelled binaries fall back to base64. Text over the size limit is truncated; oversized binary is refused.
30
+ - `papra_create_document` requires strictly valid base64 (`validate=True`); plain text belongs in `papra_create_text_document`.
31
+ - Tag color values must match the regex `^#[0-9a-fA-F]{6}$` (enforced by Pydantic input models).
32
+ - Resource IDs use `<prefix>_<24 lowercase letters or digits>` with resource-specific prefixes (`org`, `doc`, `tag`, `cpd`, `cpso`, `usr`). Reject navigation and encoded variants before HTTP and encode valid IDs as one path segment.
33
+ - Multi-select and relation values are full replacement arrays; omitted IDs are removed and `[]` clears values. Option replacement requires every option's `name`, retained option IDs, and the current or new definition `name` on Papra 0.3.0.
34
+ - Update tools raise `ToolError` when no field is provided, instead of silently doing nothing.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,325 @@
1
+ Metadata-Version: 2.5
2
+ Name: papra-mcp
3
+ Version: 0.2.0
4
+ Summary: MCP server for the Papra document management API
5
+ Project-URL: Homepage, https://github.com/Rigare/papra-mcp
6
+ Project-URL: Repository, https://github.com/Rigare/papra-mcp
7
+ Project-URL: Issues, https://github.com/Rigare/papra-mcp/issues
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: document-management,mcp,papra
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Office/Business
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: httpx>=0.27.0
23
+ Requires-Dist: mcp[cli]<2,>=1.9.0
24
+ Requires-Dist: pydantic>=2.0.0
25
+ Requires-Dist: pymupdf>=1.25.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
28
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
29
+ Requires-Dist: ruff>=0.6.0; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Papra MCP Server
33
+
34
+ [![PyPI](https://img.shields.io/pypi/v/papra-mcp)](https://pypi.org/project/papra-mcp/)
35
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org)
36
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-green)](https://github.com/Rigare/papra-mcp/blob/main/LICENSE)
37
+
38
+ An [MCP](https://modelcontextprotocol.io) (Model Context Protocol) server for the [Papra](https://papra.app) document management API. Gives AI assistants the ability to manage organizations, documents, tags, and custom properties in your Papra instance.
39
+
40
+ Exposes 32 tools whose routes support Bearer API-key authentication. Session-only routes are deliberately not registered, and the server never falls back to session cookies.
41
+
42
+ ## Prerequisites
43
+
44
+ - Python 3.10+
45
+ - A running [Papra](https://github.com/papra-hq/papra) instance
46
+ - An API key from your Papra account settings
47
+ - Papra monorepo version 0.3.0 at commit `648c223b807500f0258c822e0321d6ef4964f064`; compatibility with other server versions is not claimed
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install papra-mcp
53
+ ```
54
+
55
+ Or run it without a permanent install via [uv](https://docs.astral.sh/uv/): `uvx papra-mcp`.
56
+
57
+ From source:
58
+
59
+ ```bash
60
+ git clone https://github.com/Rigare/papra-mcp.git
61
+ cd papra-mcp
62
+ pip install -e .
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ | Variable | Required | Default | Description |
68
+ |----------|----------|---------|-------------|
69
+ | `PAPRA_BASE_URL` | yes | — | Your Papra instance URL (e.g. `https://papra.example.com`) |
70
+ | `PAPRA_API_KEY` | yes | — | API key from your Papra account settings |
71
+ | `PAPRA_TIMEOUT` | no | `60` | HTTP timeout in seconds |
72
+ | `PAPRA_MAX_CONTENT_BYTES` | no | `5242880` | Size limit for document content returned to the model (5 MB) |
73
+ | `PAPRA_LOG_LEVEL` | no | `INFO` | Log level; logs always go to stderr |
74
+
75
+ All values are validated at startup. The server exits with a clear error if a required variable is missing, if `PAPRA_BASE_URL` is not a well-formed URL (missing scheme or host), or if a numeric variable is not a positive number.
76
+
77
+ ## Usage
78
+
79
+ ### Claude Desktop
80
+
81
+ Add the following to your `claude_desktop_config.json`:
82
+
83
+ ```json
84
+ {
85
+ "mcpServers": {
86
+ "papra": {
87
+ "command": "uvx",
88
+ "args": ["papra-mcp"],
89
+ "env": {
90
+ "PAPRA_BASE_URL": "https://papra.example.com",
91
+ "PAPRA_API_KEY": "your-api-key-here"
92
+ }
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ ### Claude Code
99
+
100
+ Add via the CLI:
101
+
102
+ ```bash
103
+ claude mcp add papra \
104
+ -e PAPRA_BASE_URL=https://papra.example.com \
105
+ -e PAPRA_API_KEY=your-api-key-here \
106
+ -- uvx papra-mcp
107
+ ```
108
+
109
+ If you installed with `pip`, use `papra-mcp` as the command instead of `uvx papra-mcp`.
110
+
111
+ ### Development
112
+
113
+ ```bash
114
+ pip install -e ".[dev]"
115
+ pytest # no live Papra instance required, HTTP is mocked
116
+ ruff check .
117
+ mcp dev papra_mcp.py # interactive tool inspector
118
+ ```
119
+
120
+ ### Live contract verification
121
+
122
+ `tests/test_live_papra.py` is an opt-in integration suite for a **separate disposable Papra instance**, never a production instance. It creates a random account, API keys, organizations, documents, and custom properties, and replaces or clears test values. The target must use SQLite, listen on loopback, and report both version 0.3.0 and commit `648c223b807500f0258c822e0321d6ef4964f064` from `/api/config`; the test stops before creating data if either differs.
123
+
124
+ Run Papra from its own checkout at that commit. Its Dockerfile specifies Node 26.12.1. Install dependencies with `pnpm install --frozen-lockfile`, build with `pnpm --filter "@papra/app-server..." run build`, then run `pnpm migrate:up:prod` and `pnpm start` in `apps/papra-server`. Set `PAPRA_VERSION=0.3.0` and `GIT_COMMIT` to the pinned commit, use matching local base URLs and a random `AUTH_SECRET`, and keep `PROCESS_MODE=web`. A checkout nested in another Git repository must retain its own `.git` metadata so Papra does not report the outer project's commit.
125
+
126
+ With the disposable server available at `http://127.0.0.1:37065`, run:
127
+
128
+ ```bash
129
+ PAPRA_RUN_LIVE_TESTS=1 \
130
+ PAPRA_LIVE_BASE_URL=http://127.0.0.1:37065 \
131
+ pytest tests/test_live_papra.py
132
+ ```
133
+
134
+ Without `PAPRA_RUN_LIVE_TESTS=1`, these tests are skipped. Browser-session authentication is used only to provision the throwaway account and API keys; all adapter calls under test use Bearer API keys.
135
+
136
+ ## Compatibility and API-key capabilities
137
+
138
+ The compatibility target is **Papra monorepo 0.3.0**, commit `648c223b807500f0258c822e0321d6ef4964f064`. Route registration and input validation follow that version's authentication middleware and validators. Other versions may work, but are not advertised as supported without a new verification run.
139
+
140
+ Authentication uses only the `Authorization: Bearer …` API-key header. The adapter does not create, accept, or fall back to session cookies. Create keys with only the permissions required for the tools you use:
141
+
142
+ | Tools | Minimum API-key scopes |
143
+ |-------|------------------------|
144
+ | `papra_check_api_key` | Any valid API key; no additional scope |
145
+ | `papra_list_organizations`, `papra_get_organization` | `organizations:read` |
146
+ | `papra_create_organization` | `organizations:create` |
147
+ | `papra_update_organization` | `organizations:update` |
148
+ | `papra_delete_organization` | `organizations:delete` |
149
+ | `papra_list_documents`, `papra_search_documents`, `papra_list_deleted_documents`, `papra_get_document`, `papra_get_document_content`, `papra_get_document_statistics`, `papra_get_document_activity` | `documents:read` |
150
+ | `papra_create_document`, `papra_create_text_document` | `documents:create` |
151
+ | `papra_update_document`, `papra_reprocess_document` | `documents:update` |
152
+ | `papra_delete_document` | `documents:delete` |
153
+ | `papra_list_tags` | `tags:read` |
154
+ | `papra_create_tag` | `tags:create` |
155
+ | `papra_update_tag` | `tags:update` |
156
+ | `papra_delete_tag` | `tags:delete` |
157
+ | `papra_add_tag_to_document`, `papra_remove_tag_from_document` | `documents:update` **and** `tags:read` |
158
+ | `papra_list_custom_properties`, `papra_get_custom_property` | `custom-properties:read` |
159
+ | `papra_create_custom_property` | `custom-properties:create` |
160
+ | `papra_update_custom_property` | `custom-properties:update` |
161
+ | `papra_delete_custom_property` | `custom-properties:delete` |
162
+ | `papra_list_document_custom_properties` | `documents:read` **and** `custom-properties:read` |
163
+ | `papra_set_document_custom_property`, `papra_clear_document_custom_property` | `documents:update` **and** `custom-properties:read` |
164
+
165
+ The following upstream routes require a browser session at the target version, regardless of API-key scopes, and therefore have **no MCP tool**: document restore, permanent document deletion, emptying trash, and applying a tagging rule. Listing deleted documents remains available with `documents:read`.
166
+
167
+ ### Resource IDs
168
+
169
+ Resource IDs use Papra's actual `<prefix>_<24 lowercase letters or digits>` format. The prefixes are `org_`, `doc_`, `tag_`, `cpd_` (property definitions), `cpso_` (property options), and `usr_` (users). IDs are bound to their resource type and encoded as one URL path segment. Empty values, wrong prefixes, separators, query/fragment characters, dot segments, and percent-encoded or repeatedly encoded navigation variants are rejected before any HTTP request.
170
+
171
+ ## Tools (32)
172
+
173
+ ### API Key
174
+
175
+ | Tool | Description |
176
+ |------|-------------|
177
+ | `papra_check_api_key` | Check the current API key's ID, name, and permissions |
178
+
179
+ ### Organizations
180
+
181
+ | Tool | Description |
182
+ |------|-------------|
183
+ | `papra_list_organizations` | List all accessible organizations |
184
+ | `papra_get_organization` | Get details of a specific organization |
185
+ | `papra_create_organization` | Create a new organization (name: 3-50 chars) |
186
+ | `papra_update_organization` | Update an organization's name |
187
+ | `papra_delete_organization` | Delete an organization (**destructive**) |
188
+
189
+ ### Documents
190
+
191
+ | Tool | Description |
192
+ |------|-------------|
193
+ | `papra_list_documents` | List documents with pagination, search, and sorting |
194
+ | `papra_search_documents` | Search documents (`name:`, `content:`, `tag:`, `created:`, `date:`, `has:date`, `has:tags`, `AND`, `OR`, `NOT`) with next-page navigation |
195
+ | `papra_create_document` | Upload a document from base64-encoded content |
196
+ | `papra_create_text_document` | Upload a document from plain text, no base64 needed |
197
+ | `papra_get_document` | Get a document's metadata |
198
+ | `papra_get_document_content` | Get file content (text directly, PDFs as extracted text, other binary as base64) |
199
+ | `papra_get_document_statistics` | Get document count and total size for an organization |
200
+ | `papra_update_document` | Replace name, indexed content, document date or notes; omitted fields stay unchanged |
201
+ | `papra_reprocess_document` | Queue background reprocessing (re-extract text, re-run OCR) |
202
+ | `papra_delete_document` | Soft-delete a document (moves to trash) |
203
+ | `papra_get_document_activity` | Get the activity log of a document |
204
+
205
+ #### Document date and notes
206
+
207
+ `papra_update_document` requires `documents:update` and takes one `params` object. Every supplied value replaces the current field. Omitted fields stay unchanged; an update with no values is rejected.
208
+
209
+ ```json
210
+ {
211
+ "params": {
212
+ "organization_id": "org_111111111111111111111111",
213
+ "document_id": "doc_111111111111111111111111",
214
+ "document_date": "2026-11-10",
215
+ "notes": "Reviewed against the original invoice."
216
+ }
217
+ }
218
+ ```
219
+
220
+ `document_date` maps to Papra's `documentDate`. Use `YYYY-MM-DD` for UTC midnight, or an ISO 8601 datetime with a timezone, such as `2026-11-10T14:30:00+01:00`. Explicit `"document_date": null` clears the date. `notes` replaces the full text, accepts at most 2048 UTF-16 code units (most characters count as one; an emoji can count as two), and is cleared with `"notes": ""`. Explicit `"notes": null` is invalid. For example, supplying only `document_date: null` leaves the name, indexed content and notes unchanged. These operations are marked destructive and idempotent in the tool annotations because they can overwrite or clear existing values.
221
+
222
+ #### Search filters and navigation
223
+
224
+ Both `papra_list_documents` and `papra_search_documents` use the existing `GET /documents` API. They pass `search_query` unchanged, including quotes and spaces. The following examples are verified for the supported Papra 0.3.0 commit:
225
+
226
+ | `search_query` | Matches |
227
+ |---|---|
228
+ | `has:date` | Documents with a document date |
229
+ | `has:tags` | Documents with at least one tag |
230
+ | `date:>=2026-11-10 date:<2026-11-11` | Document dates within 10 November 2026 in UTC |
231
+ | `name:"quarterly report" has:date has:tags date:>=2026-01-01 date:<2027-01-01` | Names containing the quoted phrase, with tags and a document date in 2026 |
232
+ | `has:date NOT has:tags` | Dated documents with no tags |
233
+
234
+ Adjacent filters are combined with AND; `AND`, `OR`, `NOT` and parentheses are also supported. `date:` compares exact instants: `date:2026-11-10` means midnight, so use a lower and upper bound for a whole day. Invalid dates do not match. The pinned [update validators](https://github.com/papra-hq/papra/blob/648c223b807500f0258c822e0321d6ef4964f064/apps/papra-server/src/modules/documents/documents.schemas.ts) and [search implementation](https://github.com/papra-hq/papra/blob/648c223b807500f0258c822e0321d6ef4964f064/apps/papra-server/src/modules/documents/document-search/database-fts5/query-builder/query-builder.ts) define this contract.
235
+
236
+ Pages are zero-based, with `page_size` from 1 to 100 (default 100). Results retain Papra's `documents` and `documentsCount` and add `pagination` with `page_index`, `page_size`, `has_more` and `next_call`. For 101 matches at the default page size, page 0 returns 100 documents and this navigation:
237
+
238
+ ```json
239
+ {
240
+ "page_index": 0,
241
+ "page_size": 100,
242
+ "has_more": true,
243
+ "next_call": {
244
+ "name": "papra_search_documents",
245
+ "arguments": {
246
+ "params": {
247
+ "organization_id": "org_111111111111111111111111",
248
+ "page_index": 1,
249
+ "page_size": 100,
250
+ "search_query": "has:date",
251
+ "sort_field": "createdAt",
252
+ "sort_order": "desc"
253
+ }
254
+ }
255
+ }
256
+ }
257
+ ```
258
+
259
+ Call the indicated tool with exactly `next_call.arguments`. It preserves the query, sort and page size; listing results point back to `papra_list_documents`. Continue until `has_more` is false and `next_call` is null. In this example page 1 returns the last document. Empty results and pages beyond the end have the same terminal state. Pagination reads the current collection on each call; changes during traversal can shift results between pages.
260
+
261
+ ### Trash
262
+
263
+ | Tool | Description |
264
+ |------|-------------|
265
+ | `papra_list_deleted_documents` | List deleted documents (trash); restoring or permanently deleting is session-only in Papra |
266
+
267
+ ### Tags
268
+
269
+ | Tool | Description |
270
+ |------|-------------|
271
+ | `papra_list_tags` | List all tags in an organization |
272
+ | `papra_create_tag` | Create a tag with name, hex color, and optional description |
273
+ | `papra_update_tag` | Update a tag's name, color, or description |
274
+ | `papra_delete_tag` | Delete a tag (**destructive**) |
275
+ | `papra_add_tag_to_document` | Associate a tag with a document |
276
+ | `papra_remove_tag_from_document` | Remove a tag from a document |
277
+
278
+ Applying a tagging rule is session-only in Papra and is not exposed as an MCP tool.
279
+
280
+ ### Custom Properties
281
+
282
+ | Tool | Description |
283
+ |------|-------------|
284
+ | `papra_list_custom_properties` | List all custom property definitions |
285
+ | `papra_get_custom_property` | Get a custom property definition |
286
+ | `papra_create_custom_property` | Create a custom property definition |
287
+ | `papra_update_custom_property` | Update name, description, or replace options |
288
+ | `papra_delete_custom_property` | Delete a definition and its values (**destructive**) |
289
+ | `papra_list_document_custom_properties` | List the properties set on a document |
290
+ | `papra_set_document_custom_property` | Replace a property value on a document |
291
+ | `papra_clear_document_custom_property` | Clear a property value from a document |
292
+
293
+ Custom properties support the types `text`, `number`, `date`, `boolean`, `select`, `multi_select`, `user_relation`, and `document_relation`. They need the API-key permissions listed above. Creating a select or multi-select definition requires a non-empty list of option names. Updating options requires the current or new definition `name` plus full `{id, name}` objects for retained options and `{name}` objects for new options; omitted existing options are removed. Papra 0.3.0 otherwise fails internally while applying an options-only update, so the adapter rejects that incomplete payload before HTTP. An option list cannot be empty because select definitions require at least one option. Id-less entries always create new options with fresh IDs, so updates containing them are not idempotent; fetch the definition and use the returned IDs in subsequent replacement payloads.
294
+
295
+ Select takes one `cpso_` option ID. Multi-select, user relation, and document relation take arrays of `cpso_`, `usr_`, and `doc_` IDs respectively, never a scalar. Setting a value replaces all previous values: omitted IDs are removed, and `[]` clears a multi-valued property. Use `papra_clear_document_custom_property` to remove a property value of any type.
296
+
297
+ ## Uploading documents
298
+
299
+ `papra_create_document` takes strictly valid base64 in `file_content`. Plain text is **rejected** rather than silently decoded into corrupt bytes — use `papra_create_text_document` for text.
300
+
301
+ `file_name` is required and should include the extension. Papra derives the document name and the file type from it, so `invoice-2026-01.pdf` produces a usable document where `upload` does not. `content_type` is optional and is guessed from the file name when omitted.
302
+
303
+ ## Reading documents
304
+
305
+ `papra_get_document_content` returns:
306
+
307
+ - **Text** (`text/*`, JSON, XML) decoded directly. Decoding is strict, so a binary file mislabelled as `text/plain` falls back to base64 instead of returning replacement characters.
308
+ - **PDFs** as extracted plain text via [PyMuPDF](https://pymupdf.readthedocs.io/), so models can read them without decoding binary data. Detection works both via the `application/pdf` content type and via the `%PDF` magic bytes, which covers servers that return `application/octet-stream`. If no text can be extracted (scanned documents without OCR, image-only or corrupt PDFs), it falls back to base64.
309
+ - **Other binary** as base64-encoded JSON together with the content type.
310
+
311
+ Text above `PAPRA_MAX_CONTENT_BYTES` is truncated with an explicit marker. Binary content above the limit is refused with an error, since a truncated base64 blob would be corrupt.
312
+
313
+ ## Error handling
314
+
315
+ Failed calls raise a `ToolError`, so the MCP result is flagged with `isError` and a model cannot mistake an API error for a successful response. Messages include the HTTP status and Papra's own error text.
316
+
317
+ ## Releasing
318
+
319
+ 1. Bump `version` in `pyproject.toml` and merge to `main`.
320
+ 2. Optional dry run: start the **Release** workflow manually to upload to TestPyPI.
321
+ 3. Publish a GitHub release tagged `vX.Y.Z` matching that version; the workflow uploads it to PyPI.
322
+
323
+ ## License
324
+
325
+ [Apache-2.0](https://github.com/Rigare/papra-mcp/blob/main/LICENSE)