Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

correlation_analysis

Calculate correlation between two numeric columns in Excel or CSV files to identify statistical relationships in data.

Instructions

Calculate correlation between two numeric columns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the CSV or Excel file
column1YesFirst column name or index (0-based)
column2YesSecond column name or index (0-based)
sheetNoSheet name for Excel files (optional)

Implementation Reference

  • Executes the correlation analysis by reading file data, extracting numeric pairs from two columns, computing Pearson's correlation coefficient, interpreting strength and direction, and returning formatted JSON results.
    async correlationAnalysis(args: ToolArgs): Promise<ToolResponse> {
      const { filePath, column1, column2, sheet } = args;
      const data = await readFileContent(filePath, sheet);
    
      if (data.length <= 1) {
        throw new Error('File has no data rows');
      }
    
      const col1Index = isNaN(Number(column1)) ? data[0].indexOf(column1) : Number(column1);
      const col2Index = isNaN(Number(column2)) ? data[0].indexOf(column2) : Number(column2);
    
      if (col1Index === -1 || col2Index === -1) {
        throw new Error('One or both columns not found');
      }
    
      const pairs = [];
      for (let i = 1; i < data.length; i++) {
        const val1 = Number(data[i][col1Index]);
        const val2 = Number(data[i][col2Index]);
        if (!isNaN(val1) && !isNaN(val2)) {
          pairs.push([val1, val2]);
        }
      }
    
      if (pairs.length < 2) {
        throw new Error('Not enough valid numeric pairs for correlation analysis');
      }
    
      // Calculate Pearson correlation coefficient
      const n = pairs.length;
      const sumX = pairs.reduce((sum, [x]) => sum + x, 0);
      const sumY = pairs.reduce((sum, [, y]) => sum + y, 0);
      const sumXY = pairs.reduce((sum, [x, y]) => sum + x * y, 0);
      const sumX2 = pairs.reduce((sum, [x]) => sum + x * x, 0);
      const sumY2 = pairs.reduce((sum, [, y]) => sum + y * y, 0);
    
      const numerator = n * sumXY - sumX * sumY;
      const denominator = Math.sqrt((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY));
    
      const correlation = denominator === 0 ? 0 : numerator / denominator;
    
      // Interpret correlation strength
      const absCorr = Math.abs(correlation);
      let strength = 'No correlation';
      if (absCorr >= 0.9) strength = 'Very strong';
      else if (absCorr >= 0.7) strength = 'Strong';
      else if (absCorr >= 0.5) strength = 'Moderate';
      else if (absCorr >= 0.3) strength = 'Weak';
      else if (absCorr >= 0.1) strength = 'Very weak';
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              column1: data[0][col1Index],
              column2: data[0][col2Index],
              correlation: Math.round(correlation * 10000) / 10000, // Simplified for test compatibility
              correlationDetails: {
                coefficient: Math.round(correlation * 10000) / 10000,
                strength,
                direction: correlation > 0 ? 'Positive' : correlation < 0 ? 'Negative' : 'None',
                validPairs: n,
                interpretation: `${strength} ${correlation > 0 ? 'positive' : correlation < 0 ? 'negative' : ''} correlation`
              }
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:1223-1224 (registration)
    Registers the 'correlation_analysis' tool call to invoke the correlationAnalysis method on the AnalyticsHandler instance.
    case 'correlation_analysis':
      return await this.analyticsHandler.correlationAnalysis(toolArgs);
  • Defines the tool name, description, and input schema for 'correlation_analysis' in the list of available tools.
    name: 'correlation_analysis',
    description: 'Calculate correlation between two numeric columns',
    inputSchema: {
      type: 'object',
      properties: {
        filePath: {
          type: 'string',
          description: 'Path to the CSV or Excel file',
        },
        column1: {
          type: 'string',
          description: 'First column name or index (0-based)',
        },
        column2: {
          type: 'string',
          description: 'Second column name or index (0-based)',
        },
        sheet: {
          type: 'string',
          description: 'Sheet name for Excel files (optional)',
        },
      },
      required: ['filePath', 'column1', 'column2'],
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It states what the tool does but doesn't mention critical behaviors like what correlation method is used (e.g., Pearson), error handling for non-numeric data, performance characteristics, or output format. For a statistical tool with zero annotation coverage, this leaves significant gaps.

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 front-loaded with the core purpose and appropriately sized for a straightforward tool, making it easy for an agent 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 the complexity of statistical analysis, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., correlation coefficient, p-value), error conditions, or behavioral nuances. For a tool with 4 parameters and no structured output definition, more context is needed.

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 doesn't add any semantic context beyond what's in the schema (e.g., explaining how column names/indices work together, file format limitations, or the optional 'sheet' parameter's role). Baseline 3 is appropriate when the schema does all 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 clearly states the action ('Calculate correlation') and the target ('between two numeric columns'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'statistical_analysis' or 'smart_data_analysis' that might offer similar functionality, preventing a perfect score.

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. With multiple sibling tools that might perform statistical operations (e.g., 'statistical_analysis', 'trend_analysis'), there's no indication of when this specific correlation calculation is preferred or what prerequisites exist (e.g., numeric data requirements).

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