Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

add_sheet

Add a new worksheet with data to an existing Excel file, specifying sheet name, data arrays, optional headers, and insertion position.

Instructions

Add a new sheet to an existing Excel file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the existing Excel file (.xlsx or .xls)
sheetNameYesName for the new sheet
dataYesArray of arrays representing rows of data
headersNoOptional headers for the first row
positionNoPosition to insert the sheet (0-based index, optional)

Implementation Reference

  • The core handler function that implements the add_sheet tool logic: reads an existing Excel file, adds a new worksheet with provided data and optional headers, and saves the updated workbook.
    async addSheet(args: ToolArgs): Promise<ToolResponse> {
      const { filePath, sheetName, data, headers, position } = args;
      const ext = path.extname(filePath).toLowerCase();
      const absolutePath = path.resolve(filePath);
    
      if (ext !== '.xlsx' && ext !== '.xls') {
        throw new Error('add_sheet only works with Excel files (.xlsx or .xls)');
      }
    
      try {
        await fs.access(absolutePath);
      } catch {
        throw new Error(`File not found: ${filePath}`);
      }
    
      // Read existing workbook
      const workbook = new ExcelJS.Workbook();
      await workbook.xlsx.readFile(absolutePath);
    
      // Check if sheet name already exists
      if (workbook.getWorksheet(sheetName)) {
        throw new Error(`Sheet "${sheetName}" already exists in the workbook`);
      }
    
      // Prepare data with headers if provided
      const fullData = headers ? [headers, ...data] : data;
    
      // Create new worksheet
      const worksheet = workbook.addWorksheet(sheetName);
      fullData.forEach((row: any[]) => {
        worksheet.addRow(row);
      });
    
      // Note: ExcelJS doesn't support inserting worksheets at specific positions
      // The worksheet is added at the end of the workbook
    
      // Write the updated workbook
      await workbook.xlsx.writeFile(absolutePath);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              filePath: absolutePath,
              sheetName,
              sheetCount: workbook.worksheets.length,
              sheetNames: workbook.worksheets.map(ws => ws.name),
              rowsAdded: fullData.length,
              columnsAdded: fullData[0]?.length || 0,
              position: position !== undefined ? position : workbook.worksheets.length - 1,
            }, null, 2),
          },
        ],
      };
    }
  • The JSON schema defining the input parameters for the add_sheet tool, including filePath, sheetName, data, optional headers and position.
    inputSchema: {
      type: 'object',
      properties: {
        filePath: {
          type: 'string',
          description: 'Path to the existing Excel file (.xlsx or .xls)',
        },
        sheetName: {
          type: 'string',
          description: 'Name for the new sheet',
        },
        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',
          },
        },
        position: {
          type: 'number',
          description: 'Position to insert the sheet (0-based index, optional)',
        },
      },
      required: ['filePath', 'sheetName', 'data'],
    },
  • src/index.ts:1246-1246 (registration)
    Registration of the add_sheet tool in the MCP server's CallToolRequestSchema handler, dispatching to FileOperationsHandler.addSheet method.
    return await this.fileOpsHandler.addSheet(toolArgs);
  • src/index.ts:596-630 (registration)
    Tool registration in the ListToolsRequestSchema response, defining name, description, and input schema for add_sheet.
      name: 'add_sheet',
      description: 'Add a new sheet to an existing Excel file',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the existing Excel file (.xlsx or .xls)',
          },
          sheetName: {
            type: 'string',
            description: 'Name for the new sheet',
          },
          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',
            },
          },
          position: {
            type: 'number',
            description: 'Position to insert the sheet (0-based index, optional)',
          },
        },
        required: ['filePath', 'sheetName', 'data'],
      },
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Add a new sheet' which implies a write/mutation operation, but doesn't disclose critical traits like whether it modifies the original file in-place, requires write permissions, handles errors (e.g., duplicate sheet names), or what happens if the file doesn't exist. This leaves significant gaps for a mutation tool.

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?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for the tool's complexity and front-loads the core purpose immediately.

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 mutation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (success/failure indicators, sheet reference), doesn't cover error conditions or constraints, and provides minimal behavioral context. The 100% schema coverage helps with parameters but doesn't compensate for the overall context gap.

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%, so the schema fully documents all 5 parameters. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain relationships between parameters (e.g., how 'data' interacts with 'headers') or provide usage examples. Baseline 3 is appropriate when schema does all the work.

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 ('Add a new sheet') and target resource ('to an existing Excel file'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'write_multi_sheet' or 'write_file' that might also modify Excel files, so it doesn't fully distinguish from alternatives.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file must exist), exclusions, or compare with sibling tools like 'write_multi_sheet' for multi-sheet creation or 'write_file' for file-level operations.

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