Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

get_statistics

Calculate statistical summaries for numerical columns in CSV files, including mean, median, and percentiles to analyze data distributions.

Instructions

Get statistical summary of numerical columns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
columnsNo
include_percentilesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the get_statistics tool logic: retrieves CSV session data, identifies numeric columns, computes detailed statistics (count, nulls, mean, std, min, max, sum, variance, skewness, kurtosis, optional percentiles and IQR), records the operation, and returns structured results.
    async def get_statistics(
        session_id: str, 
        columns: Optional[List[str]] = None,
        include_percentiles: bool = True,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Get statistical summary of numerical columns.
        
        Args:
            session_id: Session identifier
            columns: Specific columns to analyze (None for all numeric)
            include_percentiles: Include percentile values
            ctx: FastMCP context
            
        Returns:
            Dict with statistics for each column
        """
        try:
            manager = get_session_manager()
            session = manager.get_session(session_id)
            
            if not session or session.df is None:
                return {"success": False, "error": "Invalid session or no data loaded"}
            
            df = session.df
            
            # Select columns to analyze
            if columns:
                missing_cols = [col for col in columns if col not in df.columns]
                if missing_cols:
                    return {"success": False, "error": f"Columns not found: {missing_cols}"}
                numeric_df = df[columns].select_dtypes(include=[np.number])
            else:
                numeric_df = df.select_dtypes(include=[np.number])
            
            if numeric_df.empty:
                return {"success": False, "error": "No numeric columns found"}
            
            # Calculate statistics
            stats = {}
            percentiles = [0.25, 0.5, 0.75] if include_percentiles else []
            
            for col in numeric_df.columns:
                col_data = numeric_df[col].dropna()
                
                col_stats = {
                    "count": int(col_data.count()),
                    "null_count": int(df[col].isna().sum()),
                    "mean": float(col_data.mean()),
                    "std": float(col_data.std()),
                    "min": float(col_data.min()),
                    "max": float(col_data.max()),
                    "sum": float(col_data.sum()),
                    "variance": float(col_data.var()),
                    "skewness": float(col_data.skew()),
                    "kurtosis": float(col_data.kurt())
                }
                
                if include_percentiles:
                    col_stats["25%"] = float(col_data.quantile(0.25))
                    col_stats["50%"] = float(col_data.quantile(0.50))
                    col_stats["75%"] = float(col_data.quantile(0.75))
                    col_stats["iqr"] = col_stats["75%"] - col_stats["25%"]
                
                stats[col] = col_stats
            
            session.record_operation(OperationType.ANALYZE, {
                "type": "statistics",
                "columns": list(stats.keys())
            })
            
            return {
                "success": True,
                "statistics": stats,
                "columns_analyzed": list(stats.keys()),
                "total_rows": len(df)
            }
            
        except Exception as e:
            logger.error(f"Error getting statistics: {str(e)}")
            return {"success": False, "error": str(e)}
  • MCP tool registration for get_statistics using @mcp.tool decorator. This wrapper function defines the tool interface (parameters and docstring used for schema/input validation) and delegates execution to the core implementation via _get_statistics.
    @mcp.tool
    async def get_statistics(
        session_id: str,
        columns: Optional[List[str]] = None,
        include_percentiles: bool = True,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Get statistical summary of numerical columns."""
        return await _get_statistics(session_id, columns, include_percentiles, ctx)
  • Import statement that brings the get_statistics implementation into server.py, aliased as _get_statistics for use by the registered tool wrapper.
    from .tools.analytics import (
        get_statistics as _get_statistics,
        get_column_statistics as _get_column_statistics,
        get_correlation_matrix as _get_correlation_matrix,
        group_by_aggregate as _group_by_aggregate,
        get_value_counts as _get_value_counts,
        detect_outliers as _detect_outliers,
        profile_data as _profile_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's function but lacks details on permissions, rate limits, side effects, or output format. The agent must infer behavior from the tool name and parameters alone.

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 no wasted words. It is front-loaded and directly states the tool's purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, 1 required) and the presence of an output schema, the description is minimally adequate. However, with 0% schema coverage and no annotations, it lacks sufficient detail for safe and effective use, such as explaining parameter roles or behavioral constraints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but fails to do so. It mentions 'numerical columns' but doesn't explain parameters like 'session_id', 'columns', or 'include_percentiles'. The description adds minimal value beyond what the schema's property names imply.

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 ('Get') and target ('statistical summary of numerical columns'), which is specific and distinguishes it from siblings like 'get_column_statistics' or 'profile_data'. However, it doesn't explicitly differentiate from 'get_column_statistics', which might overlap in functionality.

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 'get_column_statistics' or 'profile_data'. There is no mention of prerequisites, exclusions, or specific contexts for application.

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/santoshray02/csv-editor'

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