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.

118 lines (117 loc) 5.48 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.registerCorrespondentTools = registerCorrespondentTools; const zod_1 = require("zod"); const middlewares_1 = require("./utils/middlewares"); const queryString_1 = require("./utils/queryString"); function registerCorrespondentTools(server, api) { server.tool("list_correspondents", { page: zod_1.z.number().optional(), page_size: zod_1.z.number().optional(), name__icontains: zod_1.z.string().optional(), name__iendswith: zod_1.z.string().optional(), name__iexact: zod_1.z.string().optional(), name__istartswith: zod_1.z.string().optional(), ordering: zod_1.z.string().optional(), }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); const queryString = (0, queryString_1.buildQueryString)(args); const response = yield api.request(`/correspondents/${queryString ? `?${queryString}` : ""}`); return { content: [ { type: "text", text: JSON.stringify(response), }, ], }; }))); server.tool("get_correspondent", { id: zod_1.z.number() }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); const response = yield api.request(`/correspondents/${args.id}/`); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }))); server.tool("create_correspondent", { name: zod_1.z.string(), match: zod_1.z.string().optional(), matching_algorithm: zod_1.z .enum(["any", "all", "exact", "regular expression", "fuzzy"]) .optional(), }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); const response = yield api.createCorrespondent(args); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }))); server.tool("update_correspondent", { id: zod_1.z.number(), name: zod_1.z.string(), match: zod_1.z.string().optional(), matching_algorithm: zod_1.z .enum(["any", "all", "exact", "regular expression", "fuzzy"]) .optional(), }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); const response = yield api.request(`/correspondents/${args.id}/`, { method: "PUT", body: JSON.stringify(args), }); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }))); server.tool("delete_correspondent", { id: zod_1.z.number() }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); yield api.request(`/correspondents/${args.id}/`, { method: "DELETE" }); return { content: [ { type: "text", text: JSON.stringify({ status: "deleted" }) }, ], }; }))); server.tool("bulk_edit_correspondents", { correspondent_ids: zod_1.z.array(zod_1.z.number()), operation: zod_1.z.enum(["set_permissions", "delete"]), owner: zod_1.z.number().optional(), permissions: zod_1.z .object({ view: zod_1.z.object({ users: zod_1.z.array(zod_1.z.number()).optional(), groups: zod_1.z.array(zod_1.z.number()).optional(), }), change: zod_1.z.object({ users: zod_1.z.array(zod_1.z.number()).optional(), groups: zod_1.z.array(zod_1.z.number()).optional(), }), }) .optional(), merge: zod_1.z.boolean().optional(), }, (0, middlewares_1.errorMiddleware)((args, extra) => __awaiter(this, void 0, void 0, function* () { if (!api) throw new Error("Please configure API connection first"); return api.bulkEditObjects(args.correspondent_ids, "correspondents", args.operation, args.operation === "set_permissions" ? { owner: args.owner, permissions: args.permissions, merge: args.merge, } : {}); }))); }