Fix documentlink custom field validation to accept arrays#39
Conversation
🦋 Changeset detectedLatest commit: 0a905d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
Co-authored-by: baruchiro <17686879+baruchiro@users.noreply.github.com>
Co-authored-by: baruchiro <17686879+baruchiro@users.noreply.github.com>
|
@copilot I'm not sure what supports your change, can you provide any documentation about accepted custom fields values structure? |
The change is based on the official Paperless-ngx REST API OpenAPI specification (version 6.0.0) in CustomFieldInstanceRequest schema (lines 5520-5540): CustomFieldInstanceRequest:
type: object
properties:
value:
oneOf:
- type: string
- type: integer
- type: number
format: double
- type: object
additionalProperties: {}
nullable: trueThe spec explicitly allows export interface CustomFieldInstanceRequest {
field: number;
value: string | number | boolean | object | null;
}The Zod validation was more restrictive than both the API spec and our own types, causing the issue. The fix aligns all three (API spec, TypeScript types, and Zod validation) to accept the same value types. |
Correct me if I wrong, but the issue requested only to support array of number, right? |
Co-authored-by: baruchiro <17686879+baruchiro@users.noreply.github.com>
You're correct. The issue specifically mentions "arrays and single IDs" for documentlink fields, not arbitrary objects. I've removed The validation now only accepts the types needed based on the issue:
Fixed in commit c63349e. |
Co-authored-by: baruchiro <17686879+baruchiro@users.noreply.github.com>
Added changeset file in commit 0a905d1. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the MCP server couldn't modify custom fields of type "documentlink" because the Zod validation schema only accepted primitive types. The fix extends the validation to accept arrays of document IDs, which is required for documentlink custom fields in Paperless-NGX.
Changes:
- Extended Zod validation schema for custom field values to support
z.array(z.number())in addition to primitive types - Added helpful documentation explaining documentlink field usage in
update_documenttool - Included a changeset file for proper version management
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/tools/documents.ts | Updated Zod validation schema in bulk_edit_documents and update_document tools to accept arrays of numbers for documentlink custom field values |
| .changeset/fix-documentlink-custom-fields.md | Added changeset file documenting the bug fix as a patch version bump |
| package-lock.json | Reflects current version (0.2.3) from main branch - no actual version change in this PR |
| value: z.union([ | ||
| z.string(), | ||
| z.number(), | ||
| z.boolean(), | ||
| z.array(z.number()), | ||
| z.null(), | ||
| ]), |
There was a problem hiding this comment.
The value field in bulk_edit_documents is missing a description, unlike the same field in update_document (line 371-373). For consistency and better developer experience, consider adding a .describe() call here that matches the description in update_document, explaining that documentlink fields accept a single document ID or an array of document IDs.
| value: z.union([ | |
| z.string(), | |
| z.number(), | |
| z.boolean(), | |
| z.array(z.number()), | |
| z.null(), | |
| ]), | |
| value: z | |
| .union([ | |
| z.string(), | |
| z.number(), | |
| z.boolean(), | |
| z.array(z.number()), | |
| z.null(), | |
| ]) | |
| .describe( | |
| "Custom field value. For documentlink fields, this can be either a single document ID (number) or an array of document IDs (number[])." | |
| ), |
Fix documentlink custom field validation to accept arrays
Problem
The MCP server cannot modify custom fields when they're "documentlink" types. The Zod validation schema restricts custom field values to only
string | number | boolean | null, which excludes arrays needed for documentlink fields.Root Cause
In
/home/runner/work/paperless-mcp/paperless-mcp/src/tools/documents.ts:Solution Implemented
Updated the Zod validation schema in two tools:
bulk_edit_documents(line 40): Addedz.array(z.number())update_document(line 364): Same changes + helpful documentationChanges Made
z.array(z.number())- for arrays of document IDs (e.g.,[123, 456])z.record(z.unknown())to keep interface clear for AICompleted Checklist
bulk_edit_documentstoolupdate_documenttoolSecurity Summary
No security vulnerabilities introduced. CodeQL scan found 0 alerts.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Note
Enables array values for documentlink custom fields to match Paperless-NGX API.
src/tools/documents.tsZod schemas to acceptz.array(z.number())foradd_custom_fieldsinbulk_edit_documentsandcustom_fieldsinupdate_documentWritten by Cursor Bugbot for commit 0a905d1. This will update automatically on new commits. Configure here.