Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

evaluate_formula

Calculate Excel formulas by providing cell values and ranges. Use this tool to test formulas before applying them to spreadsheets.

Instructions

Evaluate an Excel formula with given context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formulaYesExcel formula to evaluate (e.g., "=SUM(A1:A10)", "=VLOOKUP(B2,C:D,2,FALSE)")
contextNoCell values and ranges for formula evaluation (optional)

Implementation Reference

  • Main handler function for the 'evaluate_formula' tool. Parses the input formula, constructs a WorkbookContext adapter for cell/range lookups, evaluates using FormulaEvaluator, handles circular reference detection, and returns structured JSON response with result or error.
    async evaluateFormula(args: ToolArgs): Promise<ToolResponse> {
      const { formula, context = {} } = args;
    
      try {
        // Parse the formula
        const ast = parseFormula(formula);
    
        // Create a workbook context from the provided context
        const workbookContext: WorkbookContext = {
          getCellValue: (reference: string) => {
            const value = context[reference] || 0;
    
            // If the value is a formula, detect potential circular references
            if (typeof value === 'string' && value.startsWith('=')) {
              // This is a formula reference, check for circular references
              if (value === formula) {
                throw new Error('Circular reference detected');
              }
              // For formulas that reference the same cell, also check
              if (value.includes(reference)) {
                throw new Error('Circular reference detected');
              }
            }
    
            return value;
          },
          getNamedRangeValue: (name: string) => {
            return context[name] || 0;
          },
          getRangeValues: (range: string) => {
            // Check if range is already provided in context
            if (context[range]) {
              return context[range];
            }
    
            // Try to expand the range from individual cells
            const expanded = this.expandRange(range, context);
            return expanded;
          },
          getSheetCellValue: (sheetName: string, reference: string) => {
            // For sheet references, try to get from context using proper Excel sheet!reference format
            const key = `${sheetName}!${reference}`;
            return context[key] || context[reference] || 0;
          },
          getSheetRangeValues: (sheetName: string, range: string) => {
            // For sheet range references, try to get from context using proper Excel sheet!range format
            const key = `${sheetName}!${range}`;
            return context[key] || context[range] || [];
          }
        };
    
        // Evaluate the formula
        const result = this.formulaEvaluator.evaluate(ast, workbookContext);
    
        // Check if result is an error
        const isError = typeof result === 'string' && result.startsWith('#');
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                formula,
                result,
                success: !isError,
                ...(isError && { error: result })
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                formula,
                error: error instanceof Error ? error.message : 'Unknown error',
                success: false
              }, null, 2),
            },
          ],
        };
      }
    }
  • src/index.ts:1257-1266 (registration)
    Tool dispatch registration in the CallToolRequestSchema handler switch statement, mapping 'evaluate_formula' to AIOperationsHandler.evaluateFormula method.
    case 'evaluate_formula':
      return await this.aiOpsHandler.evaluateFormula(toolArgs);
    case 'parse_natural_language':
      return await this.aiOpsHandler.parseNaturalLanguage(toolArgs);
    case 'explain_formula':
      return await this.aiOpsHandler.explainFormula(toolArgs);
    case 'ai_provider_status':
      return await this.aiOpsHandler.getAIProviderStatus(toolArgs);
    case 'smart_data_analysis':
      return await this.aiOpsHandler.smartDataAnalysis(toolArgs);
  • Input schema definition for the 'evaluate_formula' tool registered in ListToolsRequestSchema, defining required 'formula' string and optional 'context' object.
      name: 'evaluate_formula',
      description: 'Evaluate an Excel formula with given context',
      inputSchema: {
        type: 'object',
        properties: {
          formula: {
            type: 'string',
            description: 'Excel formula to evaluate (e.g., "=SUM(A1:A10)", "=VLOOKUP(B2,C:D,2,FALSE)")',
          },
          context: {
            type: 'object',
            description: 'Cell values and ranges for formula evaluation (optional)',
            additionalProperties: true,
          },
        },
        required: ['formula'],
      },
    },
Behavior2/5

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

With no annotations, the description carries full burden but provides minimal behavioral insight. It mentions evaluating with 'given context' but doesn't disclose error handling, performance limits, or what the evaluation entails (e.g., returns a value, modifies data). This is inadequate for a tool with potential computational complexity.

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, making it easy to scan and understand 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 and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., result value, error details) or behavioral aspects like side effects, making it insufficient for safe and effective use by an AI agent.

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 parameters. The description adds no extra meaning beyond implying 'context' is for cell values, which is already in the schema. 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 clearly states the action ('evaluate') and resource ('Excel formula'), specifying it's for evaluation with given context. It distinguishes from siblings like 'explain_formula' by focusing on execution rather than explanation, though it doesn't explicitly contrast with all siblings.

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 is provided. It doesn't mention when to choose this over 'explain_formula' or other formula-related tools, nor does it specify prerequisites or exclusions for usage.

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