Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

filter_rows

Filter rows in Excel or CSV files by applying conditions to column values, enabling targeted data extraction and analysis.

Instructions

Filter rows based on column values

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the CSV or Excel file
columnYesColumn name or index (0-based)
conditionYesCondition: equals, contains, greater_than, less_than
valueYesValue to compare against
sheetNoSheet name for Excel files (optional)

Implementation Reference

  • Implements the core logic for filtering rows in a spreadsheet file based on a column, condition, and value. Supports conditions: equals, contains, greater_than, less_than.
    async filterRows(args: ToolArgs): Promise<ToolResponse> {
      try {
        const { filePath, column, condition, value, sheet } = args;
        const data = await readFileContent(filePath, sheet);
    
        if (data.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  success: false,
                  error: 'File is empty',
                }, null, 2),
              },
            ],
          };
        }
    
        const colIndex = isNaN(Number(column))
          ? data[0].indexOf(column)
          : Number(column);
    
        if (colIndex === -1 || colIndex >= (data[0]?.length || 0)) {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  success: false,
                  error: `Column "${column}" not found`,
                }, null, 2),
              },
            ],
          };
        }
    
        const headers = data[0];
        const filteredRows = [];
    
        for (let i = 1; i < data.length; i++) {
          const cellValue = String(data[i][colIndex]);
          let matches = false;
    
          switch (condition) {
            case 'equals':
              matches = cellValue === value;
              break;
            case 'contains':
              matches = cellValue.toLowerCase().includes(value.toLowerCase());
              break;
            case 'greater_than':
              matches = Number(cellValue) > Number(value);
              break;
            case 'less_than':
              matches = Number(cellValue) < Number(value);
              break;
          }
    
          if (matches) {
            filteredRows.push(data[i]);
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                totalRows: data.length - 1,
                filteredRows: filteredRows.length,
                filteredData: filteredRows,
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: false,
                error: error instanceof Error ? error.message : 'Unknown error occurred',
              }, null, 2),
            },
          ],
        };
      }
    }
  • Defines the input schema and metadata for the filter_rows tool in the tools list response.
    {
      name: 'filter_rows',
      description: 'Filter rows based on column values',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the CSV or Excel file',
          },
          column: {
            type: 'string',
            description: 'Column name or index (0-based)',
          },
          condition: {
            type: 'string',
            description: 'Condition: equals, contains, greater_than, less_than',
            enum: ['equals', 'contains', 'greater_than', 'less_than'],
          },
          value: {
            type: 'string',
            description: 'Value to compare against',
          },
          sheet: {
            type: 'string',
            description: 'Sheet name for Excel files (optional)',
          },
        },
        required: ['filePath', 'column', 'condition', 'value'],
      },
    },
  • src/index.ts:1209-1210 (registration)
    Registers the tool call dispatch to the DataOperationsHandler.filterRows method.
    case 'filter_rows':
      return await this.dataOpsHandler.filterRows(toolArgs);
  • src/index.ts:13-13 (registration)
    Imports the DataOperationsHandler class containing the filterRows method.
    import { DataOperationsHandler } from './handlers/data-operations';
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 rows but doesn't mention whether this is a read-only operation, if it modifies the original file, what the output format is (e.g., returns filtered data or saves to a new file), or any performance considerations like handling large files. For a tool with 5 parameters and no annotations, this leaves significant behavioral gaps.

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 zero waste: 'Filter rows based on column values'. It's front-loaded with the core action and resource, making it immediately understandable without unnecessary elaboration. Every word earns its place by specifying the tool's purpose directly.

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

Completeness2/5

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

Given the tool's complexity (5 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the return values (e.g., whether filtered data is returned or saved), behavioral traits like file modification, or how it differs from sibling tools. For a data filtering tool with multiple parameters, this minimal description leaves too much unspecified for effective agent use.

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 schema description coverage is 100%, with each parameter well-documented in the input schema (e.g., 'filePath' as path to CSV/Excel, 'condition' with enum values). The description adds no additional parameter semantics beyond what's in the schema, such as examples or edge cases. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

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 'Filter rows based on column values' clearly states the tool's function with a specific verb ('filter') and resource ('rows'), and it specifies the filtering mechanism ('based on column values'). However, it doesn't distinguish this tool from sibling tools like 'bulk_filter_multi_files' or 'search', which might offer similar filtering capabilities with different scopes or approaches.

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. With sibling tools like 'bulk_filter_multi_files' (for multiple files) and 'search' (which might offer broader search functionality), there's no indication of this tool's specific context, prerequisites, or exclusions. Usage is implied only by the tool name and description, lacking explicit when/when-not instructions.

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

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