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? """

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