@makeshkumar/mcp-xl-reader 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +59 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -182,6 +182,34 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
182
182
  },
183
183
  required: ["filePath", "cellAddress", "newValue"]
184
184
  }
185
+ },
186
+ {
187
+ name: "add_worksheet_with_data",
188
+ description: "Creates a new worksheet in an existing workbook and populates it with an array of JSON rows. Great for generating summary reports.",
189
+ inputSchema: {
190
+ type: "object",
191
+ properties: {
192
+ filePath: { type: "string" },
193
+ sheetName: { type: "string", description: "Name of the new sheet to create." },
194
+ columns: {
195
+ type: "array",
196
+ items: {
197
+ type: "object",
198
+ properties: {
199
+ header: { type: "string" },
200
+ key: { type: "string" }
201
+ }
202
+ },
203
+ description: "Array of column definitions, e.g., [{header: 'Name', key: 'name'}]"
204
+ },
205
+ rows: {
206
+ type: "array",
207
+ items: { type: "object" },
208
+ description: "Array of JSON objects representing the rows to insert."
209
+ }
210
+ },
211
+ required: ["filePath", "sheetName", "columns", "rows"]
212
+ }
185
213
  }
186
214
  ]
187
215
  };
@@ -398,6 +426,37 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
398
426
  content: [{ type: "text", text: `Successfully updated cell ${cellAddress} to ${newValue}` }]
399
427
  };
400
428
  }
429
+ case "add_worksheet_with_data": {
430
+ const { sheetName, columns, rows } = args;
431
+ await workbook.xlsx.readFile(absolutePath);
432
+ // Check if sheet exists to avoid crashing
433
+ if (workbook.getWorksheet(sheetName)) {
434
+ throw new Error(`A worksheet named '${sheetName}' already exists in this file.`);
435
+ }
436
+ const ws = workbook.addWorksheet(sheetName);
437
+ // Set columns
438
+ if (Array.isArray(columns)) {
439
+ ws.columns = columns.map(col => ({
440
+ header: col.header,
441
+ key: col.key,
442
+ width: 20 // Default reasonable width
443
+ }));
444
+ }
445
+ // Add data rows
446
+ if (Array.isArray(rows)) {
447
+ rows.forEach(rowData => {
448
+ ws.addRow(rowData);
449
+ });
450
+ }
451
+ // Make the header bold to look professional
452
+ const headerRow = ws.getRow(1);
453
+ headerRow.font = { bold: true };
454
+ headerRow.commit();
455
+ await workbook.xlsx.writeFile(absolutePath);
456
+ return {
457
+ content: [{ type: "text", text: `Successfully generated new reporting sheet '${sheetName}' with ${rows.length} rows of data and saved it to the file.` }]
458
+ };
459
+ }
401
460
  default:
402
461
  throw new Error(`Unknown tool: ${name}`);
403
462
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeshkumar/mcp-xl-reader",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {