autoform-mcp-server 1.7.0 → 1.7.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 CHANGED
@@ -13,7 +13,7 @@ import { handleGenerateBatch, generateBatchSchema } from './tools/generateBatch.
13
13
  import { handleListTemplates, listTemplatesSchema } from './tools/manageTemplates.js';
14
14
  import { handleImportTemplate, importTemplateSchema } from './tools/importTemplate.js';
15
15
  import { withMetrics } from './services/metricsLogger.js';
16
- const server = new Server({ name: 'autoform', version: '1.7.0' }, { capabilities: { tools: {} } });
16
+ const server = new Server({ name: 'autoform', version: '1.7.2' }, { capabilities: { tools: {} } });
17
17
  // Register all tools
18
18
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
19
19
  tools: [
@@ -4,7 +4,7 @@ import { SavedTemplate, ParsedData, DistributionMode, GenerationResult } from '.
4
4
  * Adapts web app's distributionEngine + pdfGenerator for Node.js.
5
5
  */
6
6
  export declare class BatchGenerator {
7
- static generate(template: SavedTemplate, data: ParsedData[], mode?: DistributionMode, mergeIntoSingle?: boolean): Promise<GenerationResult>;
7
+ static generate(template: SavedTemplate, data: ParsedData[], mode?: DistributionMode, mergeIntoSingle?: boolean, outputDir?: string): Promise<GenerationResult>;
8
8
  private static calculateDocumentsNeeded;
9
9
  private static createMappings;
10
10
  }
@@ -9,8 +9,9 @@ const OUTPUT_DIR = path.join(AUTOFORM_HOME, 'output');
9
9
  * Adapts web app's distributionEngine + pdfGenerator for Node.js.
10
10
  */
11
11
  export class BatchGenerator {
12
- static async generate(template, data, mode = 'sequential', mergeIntoSingle = false) {
13
- fs.mkdirSync(OUTPUT_DIR, { recursive: true });
12
+ static async generate(template, data, mode = 'sequential', mergeIntoSingle = false, outputDir) {
13
+ const effectiveOutputDir = outputDir || path.dirname(template.pdfPath) || OUTPUT_DIR;
14
+ fs.mkdirSync(effectiveOutputDir, { recursive: true });
14
15
  const timestamp = new Date().toISOString().slice(0, 10);
15
16
  const safeName = template.name.replace(/[^a-zA-Z0-9_\-]/g, '_');
16
17
  // Read base PDF
@@ -25,8 +26,8 @@ export class BatchGenerator {
25
26
  const errors = [];
26
27
  // If merging, write individuals to temp dir (will be cleaned up)
27
28
  const workingDir = mergeIntoSingle
28
- ? fs.mkdtempSync(path.join(OUTPUT_DIR, '.tmp_batch_'))
29
- : OUTPUT_DIR;
29
+ ? fs.mkdtempSync(path.join(effectiveOutputDir, '.tmp_batch_'))
30
+ : effectiveOutputDir;
30
31
  for (let docNum = 0; docNum < documentsNeeded; docNum++) {
31
32
  try {
32
33
  const mappings = this.createMappings(data, template, docNum, mode);
@@ -42,7 +43,7 @@ export class BatchGenerator {
42
43
  // Merge if requested — and clean up individuals
43
44
  let mergedPath;
44
45
  if (mergeIntoSingle && outputPaths.length > 0) {
45
- mergedPath = path.join(OUTPUT_DIR, `${safeName}_merged_${timestamp}.pdf`);
46
+ mergedPath = path.join(effectiveOutputDir, `${safeName}_merged_${timestamp}.pdf`);
46
47
  await PdfService.mergePdfs(outputPaths, mergedPath);
47
48
  // Delete temp files and dir
48
49
  for (const p of outputPaths) {
@@ -100,6 +100,14 @@ export async function handleFillAtCoordinates(args) {
100
100
  isError: true
101
101
  };
102
102
  }
103
+ // Validate PDF exists
104
+ const fs = await import('fs');
105
+ if (!fs.existsSync(pdf_path)) {
106
+ return { content: [{ type: 'text', text: JSON.stringify({
107
+ error: true,
108
+ message: `El archivo PDF NO existe en la ruta: "${pdf_path}". Verifica que la ruta sea correcta.`
109
+ }, null, 2) }], isError: true };
110
+ }
103
111
  const outputFile = output_path || path.join(path.dirname(pdf_path), `${path.basename(pdf_path, '.pdf')}_filled_${Date.now()}.pdf`);
104
112
  const filled = await PdfService.fillAtCoordinates(pdf_path, fields, outputFile);
105
113
  return {
@@ -87,6 +87,14 @@ export async function handleFillBatchAcroForm(args) {
87
87
  isError: true
88
88
  };
89
89
  }
90
+ // Validate PDF exists BEFORE attempting batch generation
91
+ const fs = await import('fs');
92
+ if (!fs.existsSync(pdf_path)) {
93
+ return { content: [{ type: 'text', text: JSON.stringify({
94
+ error: true,
95
+ message: `El archivo PDF NO existe en la ruta: "${pdf_path}". Verifica que la ruta sea correcta.`
96
+ }, null, 2) }], isError: true };
97
+ }
90
98
  const outDir = output_dir || path.dirname(pdf_path);
91
99
  const baseName = path.basename(pdf_path, '.pdf').replace(/[^a-zA-Z0-9_\-]/g, '_');
92
100
  const result = await PdfService.batchFillAcroForm(pdf_path, data_rows, outDir, baseName, merge_into_single, field_map);
@@ -111,6 +111,14 @@ export async function handleFillBatchAtCoordinates(args) {
111
111
  if (!data_rows || !Array.isArray(data_rows) || data_rows.length === 0) {
112
112
  return { content: [{ type: 'text', text: JSON.stringify({ error: true, message: 'data_rows es requerido (array de objetos con datos)' }, null, 2) }], isError: true };
113
113
  }
114
+ // Validate PDF exists BEFORE attempting batch generation
115
+ const fs = await import('fs');
116
+ if (!fs.existsSync(pdf_path)) {
117
+ return { content: [{ type: 'text', text: JSON.stringify({
118
+ error: true,
119
+ message: `El archivo PDF NO existe en la ruta: "${pdf_path}". Verifica que la ruta sea correcta. Si el usuario te dio un nombre de archivo, usa el filesystem MCP para verificar que existe antes de llamar esta tool.`
120
+ }, null, 2) }], isError: true };
121
+ }
114
122
  const outDir = output_dir || path.dirname(pdf_path);
115
123
  const baseName = path.basename(pdf_path, '.pdf').replace(/[^a-zA-Z0-9_\-]/g, '_');
116
124
  const result = await PdfService.batchFillAtCoordinates(pdf_path, field_definitions, data_rows, outDir, baseName, merge_into_single);
@@ -27,6 +27,10 @@ export declare const generateBatchSchema: {
27
27
  type: string;
28
28
  description: string;
29
29
  };
30
+ output_dir: {
31
+ type: string;
32
+ description: string;
33
+ };
30
34
  _session_id: {
31
35
  type: string;
32
36
  description: string;
@@ -36,6 +36,10 @@ Modos de distribucion:
36
36
  type: 'boolean',
37
37
  description: 'Si es true, une todos los PDFs en uno solo. Default: false.'
38
38
  },
39
+ output_dir: {
40
+ type: 'string',
41
+ description: '(Opcional) Directorio donde guardar los PDFs generados. Default: mismo directorio del PDF base del template.'
42
+ },
39
43
  _session_id: {
40
44
  type: 'string',
41
45
  description: '(Opcional) ID de sesion experimental para agrupar tool calls en metrics.jsonl.'
@@ -50,7 +54,7 @@ Modos de distribucion:
50
54
  }
51
55
  };
52
56
  export async function handleGenerateBatch(args) {
53
- const { template_name, distribution_mode = 'sequential', merge_into_single = false } = args;
57
+ const { template_name, distribution_mode = 'sequential', merge_into_single = false, output_dir } = args;
54
58
  // data puede llegar como string JSON o como array
55
59
  let data = args.data;
56
60
  if (typeof data === 'string') {
@@ -97,7 +101,7 @@ export async function handleGenerateBatch(args) {
97
101
  };
98
102
  }
99
103
  // Generate
100
- const result = await BatchGenerator.generate(template, parsedData, distribution_mode, merge_into_single);
104
+ const result = await BatchGenerator.generate(template, parsedData, distribution_mode, merge_into_single, output_dir);
101
105
  return {
102
106
  content: [{
103
107
  type: 'text',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoform-mcp-server",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "MCP server for bulk PDF form filling. Detect fields, fill templates, and generate hundreds of PDFs from data — directly from Claude.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",