pdfops-mcp 0.3.1 → 0.3.2
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.
- package/dist/index.js +50 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43,20 +43,51 @@ const errText = (e) => e instanceof PdfOpsError
|
|
|
43
43
|
? e.message
|
|
44
44
|
: String(e);
|
|
45
45
|
const fail = (e) => ({ content: [{ type: 'text', text: errText(e) }], isError: true });
|
|
46
|
+
// Declared as outputSchema on every PDF-emitting tool so an agent knows what it
|
|
47
|
+
// gets back without calling first. Both delivery modes are represented: a path
|
|
48
|
+
// when output_path was given, a pdfops:// resource uri when it was not.
|
|
49
|
+
const PDF_OUTPUT = {
|
|
50
|
+
bytes: z.number().int().describe('Size of the produced PDF in bytes'),
|
|
51
|
+
output_path: z.string().optional().describe('Absolute path written, when output_path was supplied'),
|
|
52
|
+
resource_uri: z.string().optional().describe('pdfops:// uri of the inline application/pdf resource, when output_path was omitted'),
|
|
53
|
+
};
|
|
46
54
|
const emit = async (bytes, name, summary, output_path) => {
|
|
47
55
|
if (output_path)
|
|
48
56
|
await writeFile(output_path, bytes);
|
|
49
|
-
|
|
57
|
+
const base = pdfResult(bytes, name, summary, output_path);
|
|
58
|
+
return {
|
|
59
|
+
...base,
|
|
60
|
+
structuredContent: output_path
|
|
61
|
+
? { bytes: bytes.byteLength, output_path }
|
|
62
|
+
: { bytes: bytes.byteLength, resource_uri: `pdfops://${name}` },
|
|
63
|
+
};
|
|
50
64
|
};
|
|
51
65
|
server.registerTool('pdf_inspect', {
|
|
52
66
|
title: 'Inspect PDF form fields',
|
|
53
|
-
description: 'List a PDF\'s AcroForm form fields — names, types, options, current values, per-field maxLength where declared — plus a paste-ready fillTemplate object for pdf_fill and a hasXFA flag (hybrid AcroForm/XFA inputs lose their XFA layer when filled). A PDF with no form returns count 0.
|
|
67
|
+
description: 'List a PDF\'s AcroForm form fields — names, types, options, current values, per-field maxLength where declared — plus a paste-ready fillTemplate object for pdf_fill and a hasXFA flag (hybrid AcroForm/XFA inputs lose their XFA layer when filled). A PDF with no fillable form returns count 0. Read-only: the PDF is fetched or read but never modified. Call this FIRST when filling an unfamiliar PDF, since pdf_fill rejects unknown field names and over-length values.',
|
|
54
68
|
inputSchema: { pdf_path: z.string().describe(SOURCE_DOC) },
|
|
69
|
+
outputSchema: {
|
|
70
|
+
count: z.number().int().describe('Number of form fields found; 0 when the PDF has no fillable form'),
|
|
71
|
+
hasXFA: z.boolean().describe('True for hybrid AcroForm/XFA documents, whose XFA layer is dropped when filled'),
|
|
72
|
+
fields: z
|
|
73
|
+
.array(z.object({
|
|
74
|
+
name: z.string(),
|
|
75
|
+
type: z.string().describe('text, checkbox, radio, optionlist, or unsupported'),
|
|
76
|
+
readOnly: z.boolean(),
|
|
77
|
+
value: z.string().optional(),
|
|
78
|
+
options: z.array(z.string()).optional().describe('Permitted values for radio/dropdown/optionlist fields'),
|
|
79
|
+
checked: z.boolean().optional(),
|
|
80
|
+
maxLength: z.number().int().optional().describe('Longer values are rejected by pdf_fill'),
|
|
81
|
+
raw: z.unknown().optional(),
|
|
82
|
+
}))
|
|
83
|
+
.describe('One entry per form field, in document order'),
|
|
84
|
+
fillTemplate: z.record(z.string()).describe('Field name to empty-or-current value, ready to edit and pass to pdf_fill'),
|
|
85
|
+
},
|
|
55
86
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
56
87
|
}, async ({ pdf_path }) => {
|
|
57
88
|
try {
|
|
58
89
|
const result = await client.inspect(await resolveSource(pdf_path));
|
|
59
|
-
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
90
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: { ...result } };
|
|
60
91
|
}
|
|
61
92
|
catch (e) {
|
|
62
93
|
return fail(e);
|
|
@@ -64,7 +95,7 @@ server.registerTool('pdf_inspect', {
|
|
|
64
95
|
});
|
|
65
96
|
server.registerTool('pdf_fill', {
|
|
66
97
|
title: 'Fill PDF form',
|
|
67
|
-
description: 'Fill AcroForm form fields in a PDF and save or return the result. Field names must exist in the PDF (use pdf_inspect first). All values are strings; checkboxes take "true"/"false"; dropdown/radio/optionlist values must be one of the field\'s options; text values must respect the field\'s maxLength from pdf_inspect. Encrypted PDFs are rejected with decrypt advice (common for government blanks with an empty user password).',
|
|
98
|
+
description: 'Fill AcroForm form fields in a PDF and save or return the result. Field names must exist in the PDF (use pdf_inspect first). All values are strings; checkboxes take "true"/"false"; dropdown/radio/optionlist values must be one of the field\'s options; text values must respect the field\'s maxLength from pdf_inspect. The source PDF is never modified. Returns the filled PDF written to output_path, or inline as an application/pdf resource when output_path is omitted; an existing file at output_path is overwritten. Encrypted PDFs are rejected with decrypt advice (common for government blanks with an empty user password), and a rejected fill writes no file at all.',
|
|
68
99
|
inputSchema: {
|
|
69
100
|
pdf_path: z.string().describe(`Template ${SOURCE_DOC}`),
|
|
70
101
|
fields: z
|
|
@@ -76,6 +107,7 @@ server.registerTool('pdf_fill', {
|
|
|
76
107
|
.optional()
|
|
77
108
|
.describe('Bake values into page content and drop the AcroForm so fields are no longer editable'),
|
|
78
109
|
},
|
|
110
|
+
outputSchema: PDF_OUTPUT,
|
|
79
111
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
80
112
|
}, async ({ pdf_path, fields, output_path, flatten }) => {
|
|
81
113
|
try {
|
|
@@ -88,11 +120,12 @@ server.registerTool('pdf_fill', {
|
|
|
88
120
|
});
|
|
89
121
|
server.registerTool('pdf_merge', {
|
|
90
122
|
title: 'Merge PDFs',
|
|
91
|
-
description: 'Merge two or more PDFs into one, in the order given, and save or return the result.',
|
|
123
|
+
description: 'Merge two or more PDFs into one, in the order given, and save or return the result. Source files are read only and never modified; an existing file at output_path is overwritten. Returns the merged PDF written to output_path, or inline as an application/pdf resource when output_path is omitted. This tool only concatenates whole documents: it does not reorder, rotate or delete pages within them, and it does not fill forms — use pdf_fill for a fillable form and pdf_invoice to build a document from data. An unreadable or rejected input fails with an error and writes no file, so a partial merge is never left behind.',
|
|
92
124
|
inputSchema: {
|
|
93
125
|
pdf_paths: z.array(z.string()).min(2).describe(`In order, each a ${SOURCE_DOC}`),
|
|
94
126
|
output_path: z.string().optional().describe(OUTPUT_DOC),
|
|
95
127
|
},
|
|
128
|
+
outputSchema: PDF_OUTPUT,
|
|
96
129
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
97
130
|
}, async ({ pdf_paths, output_path }) => {
|
|
98
131
|
try {
|
|
@@ -106,7 +139,7 @@ server.registerTool('pdf_merge', {
|
|
|
106
139
|
});
|
|
107
140
|
server.registerTool('pdf_invoice', {
|
|
108
141
|
title: 'Generate invoice PDF',
|
|
109
|
-
description: 'Generate a complete, professionally laid-out invoice PDF from structured data — no template needed. Deterministic: the same input produces byte-identical output (safe to re-run). Note: without a paid PDFops key the output carries a small "Generated with pdfops.dev" footer line.',
|
|
142
|
+
description: 'Generate a complete, professionally laid-out invoice PDF from structured data — no template needed. Deterministic: the same input produces byte-identical output (safe to re-run). Note: without a paid PDFops key the output carries a small "Generated with pdfops.dev" footer line. Returns the invoice written to output_path, or inline as an application/pdf resource when output_path is omitted; an existing file at output_path is overwritten. Use this when you have invoice DATA and no document; if you already have an invoice PDF or a fillable template to populate, use pdf_fill instead.',
|
|
110
143
|
inputSchema: {
|
|
111
144
|
invoice: z
|
|
112
145
|
.object({
|
|
@@ -139,6 +172,7 @@ server.registerTool('pdf_invoice', {
|
|
|
139
172
|
.describe('Invoice data'),
|
|
140
173
|
output_path: z.string().optional().describe(OUTPUT_DOC),
|
|
141
174
|
},
|
|
175
|
+
outputSchema: PDF_OUTPUT,
|
|
142
176
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
143
177
|
}, async ({ invoice, output_path }) => {
|
|
144
178
|
try {
|
|
@@ -152,13 +186,21 @@ server.registerTool('pdf_invoice', {
|
|
|
152
186
|
});
|
|
153
187
|
server.registerTool('pdfops_usage', {
|
|
154
188
|
title: 'Check PDFops quota',
|
|
155
|
-
description: 'Check the current PDFops API quota for the configured key: tier, limit, used, remaining, reset
|
|
189
|
+
description: 'Check the current PDFops API quota for the configured key: tier, limit, used, remaining, the billing period, and the reset timestamp. Read-only and safe to call before a batch to confirm there is headroom. Requires PDFOPS_API_KEY.',
|
|
156
190
|
inputSchema: {},
|
|
191
|
+
outputSchema: {
|
|
192
|
+
tier: z.string().describe('Plan name, e.g. free'),
|
|
193
|
+
limit: z.number().int().describe('Calls allowed in the current period'),
|
|
194
|
+
used: z.number().int(),
|
|
195
|
+
remaining: z.number().int(),
|
|
196
|
+
period: z.string().describe('Billing period the counts belong to, YYYY-MM'),
|
|
197
|
+
resets_at: z.string().describe('ISO 8601 timestamp when used resets to 0'),
|
|
198
|
+
},
|
|
157
199
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
158
200
|
}, async () => {
|
|
159
201
|
try {
|
|
160
202
|
const usage = await client.usage();
|
|
161
|
-
return { content: [{ type: 'text', text: JSON.stringify(usage, null, 2) }] };
|
|
203
|
+
return { content: [{ type: 'text', text: JSON.stringify(usage, null, 2) }], structuredContent: { ...usage } };
|
|
162
204
|
}
|
|
163
205
|
catch (e) {
|
|
164
206
|
return fail(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfops-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"mcpName": "dev.pdfops/pdfops-mcp",
|
|
5
5
|
"description": "MCP server for the PDFops API — give AI agents deterministic PDF tools: inspect AcroForm fields, fill forms, merge PDFs, and generate invoices. Works with Claude Code, Claude Desktop, Cursor, and any MCP client.",
|
|
6
6
|
"keywords": [
|