Skip to main content
Glama

filter_excel

Filter Excel spreadsheet data using pandas query strings to extract specific rows based on conditions like Age > 30 and Department == 'Sales'.

Instructions

Filter Excel data using a pandas query string.

Args:
    file_path: Path to the Excel file
    query: Pandas query string (e.g., "Age > 30 and Department == 'Sales'")
    sheet_name: Name of the sheet to filter (for Excel files)
    
Returns:
    Filtered data as string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
queryYes
sheet_nameNo

Implementation Reference

  • The main handler function for the 'filter_excel' MCP tool. It reads data from an Excel-compatible file, applies a pandas query filter based on the provided query string, and returns the filtered DataFrame as a formatted string. The @mcp.tool() decorator registers it as an MCP tool.
    @mcp.tool()
    def filter_excel(file_path: str, query: str, sheet_name: Optional[str] = None) -> str:
        """
        Filter Excel data using a pandas query string.
        
        Args:
            file_path: Path to the Excel file
            query: Pandas query string (e.g., "Age > 30 and Department == 'Sales'")
            sheet_name: Name of the sheet to filter (for Excel files)
            
        Returns:
            Filtered data as string
        """
        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}"
            
            # Apply filter
            filtered_df = df.query(query)
            
            # Return results
            if filtered_df.empty:
                return "No data matches the filter criteria."
            
            return filtered_df.to_string(index=False)
        except Exception as e:
            return f"Error filtering data: {str(e)}"
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 states the tool filters data and returns it as a string, but lacks details on error handling (e.g., invalid file paths or query syntax), performance implications (e.g., memory usage with large files), or side effects (e.g., whether the original file is modified). For a tool with no annotations, this is a significant gap in transparency.

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 well-structured and concise, with zero waste. It starts with a clear purpose statement, followed by bullet-like sections for 'Args' and 'Returns' that efficiently convey key information. Every sentence earns its place, and the formatting enhances readability 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, no annotations, no output schema), the description is partially complete. It covers the purpose and parameters well but lacks usage guidelines, behavioral details, and output specifics (e.g., format of the returned string). Without an output schema, the description should ideally explain the return value more thoroughly, but it does provide a basic return statement.

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

Parameters4/5

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

The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains each parameter: 'file_path' as the path to the Excel file, 'query' as a pandas query string with an example, and 'sheet_name' as the name of the sheet to filter. This compensates well for the schema's lack of descriptions, making the parameters clear and actionable for an agent.

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: 'Filter Excel data using a pandas query string.' It specifies the verb ('filter'), resource ('Excel data'), and method ('pandas query string'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'read_excel' or 'analyze_excel', which might also involve data extraction or processing.

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 mentions the tool's function but doesn't specify scenarios, prerequisites, or exclusions, such as when to choose 'filter_excel' over 'read_excel' for data retrieval or 'analyze_excel' for analysis. This lack of context makes it harder for an agent to select the right tool among siblings.

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/yzfly/mcp-excel-server'

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