UNPKG

@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.

56 lines (55 loc) 3.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerNoteTools = registerNoteTools; const zod_1 = require("zod"); const middlewares_1 = require("./utils/middlewares"); function notesResult(notes) { return { content: [ { type: "text", text: JSON.stringify(notes), }, ], }; } function registerNoteTools(server, api) { server.tool("list_document_notes", "List all notes attached to a document. Notes are free-text comments on a document and are the natural place for an audit trail (e.g. \"invoice paid on X from account Y\") or progress notes on an action item.", { id: zod_1.z.number().describe("The document ID"), }, (0, middlewares_1.withErrorHandling)((args) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); return notesResult(yield api.getDocumentNotes(args.id)); }))); server.tool("create_document_note", "Add a note to a document. Use this to record an audit trail or progress note directly on the document. Returns the document's full list of notes after the note is added.", { id: zod_1.z.number().describe("The document ID"), note: zod_1.z.string().min(1).describe("The note text to add"), }, (0, middlewares_1.withErrorHandling)((args) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); return notesResult(yield api.createDocumentNote(args.id, args.note)); }))); server.tool("delete_document_note", "⚠️ DESTRUCTIVE: Permanently delete a single note from a document by its note ID. This operation is irreversible. Returns the document's remaining notes.", { id: zod_1.z.number().describe("The document ID"), note_id: zod_1.z.number().describe("The ID of the note to delete"), confirm: zod_1.z .boolean() .describe("Must be true to confirm this destructive operation"), }, (0, middlewares_1.withErrorHandling)((args) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); if (!args.confirm) { throw new Error("Confirmation required for destructive operation. Set confirm: true to proceed."); } return notesResult(yield api.deleteDocumentNote(args.id, args.note_id)); }))); }