Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

write_multi_sheet

Create Excel files with multiple sheets containing formulas and cross-sheet references for structured data organization and calculations.

Instructions

Create a complex Excel file with multiple sheets, formulas, and inter-sheet references

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath for the new Excel file (must end with .xlsx or .xls)
sheetsYesArray of sheet definitions
sheetReferencesNoEnable inter-sheet formula references (default: true)

Implementation Reference

  • The core handler function that implements the write_multi_sheet tool. It creates an Excel workbook with multiple sheets, adds data and headers to each sheet, applies formulas to specified cells, and writes the file to disk.
    async writeMultiSheet(args: ToolArgs): Promise<ToolResponse> {
      const { filePath, sheets, sheetReferences = true } = args;
      const ext = path.extname(filePath).toLowerCase();
      const absolutePath = path.resolve(filePath);
    
      if (ext !== '.xlsx' && ext !== '.xls') {
        throw new Error('write_multi_sheet only works with Excel files (.xlsx or .xls)');
      }
    
      const workbook = new ExcelJS.Workbook();
      const sheetInfo: any[] = [];
    
      // First pass: Create all sheets with data
      for (const sheetDef of sheets) {
        const { name, data, headers, formulas } = sheetDef;
    
        // Prepare data with headers if provided
        const fullData = headers ? [headers, ...data] : data;
    
        // Create worksheet
        const worksheet = workbook.addWorksheet(name);
    
        // Add data to worksheet
        fullData.forEach((row: any[]) => {
          worksheet.addRow(row);
        });
    
        // Apply formulas if provided
        if (formulas && Array.isArray(formulas)) {
          for (const formulaDef of formulas) {
            const { cell, formula } = formulaDef;
    
            // Set formula in worksheet
            const excelCell = worksheet.getCell(cell);
            // If the formula starts with =, remove it for ExcelJS
            const cleanFormula = formula.startsWith('=') ? formula.substring(1) : formula;
            excelCell.value = { formula: cleanFormula };
          }
        }
    
        sheetInfo.push({
          name,
          rowCount: fullData.length,
          columnCount: (fullData.length > 0 && fullData[0]) ? fullData[0].length : 0,
          formulaCount: formulas?.length || 0,
        });
      }
    
      // Write the workbook
      await workbook.xlsx.writeFile(absolutePath);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              filePath: absolutePath,
              mode: 'multi-sheet-advanced',
              sheetsCreated: sheets.length,
              sheetReferences: sheetReferences,
              sheets: sheetInfo,
              totalFormulas: sheetInfo.reduce((sum, sheet) => sum + sheet.formulaCount, 0),
            }, null, 2),
          },
        ],
      };
    }
  • The input schema definition for the write_multi_sheet tool, specifying parameters like filePath, sheets (with data, headers, formulas), and sheetReferences.
      name: 'write_multi_sheet',
      description: 'Create a complex Excel file with multiple sheets, formulas, and inter-sheet references',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path for the new Excel file (must end with .xlsx or .xls)',
          },
          sheets: {
            type: 'array',
            description: 'Array of sheet definitions',
            items: {
              type: 'object',
              properties: {
                name: {
                  type: 'string',
                  description: 'Sheet name',
                },
                data: {
                  type: 'array',
                  description: 'Array of arrays representing rows of data',
                  items: {
                    type: 'array',
                  },
                },
                headers: {
                  type: 'array',
                  description: 'Optional headers for the first row',
                  items: {
                    type: 'string',
                  },
                },
                formulas: {
                  type: 'array',
                  description: 'Array of formula definitions',
                  items: {
                    type: 'object',
                    properties: {
                      cell: {
                        type: 'string',
                        description: 'Cell address in A1 notation (e.g., "A1", "B5")',
                      },
                      formula: {
                        type: 'string',
                        description: 'Excel formula (e.g., "=SUM(A1:A10)", "=Sheet1!A1+Sheet2!B2")',
                      },
                    },
                    required: ['cell', 'formula'],
                  },
                },
              },
              required: ['name', 'data'],
            },
          },
          sheetReferences: {
            type: 'boolean',
            description: 'Enable inter-sheet formula references (default: true)',
          },
        },
        required: ['filePath', 'sheets'],
      },
    },
  • src/index.ts:1247-1248 (registration)
    The switch case in the CallToolRequestSchema handler that routes calls to 'write_multi_sheet' to the FileOperationsHandler.writeMultiSheet method.
    case 'write_multi_sheet':
      return await this.fileOpsHandler.writeMultiSheet(toolArgs);
  • src/index.ts:55-55 (registration)
    Instantiation of the FileOperationsHandler class instance used for file operations tools including write_multi_sheet.
    this.fileOpsHandler = new FileOperationsHandler();
  • src/index.ts:15-15 (registration)
    Import of the FileOperationsHandler class containing the writeMultiSheet method.
    import { FileOperationsHandler } from './handlers/file-operations';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool creates, not how it behaves. It doesn't disclose whether the tool overwrites existing files, requires specific permissions, handles errors, or has performance characteristics. 'Create' implies a write operation, but no further behavioral details are given.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence that efficiently communicates the core functionality without unnecessary words. Every element ('complex Excel file', 'multiple sheets', 'formulas', 'inter-sheet references') contributes directly to understanding the tool's purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, no annotations, and no output schema that creates complex Excel files, the description is insufficient. It doesn't explain what happens if the file already exists, what the return value is, error conditions, or limitations. The absence of annotations means the description should provide more behavioral context than it does.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing complete parameter documentation. The description adds minimal value beyond the schema by mentioning 'multiple sheets, formulas, and inter-sheet references' which aligns with the sheets and sheetReferences parameters, but doesn't provide additional semantic context or usage examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create') and resource ('complex Excel file') with specific features ('multiple sheets, formulas, and inter-sheet references'). It distinguishes from basic write_file by specifying Excel capabilities, but doesn't explicitly differentiate from other Excel-related siblings like add_sheet or format_cells.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like write_file (for simpler files) or add_sheet (for adding to existing files). The description implies it's for complex Excel creation but doesn't provide explicit usage context or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ishayoyo/excel-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server