Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

pivot_table

Create pivot tables to group and aggregate data from Excel or CSV files. Use this tool to summarize information by categories and calculate totals, averages, counts, minimums, or maximums.

Instructions

Create pivot table with grouping and aggregation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the CSV or Excel file
groupByYesColumn to group by
aggregateColumnYesColumn to aggregate
operationYesAggregation operation
sheetNoSheet name for Excel files (optional)

Implementation Reference

  • The core handler function that implements the pivot_table tool logic: reads data from file/sheet, groups by specified column, aggregates numeric values in another column using sum/average/count/min/max, sorts results descending by aggregate value, and returns structured JSON response.
    async pivotTable(args: ToolArgs): Promise<ToolResponse> {
      const { filePath, groupBy, aggregateColumn, operation, sheet } = args;
      const data = await readFileContent(filePath, sheet);
    
      if (data.length <= 1) {
        throw new Error('File has no data rows');
      }
    
      const groupByIndex = isNaN(Number(groupBy)) ? data[0].indexOf(groupBy) : Number(groupBy);
      const aggIndex = isNaN(Number(aggregateColumn)) ? data[0].indexOf(aggregateColumn) : Number(aggregateColumn);
    
      if (groupByIndex === -1 || aggIndex === -1) {
        throw new Error('One or both columns not found');
      }
    
      // Group data
      const groups: Record<string, number[]> = {};
      for (let i = 1; i < data.length; i++) {
        const groupKey = String(data[i][groupByIndex]);
        const value = Number(data[i][aggIndex]);
    
        if (!groups[groupKey]) {
          groups[groupKey] = [];
        }
    
        if (!isNaN(value)) {
          groups[groupKey].push(value);
        }
      }
    
      // Calculate aggregations
      const results: Array<{ group: string, value: number, count: number }> = [];
      for (const [group, values] of Object.entries(groups)) {
        if (values.length === 0) continue;
    
        let result: number;
        switch (operation) {
          case 'sum':
            result = values.reduce((a: number, b: number) => a + b, 0);
            break;
          case 'average':
            result = values.reduce((a: number, b: number) => a + b, 0) / values.length;
            break;
          case 'count':
            result = values.length;
            break;
          case 'min':
            result = Math.min(...values);
            break;
          case 'max':
            result = Math.max(...values);
            break;
          default:
            result = 0;
        }
    
        results.push({
          group,
          value: Math.round(result * 100) / 100,
          count: values.length
        });
      }
    
      // Sort by value descending
      results.sort((a, b) => b.value - a.value);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              pivotTable: {
                groupBy: data[0][groupByIndex],
                aggregateColumn: data[0][aggIndex],
                operation,
                totalGroups: results.length,
                results
              }
            }, null, 2),
          },
        ],
      };
    }
  • The input schema definition for the pivot_table tool, defining parameters: filePath (required), groupBy, aggregateColumn, operation (sum/average/count/min/max), and optional sheet.
    {
      name: 'pivot_table',
      description: 'Create pivot table with grouping and aggregation',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the CSV or Excel file',
          },
          groupBy: {
            type: 'string',
            description: 'Column to group by',
          },
          aggregateColumn: {
            type: 'string',
            description: 'Column to aggregate',
          },
          operation: {
            type: 'string',
            description: 'Aggregation operation',
            enum: ['sum', 'average', 'count', 'min', 'max'],
          },
          sheet: {
            type: 'string',
            description: 'Sheet name for Excel files (optional)',
          },
        },
        required: ['filePath', 'groupBy', 'aggregateColumn', 'operation'],
      },
    },
  • src/index.ts:1227-1228 (registration)
    The dispatch/registration in the main MCP server request handler switch statement, routing 'pivot_table' calls to AnalyticsHandler.pivotTable method.
    case 'pivot_table':
      return await this.analyticsHandler.pivotTable(toolArgs);
Behavior2/5

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

With no annotations, the description carries full burden but lacks behavioral details. It states the action ('Create') but doesn't disclose if this modifies the original file, creates a new output, requires specific permissions, or handles errors. For a tool with 5 parameters and no annotations, this is a significant gap in transparency.

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 waste. It's front-loaded with the core purpose and uses clear terminology, making it easy to parse quickly.

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?

Given no annotations, no output schema, and 5 parameters, the description is incomplete. It doesn't explain what the tool returns (e.g., a new file, in-memory table, or summary), error conditions, or behavioral constraints, leaving key context gaps for a data transformation tool.

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 parameters. The description adds no additional meaning beyond implying grouping and aggregation, which is already covered by parameter names and descriptions. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'Create pivot table with grouping and aggregation' clearly states the verb ('Create') and resource ('pivot table'), specifying the core functionality. It distinguishes from siblings like 'aggregate' or 'statistical_analysis' by focusing on pivot tables, though it doesn't explicitly contrast with them.

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 is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., file format requirements), exclusions, or compare to siblings like 'bulk_aggregate_multi_files' or 'smart_data_analysis', leaving usage context unclear.

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