Skip to main content
Glama
K02D

MCP Tabular Data Analysis Server

by K02D

filter_rows

Filter rows in CSV or SQLite files using comparison operators to extract specific data based on column conditions.

Instructions

Filter rows based on a condition.

Args:
    file_path: Path to CSV or SQLite file
    column: Column name to filter on
    operator: Comparison operator - 'eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'contains', 'startswith', 'endswith'
    value: Value to compare against
    limit: Maximum number of rows to return (default 100)

Returns:
    Dictionary containing:
    - filter_applied: Description of the filter
    - original_count: Number of rows before filtering
    - filtered_count: Number of rows after filtering
    - rows: Filtered rows (up to limit)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
columnYes
operatorYes
valueYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The filter_rows tool handler function. Loads data using _load_data helper, applies conditional filtering based on operator and value, and returns filtered rows preview with counts.
    def filter_rows(
        file_path: str,
        column: str,
        operator: str,
        value: str | float | int,
        limit: int = 100,
    ) -> dict[str, Any]:
        """
        Filter rows based on a condition.
        
        Args:
            file_path: Path to CSV or SQLite file
            column: Column name to filter on
            operator: Comparison operator - 'eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'contains', 'startswith', 'endswith'
            value: Value to compare against
            limit: Maximum number of rows to return (default 100)
        
        Returns:
            Dictionary containing:
            - filter_applied: Description of the filter
            - original_count: Number of rows before filtering
            - filtered_count: Number of rows after filtering
            - rows: Filtered rows (up to limit)
        """
        df = _load_data(file_path)
        
        if column not in df.columns:
            raise ValueError(f"Column '{column}' not found. Available: {df.columns.tolist()}")
        
        original_count = len(df)
        
        # Apply filter based on operator
        if operator == "eq":
            mask = df[column] == value
        elif operator == "ne":
            mask = df[column] != value
        elif operator == "gt":
            mask = df[column] > float(value)
        elif operator == "gte":
            mask = df[column] >= float(value)
        elif operator == "lt":
            mask = df[column] < float(value)
        elif operator == "lte":
            mask = df[column] <= float(value)
        elif operator == "contains":
            mask = df[column].astype(str).str.contains(str(value), case=False, na=False)
        elif operator == "startswith":
            mask = df[column].astype(str).str.startswith(str(value), na=False)
        elif operator == "endswith":
            mask = df[column].astype(str).str.endswith(str(value), na=False)
        else:
            raise ValueError(
                f"Unknown operator: {operator}. Use: eq, ne, gt, gte, lt, lte, contains, startswith, endswith"
            )
        
        filtered_df = df[mask]
        
        return {
            "filter_applied": f"{column} {operator} {value}",
            "original_count": original_count,
            "filtered_count": len(filtered_df),
            "rows": filtered_df.head(limit).to_dict(orient="records"),
            "truncated": len(filtered_df) > limit,
        }
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 mentions the tool filters rows and returns a dictionary with counts and rows, but fails to describe critical behaviors like whether it modifies the original file, handles errors (e.g., invalid file paths), supports pagination beyond the limit, or has performance implications for large datasets. This leaves significant gaps for a mutation-like tool.

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 appropriately sized and front-loaded with the core purpose in the first sentence, followed by structured sections for arguments and returns. Every sentence earns its place by providing essential information, though minor improvements could include briefer formatting or merging related details for slightly better flow.

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 (5 parameters, no annotations, but with an output schema), the description is partially complete. It adequately covers parameters and return values due to the output schema, but lacks behavioral context (e.g., file handling, error cases) and usage guidelines relative to siblings, leaving room for improvement in overall completeness.

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?

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It clearly explains each parameter's purpose: 'file_path' for CSV/SQLite files, 'column' for filtering, 'operator' with specific comparison options, 'value' as the comparison target, and 'limit' with its default. This fully compensates for the schema's lack of descriptions, making parameters well-understood.

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 as 'Filter rows based on a condition' with the verb 'filter' and resource 'rows', which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'query_sqlite' or 'group_aggregate' that might also involve data filtering operations, 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 'query_sqlite' for SQL-based filtering or 'list_data_files' for file operations. It lacks context about prerequisites (e.g., file format support) or exclusions, offering only basic parameter documentation without usage context.

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/K02D/mcp-tabular'

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