Skip to main content
Glama

get_column_stats

Analyze a specific column in a data file to generate statistical insights in JSON format for data analysis and visualization.

Instructions

Get statistics for a specific column.

Args: file_path: Path to the data file column: Column name to analyze

Returns: Column statistics in JSON format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
columnYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main implementation of get_column_stats tool. Loads data from file using pandas, calculates comprehensive statistics for the specified column including type, null counts, unique values, sample data. For numeric columns: min, max, mean, median, std, and quartiles. For non-numeric: most common values with counts and percentages.
    @mcp.tool()
    def get_column_stats(file_path: str, column: str) -> str:
        """
        Get statistics for a specific column.
        
        Args:
            file_path: Path to the data file
            column: Column name to analyze
        
        Returns:
            Column statistics in JSON format
        """
        try:
            import pandas as pd
            from pathlib import Path
            
            file_extension = Path(file_path).suffix.lower()
            
            # Load with pandas
            if file_extension == '.csv':
                df = pd.read_csv(file_path)
            elif file_extension == '.json':
                df = pd.read_json(file_path)
            elif file_extension in ['.xlsx', '.xls']:
                df = pd.read_excel(file_path)
            elif file_extension == '.tsv':
                df = pd.read_csv(file_path, sep='\t')
            else:
                df = pd.read_csv(file_path)
            
            if column not in df.columns:
                return f"Error: Column '{column}' not found. Available columns: {list(df.columns)}"
            
            col_data = df[column]
            
            stats = {
                "column": column,
                "type": str(col_data.dtype),
                "total_values": len(col_data),
                "non_null_values": int(col_data.notna().sum()),
                "null_count": int(col_data.isna().sum()),
                "unique_values": int(col_data.nunique())
            }
            
            # Sample values
            sample_values = []
            for value in col_data.dropna().head(10):
                if hasattr(value, 'item'):  # numpy types
                    sample_values.append(value.item())
                else:
                    sample_values.append(str(value))
            stats["sample_values"] = sample_values
            
            # If numeric, calculate additional stats
            if pd.api.types.is_numeric_dtype(col_data):
                numeric_col = col_data.dropna()
                if not numeric_col.empty:
                    stats["min"] = float(numeric_col.min())
                    stats["max"] = float(numeric_col.max())
                    stats["mean"] = float(numeric_col.mean())
                    stats["median"] = float(numeric_col.median())
                    stats["std"] = float(numeric_col.std())
                    stats["quartiles"] = {
                        "25%": float(numeric_col.quantile(0.25)),
                        "50%": float(numeric_col.quantile(0.50)),
                        "75%": float(numeric_col.quantile(0.75))
                    }
            else:
                # For non-numeric, show value counts
                value_counts = col_data.value_counts().head(10)
                stats["most_common"] = []
                for value, count in value_counts.items():
                    stats["most_common"].append({
                        "value": str(value),
                        "count": int(count),
                        "percentage": round(count / len(col_data) * 100, 2)
                    })
            
            return json.dumps(stats, indent=2)
            
        except Exception as e:
            return f"Error getting column stats: {str(e)}\n{traceback.format_exc()}"
  • Tool registration via @mcp.tool() decorator that registers get_column_stats as an MCP tool with parameters file_path and column.
    @mcp.tool()
    def get_column_stats(file_path: str, column: str) -> str:
        """
        Get statistics for a specific column.
        
        Args:
            file_path: Path to the data file
            column: Column name to analyze
        
        Returns:
            Column statistics in JSON format
        """
  • Import of get_column_stats function in demo example.
    get_column_stats,
  • Usage example showing how to call get_column_stats with file path and column name, then parse and display the returned statistics.
    result = get_column_stats(str(sample_file), "salary")
    stats = json.loads(result)
    print(f"Statistics for '{stats['column']}' column:")
    print(f"- Type: {stats['type']}")
    print(f"- Values: {stats['total_values']}")
    print(f"- Null count: {stats['null_count']}")
    if 'min' in stats:
        print(f"- Range: ${stats['min']:,} - ${stats['max']:,}")
        print(f"- Average: ${stats['mean']:,.2f}")
    print()
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions that the tool 'Get statistics' and returns 'Column statistics in JSON format,' but it doesn't cover critical aspects like whether it's read-only, if it modifies data, error handling, performance implications, or rate limits. For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 and concise, using a clear purpose statement followed by 'Args' and 'Returns' sections. Each sentence serves a purpose without unnecessary elaboration, making it easy to parse. However, the 'Args' and 'Returns' labels are slightly redundant with the schema, but overall it's efficient.

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 that there is an output schema (implied by 'Has output schema: true'), the description doesn't need to detail return values. However, with no annotations and low schema coverage, it lacks context on behavioral traits and parameter nuances. For a simple tool with two parameters, it's minimally adequate but could benefit from more guidance on usage and behavior.

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 lists the parameters ('file_path' and 'column') and their roles, but with 0% schema description coverage, it doesn't fully compensate by providing details like expected formats, constraints, or examples. It adds basic meaning beyond the schema's property names, but falls short of fully explaining the parameters, resulting in a baseline score.

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: 'Get statistics for a specific column.' This specifies the verb ('Get statistics') and resource ('a specific column'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'analyze_data' or 'create_distribution_plots' that might also involve statistical analysis, so it doesn't reach the highest 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. It doesn't mention prerequisites, context, or comparisons to sibling tools such as 'analyze_data' or 'get_data_sample', leaving the agent to infer usage based on the name alone. This lack of explicit direction reduces its effectiveness in tool selection.

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/moeloubani/visidata-mcp'

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