Skip to main content
Glama

analyze_excel

Perform statistical analysis on Excel data to calculate descriptive statistics, identify trends, and extract insights from numeric columns in spreadsheet files.

Instructions

Perform statistical analysis on Excel data.

Args:
    file_path: Path to the Excel file
    columns: Comma-separated list of columns to analyze (analyzes all numeric columns if None)
    sheet_name: Name of the sheet to analyze (for Excel files)
    
Returns:
    JSON string with statistical analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
columnsNo
sheet_nameNo

Implementation Reference

  • The handler function for the 'analyze_excel' tool. It reads the Excel file (or CSV/TSV/JSON), filters specified columns if provided, selects numeric columns, and computes descriptive statistics, correlation matrix, missing values count, and unique value counts per column. Returns JSON analysis or error.
    @mcp.tool()
    def analyze_excel(file_path: str, columns: Optional[str] = None, 
                    sheet_name: Optional[str] = None) -> str:
        """
        Perform statistical analysis on Excel data.
        
        Args:
            file_path: Path to the Excel file
            columns: Comma-separated list of columns to analyze (analyzes all numeric columns if None)
            sheet_name: Name of the sheet to analyze (for Excel files)
            
        Returns:
            JSON string with statistical analysis
        """
        try:
            # Read file
            _, ext = os.path.splitext(file_path)
            ext = ext.lower()
            
            read_params = {}
            if ext in ['.xlsx', '.xls', '.xlsm'] and sheet_name is not None:
                read_params["sheet_name"] = sheet_name
                
            if ext in ['.xlsx', '.xls', '.xlsm']:
                df = pd.read_excel(file_path, **read_params)
            elif ext == '.csv':
                df = pd.read_csv(file_path)
            elif ext == '.tsv':
                df = pd.read_csv(file_path, sep='\t')
            elif ext == '.json':
                df = pd.read_json(file_path)
            else:
                return f"Unsupported file extension: {ext}"
                
            # Filter columns if specified
            if columns:
                column_list = [c.strip() for c in columns.split(',')]
                df = df[column_list]
            
            # Select only numeric columns for analysis
            numeric_df = df.select_dtypes(include=['number'])
            
            if numeric_df.empty:
                return json.dumps({"error": "No numeric columns found for analysis"})
            
            # Perform analysis
            analysis = {
                "descriptive_stats": numeric_df.describe().to_dict(),
                "correlation": numeric_df.corr().to_dict(),
                "missing_values": numeric_df.isnull().sum().to_dict(),
                "unique_values": {col: int(numeric_df[col].nunique()) for col in numeric_df.columns}
            }
            
            return json.dumps(analysis, indent=2, default=str)
        except Exception as e:
            return json.dumps({"error": str(e)})
  • The @mcp.tool() decorator registers the analyze_excel function as an MCP tool.
    @mcp.tool()
  • A prompt template related to analyzing Excel data, which generates a user prompt for analysis tasks.
    @mcp.prompt()
    def analyze_excel_data(file_path: str) -> str:
        """
        Create a prompt for analyzing Excel data
        """
        return f"""
    I have an Excel file at {file_path} that I'd like to analyze. 
    Could you help me understand the data structure, perform basic statistical analysis, 
    and identify any patterns or insights in the data?
    """
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs statistical analysis and returns JSON, but lacks critical details like what statistical methods are used, whether it modifies the Excel file, error handling for invalid data, or performance considerations. This is inadequate for a tool with 3 parameters and no annotation coverage.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by 'Args' and 'Returns' sections, making it easy to parse. It's concise with no redundant information, though the lack of usage guidelines slightly reduces efficiency. Every sentence adds value, earning a high score for structure.

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 tool's complexity (3 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the statistical analysis output in detail (e.g., what metrics are included), error conditions, or how it interacts with sibling tools. For a data analysis tool with multiple parameters, this leaves significant gaps for 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?

The description adds some semantic context beyond the input schema, which has 0% description coverage. It explains that 'columns' is a comma-separated list and defaults to analyzing all numeric columns if None, and that 'sheet_name' is for Excel files. However, it doesn't clarify the format for 'file_path' (e.g., local vs. remote) or provide examples, leaving gaps in parameter understanding.

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 tool's purpose with a specific verb ('perform statistical analysis') and resource ('on Excel data'), making it immediately understandable. However, it doesn't differentiate this tool from potential sibling tools like 'data_summary' or 'read_excel' that might also analyze Excel data, 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 like 'data_summary', 'filter_excel', or 'pivot_table' from the sibling list. It mentions parameters but doesn't explain the tool's specific use cases, prerequisites, or exclusions, leaving the agent with minimal contextual direction.

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/yzfly/mcp-excel-server'

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