@retiform/paperless-mcp 0.0.0-stage → 2.3.1

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.
Files changed (74) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +1004 -2
  3. package/build/api/PaperlessAPI.d.ts +63 -0
  4. package/build/api/PaperlessAPI.js +405 -0
  5. package/build/api/documentEnhancer.d.ts +24 -0
  6. package/build/api/documentEnhancer.js +111 -0
  7. package/build/api/documentEnhancer.test.d.ts +1 -0
  8. package/build/api/documentEnhancer.test.js +80 -0
  9. package/build/api/types.d.ts +203 -0
  10. package/build/api/types.js +15 -0
  11. package/build/api/utils.d.ts +16 -0
  12. package/build/api/utils.js +29 -0
  13. package/build/index.d.ts +2 -0
  14. package/build/index.js +189 -0
  15. package/build/resources/documents.d.ts +7 -0
  16. package/build/resources/documents.js +119 -0
  17. package/build/resources/documents.test.d.ts +1 -0
  18. package/build/resources/documents.test.js +124 -0
  19. package/build/server.d.ts +24 -0
  20. package/build/server.js +70 -0
  21. package/build/server.test.d.ts +1 -0
  22. package/build/server.test.js +54 -0
  23. package/build/test/mocks/paperlessApi.d.ts +4 -0
  24. package/build/test/mocks/paperlessApi.js +33 -0
  25. package/build/tools/boundedContent.test.d.ts +1 -0
  26. package/build/tools/boundedContent.test.js +544 -0
  27. package/build/tools/correspondents.d.ts +3 -0
  28. package/build/tools/correspondents.js +149 -0
  29. package/build/tools/customFields.d.ts +3 -0
  30. package/build/tools/customFields.js +142 -0
  31. package/build/tools/documentTypes.d.ts +3 -0
  32. package/build/tools/documentTypes.js +143 -0
  33. package/build/tools/documents.d.ts +134 -0
  34. package/build/tools/documents.js +814 -0
  35. package/build/tools/documents.test.d.ts +1 -0
  36. package/build/tools/documents.test.js +658 -0
  37. package/build/tools/mail.d.ts +3 -0
  38. package/build/tools/mail.js +187 -0
  39. package/build/tools/mail.test.d.ts +1 -0
  40. package/build/tools/mail.test.js +212 -0
  41. package/build/tools/notes.d.ts +3 -0
  42. package/build/tools/notes.js +55 -0
  43. package/build/tools/notes.test.d.ts +1 -0
  44. package/build/tools/notes.test.js +177 -0
  45. package/build/tools/schemaCompat.test.d.ts +1 -0
  46. package/build/tools/schemaCompat.test.js +59 -0
  47. package/build/tools/tags.d.ts +3 -0
  48. package/build/tools/tags.js +143 -0
  49. package/build/tools/utils/descriptions.d.ts +1 -0
  50. package/build/tools/utils/descriptions.js +4 -0
  51. package/build/tools/utils/documentQuery.d.ts +71 -0
  52. package/build/tools/utils/documentQuery.js +270 -0
  53. package/build/tools/utils/empty.d.ts +2 -0
  54. package/build/tools/utils/empty.js +7 -0
  55. package/build/tools/utils/matchingAlgorithm.d.ts +2 -0
  56. package/build/tools/utils/matchingAlgorithm.js +15 -0
  57. package/build/tools/utils/middlewares.d.ts +3 -0
  58. package/build/tools/utils/middlewares.js +31 -0
  59. package/build/tools/utils/monetary.d.ts +5 -0
  60. package/build/tools/utils/monetary.js +34 -0
  61. package/build/tools/utils/monetary.test.d.ts +1 -0
  62. package/build/tools/utils/monetary.test.js +25 -0
  63. package/build/tools/utils/queryString.d.ts +1 -0
  64. package/build/tools/utils/queryString.js +12 -0
  65. package/build/tools/utils/resourceUri.d.ts +29 -0
  66. package/build/tools/utils/resourceUri.js +37 -0
  67. package/build/tools/utils/resourceUri.test.d.ts +1 -0
  68. package/build/tools/utils/resourceUri.test.js +50 -0
  69. package/build/tools/utils/selectFields.d.ts +13 -0
  70. package/build/tools/utils/selectFields.js +91 -0
  71. package/build/tools/utils/selectFields.test.d.ts +1 -0
  72. package/build/tools/utils/selectFields.test.js +164 -0
  73. package/package.json +59 -4
  74. package/paperless-mcp.dxt +0 -0
package/README.md CHANGED
@@ -1,3 +1,1005 @@
1
- # Temporary Holding Version
1
+ <!-- [![MseeP.ai Security Assessment Badge](https://mseep.net/pr/nloui-paperless-mcp-badge.png)](https://mseep.ai/app/nloui-paperless-mcp) -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # Paperless-NGX MCP Server
4
+
5
+ ![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/retiform-labs/paperless-mcp?utm_source=oss&utm_medium=github&utm_campaign=retiform-labs%2Fpaperless-mcp&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews)
6
+
7
+ An MCP (Model Context Protocol) server for interacting with a Paperless-NGX API server. This server provides tools for managing documents, tags, correspondents, and document types in your Paperless-NGX instance.
8
+
9
+ ## About this fork
10
+
11
+ This is a fork of [baruchiro/paperless-mcp](https://github.com/baruchiro/paperless-mcp)
12
+ (ISC license, (c) Baruch Odem), maintained by **Retiform Labs** and published as
13
+ **`@retiform/paperless-mcp`**. Fork point: tag `upstream-v2.2.1`.
14
+
15
+ Upstream returns whole documents. That is fine for a human clicking through a UI
16
+ and crippling for an agent: a single `get_document_content` call on a
17
+ several-hundred-page PDF can consume an entire context window, and there is no
18
+ way to ask for a slice. This fork adds bounded reads:
19
+
20
+ - **Ranged `get_document_content`** -- `offset` + `max_chars` windows, with honest
21
+ `content_length` / `truncated` / `has_more` metadata.
22
+ - **`search_passages`** -- full-text hits returned as bounded passages around the
23
+ actual match, with score and offset, so an agent can locate and then page into
24
+ the exact region it needs.
25
+ - **An inline budget** -- `PAPERLESS_MCP_MAX_INLINE_CHARS` makes an oversized
26
+ request fail loudly instead of silently flooding the caller.
27
+ - **`content_length`** on list/query/get results, so a client can size a read
28
+ before making it.
29
+ - **Query resilience** -- an apostrophe in a search query is retried sanitized
30
+ instead of returning a hard 400.
31
+
32
+ We also fix the build so it is idempotent (`tsc` no longer consumes its own
33
+ `.d.ts` output on a rebuild). The bounded-read work is offered upstream by pull
34
+ request; it is published here in the meantime because agentic clients need it now.
35
+
36
+ ## Quick Start
37
+
38
+ [![Install MCP Server](https://cursor.com/deeplink/mcp-install-light.svg)](https://cursor.com/install-mcp?name=paperless&config=eyJjb21tYW5kIjoibnB4IC15IEByZXRpZm9ybS9wYXBlcmxlc3MtbWNwQGxhdGVzdCIsImVudiI6eyJQQVBFUkxFU1NfVVJMIjoiaHR0cDovL3lvdXItcGFwZXJsZXNzLWluc3RhbmNlOjgwMDAiLCJQQVBFUkxFU1NfQVBJX0tFWSI6InlvdXItYXBpLXRva2VuIn19)
39
+
40
+ ### Installation
41
+
42
+ Add these to your MCP config file:
43
+
44
+ // STDIO mode (recommended for local or CLI use)
45
+ ```json
46
+ "paperless": {
47
+ "command": "npx",
48
+ "args": [
49
+ "-y",
50
+ "@retiform/paperless-mcp@latest",
51
+ ],
52
+ "env": {
53
+ "PAPERLESS_URL": "http://your-paperless-instance:8000",
54
+ "PAPERLESS_API_KEY": "your-api-token",
55
+ "PAPERLESS_PUBLIC_URL": "https://your-public-domain.com"
56
+ }
57
+ }
58
+ ```
59
+
60
+ // HTTP mode (recommended for Docker or remote use)
61
+ ```json
62
+ "paperless": {
63
+ "command": "docker",
64
+ "args": [
65
+ "run",
66
+ "-i",
67
+ "--rm",
68
+ "ghcr.io/retiform-labs/paperless-mcp:latest",
69
+ ],
70
+ "env": {
71
+ "PAPERLESS_URL": "http://your-paperless-instance:8000",
72
+ "PAPERLESS_API_KEY": "your-api-token",
73
+ "PAPERLESS_PUBLIC_URL": "https://your-public-domain.com"
74
+ }
75
+ }
76
+ ```
77
+
78
+ 3. Get your API token:
79
+ 1. Log into your Paperless-NGX instance
80
+ 2. Click your username in the top right
81
+ 3. Select "My Profile"
82
+ 4. Click the circular arrow button to generate a new token
83
+
84
+ 4. Replace the placeholders in your MCP config:
85
+ - `http://your-paperless-instance:8000` with your Paperless-NGX URL
86
+ - `your-api-token` with the token you just generated
87
+ - `https://your-public-domain.com` with your public Paperless-NGX URL (optional, falls back to PAPERLESS_URL)
88
+
89
+ ### Environment Variables
90
+
91
+ | Variable | Required | Default | Description |
92
+ |---|---|---|---|
93
+ | `PAPERLESS_URL` | Yes | — | Base URL of your Paperless-NGX instance |
94
+ | `PAPERLESS_API_KEY` | Yes | — | API token from your Paperless-NGX profile |
95
+ | `PAPERLESS_PUBLIC_URL` | No | `PAPERLESS_URL` | Public-facing URL for document links |
96
+ | `PAPERLESS_API_VERSION` | No | `9` | Paperless-ngx REST API version. `9` works on Paperless-ngx v2.x (recent) and v3.x. Paperless-ngx v3.0.0 dropped support for versions below `9`, so older defaults now return HTTP 406. If you see HTTP 406 errors, set this to a version your server supports. |
97
+ | `PAPERLESS_MCP_UPLOAD_PATHS` | No | — | Colon-separated list of allowed directories for `file_path` uploads. **Recommended for security.** Example: `/var/uploads:/tmp/scans` |
98
+ | `PAPERLESS_MCP_MAX_INLINE_CHARS` | No | `50000` | Hard cap on characters a single tool response may inline. Requests above the budget fail with the document size and a hint toward bounded reads instead of silently truncating or flooding context. |
99
+
100
+ That's it! Now you can ask Claude to help you manage your Paperless-NGX documents.
101
+
102
+ ### Example Usage
103
+
104
+ Here are some things you can ask Claude to do:
105
+
106
+ - "Show me all documents tagged as 'Invoice'"
107
+ - "Search for documents containing 'tax return'"
108
+ - "Create a new tag called 'Receipts' with color #FF0000"
109
+ - "Download document #123"
110
+ - "List all correspondents"
111
+ - "Create a new document type called 'Bank Statement'"
112
+
113
+ ## Available Tools
114
+
115
+ ### Document Operations
116
+
117
+ #### list_documents
118
+ Get a paginated list of documents with simple filters. Use this for straightforward listing tasks. For full-text queries, structured custom field filtering, or advanced Paperless filters, use `query_documents`.
119
+
120
+ Parameters:
121
+ - page (optional): Page number
122
+ - page_size (optional): Number of documents per page
123
+ - search (optional): Simple Paperless search term
124
+ - correspondent (optional): Correspondent ID
125
+ - document_type (optional): Document type ID
126
+ - tag (optional): Tag ID
127
+ - storage_path (optional): Storage path ID
128
+ - created__date__gte (optional): Created date on or after YYYY-MM-DD
129
+ - created__date__lte (optional): Created date on or before YYYY-MM-DD
130
+ - ordering (optional): Paperless ordering field
131
+ - archive_serial_number (optional): Archive serial number
132
+ - archive_serial_number__isnull (optional): Whether the archive serial number is empty
133
+ - custom_field_query (optional): Raw JSON-encoded Paperless custom field query string
134
+ - custom_fields__icontains (optional): Case-insensitive substring match across custom field values
135
+
136
+ ```typescript
137
+ list_documents({
138
+ page: 1,
139
+ page_size: 25
140
+ })
141
+ ```
142
+
143
+ #### query_documents
144
+ Canonical document query tool. Supports full-text querying, simple Paperless search, custom field filters, and documented `/api/documents/` Paperless query parameters.
145
+
146
+ Parameters:
147
+ - page (optional): Page number
148
+ - page_size (optional): Number of documents per page
149
+ - ordering (optional): Paperless ordering field
150
+ - query (optional): Full-text query string
151
+ - search (optional): Simple Paperless search term
152
+ - more_like_id (optional): Find documents similar to this document ID
153
+ - correspondent (optional): Correspondent ID
154
+ - document_type (optional): Document type ID
155
+ - tag (optional): Tag ID
156
+ - storage_path (optional): Storage path ID
157
+ - created__date__gte (optional): Created date on or after YYYY-MM-DD
158
+ - created__date__lte (optional): Created date on or before YYYY-MM-DD
159
+ - custom_field_query (optional): Structured Paperless custom field query using `[field_name_or_id, operator, value]` leaves or `["AND" | "OR", [clause1, clause2]]` groups
160
+ - paperless_filters (optional): Additional documented `/api/documents/` Paperless query parameters, passed as key/value pairs
161
+
162
+ ```typescript
163
+ // Full-text query
164
+ query_documents({
165
+ query: "invoice 2024"
166
+ })
167
+
168
+ // Simple search term
169
+ query_documents({
170
+ search: "acme"
171
+ })
172
+
173
+ // Custom field exact match
174
+ query_documents({
175
+ custom_field_query: ["Invoice Number", "exact", "12345"]
176
+ })
177
+
178
+ // Custom field empty
179
+ query_documents({
180
+ custom_field_query: ["OR", [
181
+ ["Invoice Number", "isnull", true],
182
+ ["Invoice Number", "exact", ""]
183
+ ]]
184
+ })
185
+
186
+ // Custom field missing
187
+ query_documents({
188
+ custom_field_query: ["Invoice Number", "exists", false]
189
+ })
190
+
191
+ // Combined filters
192
+ query_documents({
193
+ query: "invoice",
194
+ tag: 5,
195
+ created__date__gte: "2024-01-01",
196
+ custom_field_query: ["Invoice Number", "exists", true]
197
+ })
198
+
199
+ // One documented Paperless filter that is not a first-class argument
200
+ query_documents({
201
+ paperless_filters: {
202
+ id__in: [101, 202, 303]
203
+ }
204
+ })
205
+ ```
206
+
207
+ #### get_document
208
+ Get a specific document by ID.
209
+
210
+ Parameters:
211
+ - id: Document ID
212
+
213
+ ```typescript
214
+ get_document({
215
+ id: 123
216
+ })
217
+ ```
218
+
219
+ #### search_documents
220
+ Deprecated compatibility wrapper for full-text search. Prefer `query_documents({ query: ... })` for new integrations.
221
+
222
+ Parameters:
223
+ - query: Search query string
224
+
225
+ ```typescript
226
+ search_documents({
227
+ query: "invoice 2024"
228
+ })
229
+ ```
230
+
231
+ #### get_document_content
232
+ Get the text content of a document by ID **in bounded windows**. Returns at most `max_chars` characters (default 8000) starting at `offset`, plus pagination metadata so callers can page through long documents without flooding context.
233
+
234
+ Parameters:
235
+ - id: Document ID
236
+ - offset (optional): Character offset to start reading from (default 0)
237
+ - max_chars (optional): Maximum characters to return (default 8000)
238
+
239
+ ```typescript
240
+ get_document_content({ id: 123 })
241
+ // → { content: "<first 8000 chars>", offset: 0, content_length: 726573, returned_chars: 8000, truncated: true, has_more: true }
242
+
243
+ get_document_content({ id: 123, offset: 8000, max_chars: 8000 })
244
+ // → next window
245
+ ```
246
+
247
+ Requests above the inline budget (`PAPERLESS_MCP_MAX_INLINE_CHARS`, default 50000) fail with the document size and a hint toward offset reads or the `download_document` resource — never a silent slice, never an unbounded return. The response always carries `content_length`, `truncated`, and `has_more` so callers can page deterministically.
248
+
249
+ #### search_passages
250
+ Search documents full-text and return **bounded text passages around each hit** instead of whole documents. Each window is anchored on the server's own highlighted phrase (falling back to the first verbatim term occurrence, then the document head), so the returned passage contains the actual hit even when the search index stemmed a word variant that does not appear verbatim in the stored text. Returns the document id, title, score, offset, `content_length`, and the highlighted snippet.
251
+
252
+ Queries that the server rejects with an opaque HTTP 400 (django-watson rejects some syntactically valid queries, notably those containing apostrophes) are retried once with a defensively rewritten query — apostrophes and stray quotes removed; structured filter values are never rewritten. Responses from a rewritten retry carry `query_sanitized: true`. Persistent failures throw a structured error naming every attempted query.
253
+
254
+ Parameters:
255
+ - query: Search query string (same syntax as `query_documents`)
256
+ - window (optional): Characters per passage (default 800, range 200–4000)
257
+ - max_passages (optional): Maximum passages to return (default 5, cap 20)
258
+
259
+ ```typescript
260
+ search_passages({ query: "invoice 2024" })
261
+ // → { query: "invoice 2024", total_hits: 3, passages: [{ id, title, score, highlights, passage, offset, content_length }, ...] }
262
+
263
+ search_passages({ query: "God's will" })
264
+ // → { ..., query_sanitized: true, ... } // apostrophe stripped on retry after a 400
265
+ ```
266
+
267
+ Use this to locate and skim evidence across many documents in a single call; page further into a hit with `get_document_content` offsets. Standard `query_documents` filters (`correspondent`, `tag`, `document_type`, `storage_path`, date ranges, `paperless_filters`) are accepted and behave identically. Note: `total_hits` reflects the server's OR-expanded match count and may exceed the number of top-ranked passages returned.
268
+
269
+ #### download_document
270
+ Download a document file by ID.
271
+
272
+ Parameters:
273
+ - id: Document ID
274
+ - original (optional): If true, downloads original file instead of archived version
275
+
276
+ ```typescript
277
+ download_document({
278
+ id: 123,
279
+ original: false
280
+ })
281
+ ```
282
+
283
+ #### get_document_thumbnail
284
+ Get a document thumbnail (image preview) by ID. Returns the thumbnail as a base64-encoded WebP image resource.
285
+
286
+ Parameters:
287
+ - id: Document ID
288
+
289
+ ```typescript
290
+ get_document_thumbnail({
291
+ id: 123
292
+ })
293
+ ```
294
+
295
+ #### bulk_edit_documents
296
+ Perform bulk operations on multiple documents.
297
+
298
+ Parameters:
299
+ - documents: Array of document IDs
300
+ - method: One of:
301
+ - set_correspondent: Set correspondent for documents
302
+ - set_document_type: Set document type for documents
303
+ - set_storage_path: Set storage path for documents
304
+ - add_tag: Add a tag to documents
305
+ - remove_tag: Remove a tag from documents
306
+ - modify_tags: Add and/or remove multiple tags
307
+ - delete: Delete documents
308
+ - reprocess: Reprocess documents
309
+ - set_permissions: Set document permissions
310
+ - merge: Merge multiple documents
311
+ - split: Split a document into multiple documents
312
+ - rotate: Rotate document pages
313
+ - delete_pages: Delete specific pages from a document
314
+ - Additional parameters based on method:
315
+ - correspondent: ID for set_correspondent
316
+ - document_type: ID for set_document_type
317
+ - storage_path: ID for set_storage_path
318
+ - tag: ID for add_tag/remove_tag
319
+ - add_tags: Array of tag IDs for modify_tags
320
+ - remove_tags: Array of tag IDs for modify_tags
321
+ - set_permissions: Object for set_permissions with view/change users and groups (`{"view": {"users": [], "groups": []}, "change": {...}}`). Omitted actions/lists are left untouched
322
+ - owner: User ID (or null to remove) for set_permissions. Unless merge is true, omitting owner clears the current owner
323
+ - merge: Boolean for set_permissions — true adds to existing permissions and keeps the owner; false (default) replaces the listed users/groups
324
+ - metadata_document_id: ID for merge to specify metadata source
325
+ - delete_originals: Boolean for merge/split
326
+ - pages: String for split "[1,2-3,4,5-7]" or delete_pages "[2,3,4]"
327
+ - degrees: Number for rotate (90, 180, or 270)
328
+
329
+ Examples:
330
+ ```typescript
331
+ // Add a tag to multiple documents
332
+ bulk_edit_documents({
333
+ documents: [1, 2, 3],
334
+ method: "add_tag",
335
+ tag: 5
336
+ })
337
+
338
+ // Set correspondent and document type
339
+ bulk_edit_documents({
340
+ documents: [4, 5],
341
+ method: "set_correspondent",
342
+ correspondent: 2
343
+ })
344
+
345
+ // Merge documents
346
+ bulk_edit_documents({
347
+ documents: [6, 7, 8],
348
+ method: "merge",
349
+ metadata_document_id: 6,
350
+ delete_originals: true
351
+ })
352
+
353
+ // Split document into parts
354
+ bulk_edit_documents({
355
+ documents: [9],
356
+ method: "split",
357
+ pages: "[1-2,3-4,5]"
358
+ })
359
+
360
+ // Modify multiple tags at once
361
+ bulk_edit_documents({
362
+ documents: [10, 11],
363
+ method: "modify_tags",
364
+ add_tags: [1, 2],
365
+ remove_tags: [3, 4]
366
+ })
367
+
368
+ // Modify custom fields
369
+ bulk_edit_documents({
370
+ documents: [12, 13],
371
+ method: "modify_custom_fields",
372
+ add_custom_fields: [
373
+ { field: 2, value: "year" }
374
+ ],
375
+ remove_custom_fields: []
376
+ })
377
+
378
+ // Set an empty custom field value, e.g. a date field used as a pending marker
379
+ bulk_edit_documents({
380
+ documents: [14],
381
+ method: "modify_custom_fields",
382
+ add_custom_fields: [
383
+ { field: 9, value: "" }
384
+ ],
385
+ remove_custom_fields: []
386
+ })
387
+ ```
388
+
389
+ #### post_document
390
+ Upload a new document to Paperless-NGX.
391
+
392
+ **Two upload modes:**
393
+
394
+ 1. **Base64 mode** (traditional): Provide `file` (base64-encoded content) + `filename`
395
+ 2. **Filesystem mode** (efficient): Provide `file_path` (absolute path on server)
396
+
397
+ **Security Note:** When using `file_path`, set the `PAPERLESS_MCP_UPLOAD_PATHS` environment variable (colon-separated list of allowed directories) to restrict uploads to specific locations. Without this, any file on the server's filesystem could be uploaded.
398
+
399
+ Parameters:
400
+ - file (optional): Base64 encoded file content. Either `file` or `file_path` required.
401
+ - file_path (optional): Absolute path to file on server's filesystem. Either `file` or `file_path` required.
402
+ - filename (optional): Name of the file. Required with `file`, optional with `file_path` (derives from path).
403
+ - title (optional): Title for the document
404
+ - created (optional): DateTime when the document was created (e.g. "2024-01-19" or "2024-01-19 06:15:00+02:00")
405
+ - correspondent (optional): ID of a correspondent
406
+ - document_type (optional): ID of a document type
407
+ - storage_path (optional): ID of a storage path
408
+ - tags (optional): Array of tag IDs
409
+ - archive_serial_number (optional): Archive serial number
410
+ - custom_fields (optional): Array of custom field IDs
411
+
412
+ **File size limit:** 100MB for both modes
413
+
414
+ ```typescript
415
+ // Base64 mode (traditional)
416
+ post_document({
417
+ file: "base64_encoded_content",
418
+ filename: "invoice.pdf",
419
+ title: "January Invoice",
420
+ created: "2024-01-19",
421
+ correspondent: 1,
422
+ document_type: 2,
423
+ tags: [1, 3],
424
+ archive_serial_number: "2024-001",
425
+ custom_fields: [1, 2]
426
+ })
427
+
428
+ // Filesystem mode (more efficient for large files)
429
+ post_document({
430
+ file_path: "/var/uploads/invoice.pdf",
431
+ title: "January Invoice",
432
+ correspondent: 1,
433
+ document_type: 2,
434
+ tags: [1, 3]
435
+ })
436
+ ```
437
+
438
+ ### Document Notes
439
+
440
+ #### list_document_notes
441
+ List all notes attached to a document.
442
+
443
+ Parameters:
444
+ - id: Document ID
445
+
446
+ ```typescript
447
+ list_document_notes({
448
+ id: 123
449
+ })
450
+ ```
451
+
452
+ #### create_document_note
453
+ Add a note to a document. Returns the document's full list of notes.
454
+
455
+ Parameters:
456
+ - id: Document ID
457
+ - note: The note text to add
458
+
459
+ ```typescript
460
+ create_document_note({
461
+ id: 123,
462
+ note: "Invoice paid on 2026-06-30 from Commerzbank account."
463
+ })
464
+ ```
465
+
466
+ #### delete_document_note
467
+ ⚠️ Delete a single note from a document by its note ID. This operation is irreversible.
468
+
469
+ Parameters:
470
+ - id: Document ID
471
+ - note_id: The ID of the note to delete
472
+ - confirm: Must be `true` to confirm this destructive operation
473
+
474
+ ```typescript
475
+ delete_document_note({
476
+ id: 123,
477
+ note_id: 5,
478
+ confirm: true
479
+ })
480
+ ```
481
+
482
+ ### Tag Operations
483
+
484
+ #### list_tags
485
+ Get all tags.
486
+
487
+ ```typescript
488
+ list_tags()
489
+ ```
490
+
491
+ #### create_tag
492
+ Create a new tag.
493
+
494
+ Parameters:
495
+ - name: Tag name
496
+ - color (optional): Hex color code (e.g. "#ff0000")
497
+ - match (optional): Text pattern to match
498
+ - matching_algorithm (optional): Number between 0 and 6:
499
+ 0 - None
500
+ 1 - Any word
501
+ 2 - All words
502
+ 3 - Exact match
503
+ 4 - Regular expression
504
+ 5 - Fuzzy word
505
+ 6 - Automatic
506
+
507
+ ```typescript
508
+ create_tag({
509
+ name: "Invoice",
510
+ color: "#ff0000",
511
+ match: "invoice",
512
+ matching_algorithm: 5
513
+ })
514
+ ```
515
+
516
+ ### Correspondent Operations
517
+
518
+ #### list_correspondents
519
+ Get all correspondents.
520
+
521
+ ```typescript
522
+ list_correspondents()
523
+ ```
524
+
525
+ #### create_correspondent
526
+ Create a new correspondent.
527
+
528
+ Parameters:
529
+ - name: Correspondent name
530
+ - match (optional): Text pattern to match
531
+ - matching_algorithm (optional): Number between 0 and 6:
532
+ 0 - None
533
+ 1 - Any word
534
+ 2 - All words
535
+ 3 - Exact match
536
+ 4 - Regular expression
537
+ 5 - Fuzzy word
538
+ 6 - Automatic
539
+
540
+ ```typescript
541
+ create_correspondent({
542
+ name: "ACME Corp",
543
+ match: "ACME",
544
+ matching_algorithm: 5
545
+ })
546
+ ```
547
+
548
+ ### Document Type Operations
549
+
550
+ #### list_document_types
551
+ Get all document types.
552
+
553
+ ```typescript
554
+ list_document_types()
555
+ ```
556
+
557
+ #### create_document_type
558
+ Create a new document type.
559
+
560
+ Parameters:
561
+ - name: Document type name
562
+ - match (optional): Text pattern to match
563
+ - matching_algorithm (optional): Number between 0 and 6:
564
+ 0 - None
565
+ 1 - Any word
566
+ 2 - All words
567
+ 3 - Exact match
568
+ 4 - Regular expression
569
+ 5 - Fuzzy word
570
+ 6 - Automatic
571
+
572
+ ```typescript
573
+ create_document_type({
574
+ name: "Invoice",
575
+ match: "invoice total amount due",
576
+ matching_algorithm: 1
577
+ })
578
+ ```
579
+
580
+ ### Custom Field Operations
581
+
582
+ #### list_custom_fields
583
+ Get all custom fields.
584
+
585
+ ```typescript
586
+ list_custom_fields()
587
+ ```
588
+
589
+ #### get_custom_field
590
+ Get a specific custom field by ID.
591
+
592
+ Parameters:
593
+ - id: Custom field ID
594
+
595
+ ```typescript
596
+ get_custom_field({
597
+ id: 1
598
+ })
599
+ ```
600
+
601
+ #### create_custom_field
602
+ Create a new custom field.
603
+
604
+ Parameters:
605
+ - name: Custom field name
606
+ - data_type: One of "string", "url", "date", "boolean", "integer", "float", "monetary", "documentlink", "select"
607
+ - extra_data (optional): Extra data for the custom field, such as select options
608
+
609
+ ```typescript
610
+ create_custom_field({
611
+ name: "Invoice Number",
612
+ data_type: "string"
613
+ })
614
+ ```
615
+
616
+ #### update_custom_field
617
+ Update an existing custom field.
618
+
619
+ Parameters:
620
+ - id: Custom field ID
621
+ - name (optional): New custom field name
622
+ - data_type (optional): New data type
623
+ - extra_data (optional): Extra data for the custom field
624
+
625
+ ```typescript
626
+ update_custom_field({
627
+ id: 1,
628
+ name: "Updated Invoice Number",
629
+ data_type: "string"
630
+ })
631
+ ```
632
+
633
+ #### delete_custom_field
634
+ Delete a custom field.
635
+
636
+ Parameters:
637
+ - id: Custom field ID
638
+
639
+ ```typescript
640
+ delete_custom_field({
641
+ id: 1
642
+ })
643
+ ```
644
+
645
+ #### bulk_edit_custom_fields
646
+ Perform bulk operations on multiple custom fields.
647
+
648
+ Parameters:
649
+ - custom_fields: Array of custom field IDs
650
+ - operation: One of "delete"
651
+
652
+ ```typescript
653
+ bulk_edit_custom_fields({
654
+ custom_fields: [1, 2, 3],
655
+ operation: "delete"
656
+ })
657
+ ```
658
+
659
+ ### Mail Operations
660
+
661
+ Tools for managing Paperless mail accounts and the mail rules that drive
662
+ automatic email ingestion. Account passwords/tokens are never exposed: they are
663
+ redacted from every tool response.
664
+
665
+ #### list_mail_accounts
666
+ List mail accounts so you can pick the account ID needed when creating a mail
667
+ rule. Passwords are redacted.
668
+
669
+ Parameters:
670
+ - page (optional): Page number
671
+ - page_size (optional): Number of results per page
672
+
673
+ ```typescript
674
+ list_mail_accounts()
675
+ ```
676
+
677
+ #### get_mail_account
678
+ Get a single mail account by ID. Password/token fields are redacted.
679
+
680
+ Parameters:
681
+ - id: Mail account ID
682
+
683
+ ```typescript
684
+ get_mail_account({
685
+ id: 1
686
+ })
687
+ ```
688
+
689
+ #### process_mail_account
690
+ Manually trigger Paperless mail processing for one account. This can consume
691
+ matching mails according to the account's enabled mail rules.
692
+
693
+ Parameters:
694
+ - id: Mail account ID
695
+
696
+ ```typescript
697
+ process_mail_account({
698
+ id: 1
699
+ })
700
+ ```
701
+
702
+ #### list_mail_rules
703
+ List mail rules with optional pagination.
704
+
705
+ Parameters:
706
+ - page (optional): Page number
707
+ - page_size (optional): Number of results per page
708
+
709
+ ```typescript
710
+ list_mail_rules()
711
+ ```
712
+
713
+ #### get_mail_rule
714
+ Get a single mail rule by ID.
715
+
716
+ Parameters:
717
+ - id: Mail rule ID
718
+
719
+ ```typescript
720
+ get_mail_rule({
721
+ id: 1
722
+ })
723
+ ```
724
+
725
+ #### create_mail_rule
726
+ Create a mail rule. Use `list_mail_accounts` first to choose the account.
727
+
728
+ Required parameters:
729
+ - name: Rule name
730
+ - account: Mail account ID
731
+ - folder: IMAP folder to scan (e.g. "INBOX")
732
+
733
+ Common optional parameters:
734
+ - enabled (default true): Whether the rule is active
735
+ - filter_from / filter_to / filter_subject / filter_body: Match incoming mail
736
+ - maximum_age: Only process mail newer than this many days
737
+ - action: 1=Delete, 2=Move to folder, 3=Mark as read, 4=Flag, 5=Tag
738
+ - action_parameter: Target folder/tag for the chosen action
739
+ - assign_title_from: 1=Subject, 2=Attachment filename, 3=Do not assign
740
+ - assign_tags / assign_correspondent / assign_document_type: Metadata to apply
741
+ - assign_correspondent_from: 1=None, 2=Mail address, 3=Sender name, 4=Use assign_correspondent
742
+ - attachment_type: 1=Attachments only, 2=All files incl. inline
743
+ - consumption_scope: 1=Attachments only, 2=Full mail as .eml, 3=Both
744
+ - pdf_layout: 0=System default, 1=Text+HTML, 2=HTML+text, 3=HTML only, 4=Text only
745
+
746
+ ```typescript
747
+ create_mail_rule({
748
+ name: "Invoices",
749
+ account: 1,
750
+ folder: "INBOX",
751
+ filter_subject: "invoice",
752
+ action: 3,
753
+ attachment_type: 1
754
+ })
755
+ ```
756
+
757
+ #### update_mail_rule
758
+ Patch an existing mail rule. Only the fields you supply are changed.
759
+
760
+ Parameters:
761
+ - id: Mail rule ID
762
+ - ...any of the `create_mail_rule` fields to update
763
+
764
+ ```typescript
765
+ update_mail_rule({
766
+ id: 1,
767
+ enabled: false
768
+ })
769
+ ```
770
+
771
+ #### delete_mail_rule
772
+ Delete a mail rule. Requires an explicit confirmation flag. This changes future
773
+ mail ingestion behavior but does not delete any existing documents.
774
+
775
+ Parameters:
776
+ - id: Mail rule ID
777
+ - confirm: Must be `true` to confirm deletion
778
+
779
+ ```typescript
780
+ delete_mail_rule({
781
+ id: 1,
782
+ confirm: true
783
+ })
784
+ ```
785
+
786
+ ## Error Handling
787
+
788
+ The server will show clear error messages if:
789
+ - The Paperless-NGX URL or API token is incorrect
790
+ - The Paperless-NGX server is unreachable
791
+ - The requested operation fails
792
+ - The provided parameters are invalid
793
+
794
+ ## Testing
795
+
796
+ ### Unit tests
797
+
798
+ Run the unit test suite (no external dependencies required):
799
+
800
+ ```bash
801
+ npm test
802
+ ```
803
+
804
+ ### E2E tests
805
+
806
+ The E2E suite boots an empty Paperless-ngx instance, runs the compiled MCP server, and drives a deterministic serial scenario through `tools/call` requests — creating a tag, correspondent, and document type, uploading a PDF, then exercising list / get / search / download / thumbnail / bulk-edit on the same document. No LLM and no Paperless REST client outside MCP.
807
+
808
+ **Prerequisites:** Docker, Docker Compose, and `jq`.
809
+
810
+ ```bash
811
+ # 1. Build the MCP server
812
+ npm run build
813
+
814
+ # 2. Start Paperless-ngx
815
+ docker compose -f docker-compose.e2e.yml up -d
816
+
817
+ # 3. Wait for Paperless to be ready, then get a token
818
+ TOKEN=$(curl -s -X POST http://localhost:8000/api/token/ \
819
+ -H 'Content-Type: application/json' \
820
+ -d '{"username":"admin","password":"admin123"}' | jq -r '.token')
821
+
822
+ # 4. Start the MCP server
823
+ node build/index.js --http --port 3001 \
824
+ --baseUrl http://localhost:8000 --token "$TOKEN" &
825
+ MCP_PID=$!
826
+
827
+ # 5. Run the E2E tests
828
+ MCP_URL=http://localhost:3001/mcp \
829
+ PAPERLESS_URL=http://localhost:8000 \
830
+ PAPERLESS_TOKEN="$TOKEN" \
831
+ npm run test:e2e
832
+
833
+ # 6. Cleanup
834
+ kill "$MCP_PID"
835
+ docker compose -f docker-compose.e2e.yml down -v
836
+ ```
837
+
838
+ E2E tests also run automatically in CI on every pull request and push to `main`, covering both the `build/index.js` CLI and the published Docker image.
839
+
840
+ ## Development
841
+
842
+ Want to contribute or modify the server? Here's what you need to know:
843
+
844
+ 1. Clone the repository
845
+ 2. Install dependencies:
846
+ ```bash
847
+ npm install
848
+ ```
849
+
850
+ 3. Make your changes to server.js
851
+ 4. Test locally:
852
+ ```bash
853
+ node server.js http://localhost:8000 your-test-token
854
+ ```
855
+
856
+ The server is built with:
857
+ - [litemcp](https://github.com/wong2/litemcp): A TypeScript framework for building MCP servers
858
+ - [zod](https://github.com/colinhacks/zod): TypeScript-first schema validation
859
+
860
+ ## API Documentation
861
+
862
+ This MCP server implements endpoints from the Paperless-NGX REST API. For more details about the underlying API, see the [official documentation](https://docs.paperless-ngx.com/api/).
863
+
864
+ ## Running the MCP Server
865
+
866
+ The MCP server can be run in two modes:
867
+
868
+ ### 1. stdio (default)
869
+
870
+ This is the default mode. The server communicates over stdio, suitable for CLI and direct integrations.
871
+
872
+ ```
873
+ npm run start -- <baseUrl> <token>
874
+ ```
875
+
876
+ ### 2. HTTP (Streamable HTTP Transport)
877
+
878
+ To run the server as an HTTP service, use the `--http` flag. You can also specify the port with `--port` (default: 3000). This mode requires [Express](https://expressjs.com/) to be installed (it is included as a dependency).
879
+
880
+ ```
881
+ npm run start -- <baseUrl> <token> --http --port 3000
882
+ ```
883
+
884
+ - The MCP API will be available at `POST /mcp` on the specified port.
885
+ - Each request is handled statelessly, following the [StreamableHTTPServerTransport](https://github.com/modelcontextprotocol/typescript-sdk) pattern.
886
+ - GET and DELETE requests to `/mcp` will return 405 Method Not Allowed.
887
+
888
+ #### Per-request API token (HTTP/Docker mode)
889
+
890
+ In HTTP mode, clients authenticate by supplying a Paperless-NGX API token via the standard `Authorization` header:
891
+
892
+ ```
893
+ Authorization: Bearer <paperless-ngx-api-token>
894
+ ```
895
+
896
+ The token is passed straight through to Paperless-NGX, so each client's own Paperless permissions are enforced end-to-end. This lets a single server instance serve multiple users, each with their own token. The same behaviour applies to both `/mcp` and `/sse` endpoints.
897
+
898
+ > **⚠️ Breaking change in v2.0.0 — HTTP mode is now authenticated by default.**
899
+ >
900
+ > Previously, a request with no `Authorization` header silently fell back to the server-configured `PAPERLESS_API_KEY`, which left the HTTP endpoint open to anyone who could reach the port. As of v2.0.0, requests without a `Bearer` token are rejected with `401 Unauthorized`. The server token is **never** used for unauthenticated requests unless you explicitly opt in with `--no-auth`.
901
+
902
+ | Scenario | `--no-auth` off (default) | `--no-auth` on |
903
+ |---|---|---|
904
+ | Client sends `Authorization: Bearer <tok>` | `<tok>` (client-supplied) | `<tok>` (client-supplied) |
905
+ | No header, `PAPERLESS_API_KEY` / `--token` set | `401 Unauthorized` | server token |
906
+ | No header, no server token | `401 Unauthorized` | `401 Unauthorized` |
907
+
908
+ **Migrating from v1.x:** if you relied on the old fallback (a single shared `PAPERLESS_API_KEY` with clients that don't send a token), you have two options:
909
+
910
+ 1. **Recommended:** have each client send `Authorization: Bearer <paperless-token>`.
911
+ 2. **Restore the old behaviour** (trusted/local networks only): start the server with the `--no-auth` flag, e.g. append it to the Docker `command`/args or your CLI invocation. This requires a server token (`PAPERLESS_API_KEY` or `--token`) to be configured.
912
+
913
+ <details>
914
+ <summary>Docker Deployment</summary>
915
+
916
+ The MCP server can be deployed using Docker and Docker Compose. The Docker image automatically runs in HTTP mode with SSE (Server-Sent Events) support on port 3000.
917
+
918
+ ### Docker Compose Configuration
919
+
920
+ Create a `docker-compose.yml` file:
921
+
922
+ ```yaml
923
+ services:
924
+ paperless-mcp:
925
+ container_name: paperless-mcp
926
+ image: ghcr.io/retiform-labs/paperless-mcp:latest
927
+ environment:
928
+ - PAPERLESS_URL=http://your-paperless-ngx-server:8000
929
+ - PAPERLESS_API_KEY=your-paperless-api-key
930
+ - PAPERLESS_PUBLIC_URL=https://paperless-ngx.yourpublicurl.com
931
+ ports:
932
+ - "3000:3000"
933
+ restart: unless-stopped
934
+ ```
935
+
936
+ Then run:
937
+ ```bash
938
+ docker-compose up -d
939
+ ```
940
+
941
+ ### Using with Continue VS Code Extension
942
+
943
+ If you're using the [Continue VS Code extension](https://continue.dev/), you can configure it to use the Dockerized MCP server via SSE.
944
+
945
+ Create or edit `.continue/mcpServers/paperless-mcp.yaml` at your workspace root:
946
+
947
+ ```yaml
948
+ name: Paperless
949
+ version: 0.0.1
950
+ schema: v1
951
+ mcpServers:
952
+ - name: Paperless
953
+ type: sse
954
+ url: http://localhost:3000/sse
955
+ ```
956
+
957
+ **Notes:**
958
+ - Replace `localhost` with your Docker host's IP address or hostname if running on a remote server
959
+ - The Docker container handles authentication via environment variables, so no credentials are needed in the Continue config
960
+ - The SSE endpoint is available at `/sse` on the configured port (default: 3000)
961
+
962
+ </details>
963
+
964
+ # Credits
965
+
966
+ This project is a fork of [nloui/paperless-mcp](https://github.com/nloui/paperless-mcp). Many thanks to the original author for their work. Contributions and improvements may be returned upstream.
967
+
968
+ ## Debugging
969
+
970
+ To debug the MCP server in VS Code, use the following launch configuration:
971
+
972
+ ```json
973
+ {
974
+ "type": "node",
975
+ "request": "launch",
976
+ "name": "Debug Paperless MCP (HTTP, ts-node ESM)",
977
+ "program": "${workspaceFolder}/node_modules/ts-node/dist/bin.js",
978
+ "args": [
979
+ "--esm",
980
+ "src/index.ts",
981
+ "--http",
982
+ "--baseUrl",
983
+ "http://your-paperless-instance:8000",
984
+ "--token",
985
+ "your-api-token",
986
+ "--port",
987
+ "3002"
988
+ ],
989
+ "env": {
990
+ "NODE_OPTIONS": "--loader ts-node/esm",
991
+ },
992
+ "console": "integratedTerminal",
993
+ "skipFiles": [
994
+ "<node_internals>/**"
995
+ ]
996
+ }
997
+ ```
998
+
999
+ **Important:** Before debugging, uncomment the following line in `src/index.ts` (around line 175):
1000
+
1001
+ ```typescript
1002
+ // await new Promise((resolve) => setTimeout(resolve, 1000000));
1003
+ ```
1004
+
1005
+ This prevents the server from exiting immediately and allows you to set breakpoints and debug the code.