Skip to main content
Glama
NovaAI-innovation

CSV MCP Server

group_data

Group and aggregate CSV data by specified columns using functions like sum, mean, count, min, max, or std to analyze and summarize datasets.

Instructions

Group and aggregate CSV data.

Args:
    filename: Name of the CSV file
    group_by: Column name or list of column names to group by
    aggregations: Dictionary mapping column names to aggregation functions
                 (sum, mean, count, min, max, std, etc.)

Returns:
    Dictionary with grouped and aggregated data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
group_byYes
aggregationsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'group_data' that delegates to CSVManager.group_data, providing input schema via type hints and error handling.
    @mcp.tool()
    def group_data(
        filename: str,
        group_by: Union[str, List[str]],
        aggregations: Dict[str, str]
    ) -> Dict[str, Any]:
        """
        Group and aggregate CSV data.
        
        Args:
            filename: Name of the CSV file
            group_by: Column name or list of column names to group by
            aggregations: Dictionary mapping column names to aggregation functions
                         (sum, mean, count, min, max, std, etc.)
        
        Returns:
            Dictionary with grouped and aggregated data
        """
        try:
            return csv_manager.group_data(filename, group_by, aggregations)
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Core implementation of group_data in CSVManager using pandas groupby and agg for grouping and aggregation logic.
    def group_data(self, filename: str, group_by: Union[str, List[str]], aggregations: Dict[str, str]) -> Dict[str, Any]:
        """Group and aggregate CSV data."""
        filepath = self._get_file_path(filename)
        
        if not filepath.exists():
            raise FileNotFoundError(f"CSV file '{filename}' not found")
        
        try:
            df = pd.read_csv(filepath)
            
            # Ensure group_by is a list
            if isinstance(group_by, str):
                group_by = [group_by]
            
            # Validate group_by columns exist
            for col in group_by:
                if col not in df.columns:
                    raise ValueError(f"Group by column '{col}' not found in CSV")
            
            # Validate aggregation columns exist
            for col in aggregations.keys():
                if col not in df.columns:
                    raise ValueError(f"Aggregation column '{col}' not found in CSV")
            
            # Group and aggregate
            grouped = df.groupby(group_by).agg(aggregations).reset_index()
            
            return {
                "success": True,
                "filename": filename,
                "group_by": group_by,
                "aggregations": aggregations,
                "grouped_data": grouped.to_dict('records'),
                "group_count": len(grouped)
            }
        except Exception as e:
            logger.error(f"Failed to group data: {e}")
            raise
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. It states the tool groups and aggregates data but lacks critical behavioral details: it doesn't mention whether the operation modifies the original file, what happens with invalid inputs, memory/performance considerations, or error handling. The description covers basic functionality but misses important operational context.

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. Every sentence earns its place by explaining parameters or outputs. It could be slightly more concise by integrating the purpose with the parameter explanations, but overall it's efficient and front-loaded.

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

Completeness4/5

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

Given the complexity (3 parameters with nested objects, no annotations) and the presence of an output schema (implied by 'Returns' statement), the description is reasonably complete. It explains all parameters thoroughly and states the return type, though it could benefit from more behavioral context like file handling or error scenarios.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all three parameters in detail: filename specifies the CSV file, group_by indicates column(s) for grouping, and aggregations defines the mapping of columns to functions. It provides concrete examples of aggregation functions (sum, mean, count, etc.), adding significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Group and aggregate CSV data') with the resource ('CSV data'), distinguishing it from siblings like filter_data, sort_data, or get_statistics. It precisely conveys the transformation operation rather than just reading or modifying files.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for grouping and aggregating CSV data, but does not explicitly state when to use this tool versus alternatives like get_statistics or filter_data. No exclusions or prerequisites are mentioned, leaving the agent to infer context from the tool name and description alone.

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/NovaAI-innovation/csv-mcp-server'

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