@baruchiro/paperless-mcp
Version:
Model Context Protocol (MCP) server for interacting with Paperless-NGX document management system. Enables AI assistants to manage documents, tags, correspondents, and document types through the Paperless-NGX API.
39 lines (38 loc) • 2.19 kB
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
import { PaperlessAPI } from "../api/PaperlessAPI";
export type BulkCustomFieldValue = string | number | boolean | number[] | null;
export type BulkCustomFieldUpdate = {
field: number;
value: BulkCustomFieldValue;
};
export type BulkCustomFieldParameters = {
add_custom_fields?: Record<string, BulkCustomFieldValue>;
remove_custom_fields?: number[];
};
/** Validates that a file path is safe to read for document upload. */
export declare function validateFilePath(filePath: string): Promise<void>;
/**
* Builds Paperless-NGX bulk edit parameters from base parameters plus optional
* custom field updates.
*
* Paperless-NGX expects custom field bulk updates as an `add_custom_fields`
* record keyed by custom field id. `addCustomFields` is accepted as an array for
* the MCP tool schema and transformed into that id-to-value record while
* preserving supported value types, including `number[]` document links and
* `null` resets. Passing an empty `addCustomFields` array intentionally produces
* an empty `add_custom_fields` record.
*
* When `includeCustomFieldDefaults` is true, the function also initializes
* `add_custom_fields` and `remove_custom_fields` with empty defaults using
* nullish coalescing (`??=`). This keeps the `modify_custom_fields` method's
* payload shape acceptable to Paperless even when no field values are supplied.
*
* @param parameters - Base bulk edit parameters to include in the result.
* @param addCustomFields - Optional custom field updates to map by field id.
* @param includeCustomFieldDefaults - Whether to include empty custom field
* defaults required by `modify_custom_fields`.
* @returns The merged API parameters with custom field updates transformed into
* Paperless-NGX's `add_custom_fields` record shape.
*/
export declare function buildBulkEditParameters<T extends Record<string, unknown>>(parameters: T, addCustomFields?: BulkCustomFieldUpdate[], includeCustomFieldDefaults?: boolean, includeTagDefaults?: boolean): T & BulkCustomFieldParameters;
export declare function registerDocumentTools(server: McpServer, api: PaperlessAPI): void;