Skip to main content
Glama

filter_results

Filter scan results by severity, rule ID, file path pattern, language, or message pattern to focus on relevant findings.

Instructions

Filters scan results by various criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
results_fileYesAbsolute path to JSON results file
severityNoFilter by severity (ERROR, WARNING, INFO)
rule_idNoFilter by rule ID
path_patternNoFilter by file path pattern (regex)
languageNoFilter by programming language
message_patternNoFilter by message content (regex)

Implementation Reference

  • The handler function `handleFilterResults` that executes the filter_results tool logic. It reads a JSON results file, parses it, and applies optional filters: severity, rule_id, path_pattern (regex), language, and message_pattern (regex). Returns filtered results as JSON.
    private async handleFilterResults(args: any) {
      if (!args.results_file) {
        throw new McpError(ErrorCode.InvalidParams, 'results_file is required');
      }
    
      const resultsFile = validateAbsolutePath(args.results_file, 'results_file');
    
      try {
        const fileContent = await readFile(resultsFile, 'utf-8');
        const results = parseSemgrepResults(fileContent);
    
        let filteredResults = getSemgrepFindings(results);
    
        if (args.severity) {
          filteredResults = filteredResults.filter(
            (finding: any) => finding.extra?.severity === args.severity
          );
        }
    
        if (args.rule_id) {
          filteredResults = filteredResults.filter(
            (finding: any) => finding.check_id === args.rule_id
          );
        }
    
        if (args.path_pattern) {
          const pathRegex = new RegExp(args.path_pattern);
          filteredResults = filteredResults.filter(
            (finding: any) => pathRegex.test(finding.path)
          );
        }
    
        if (args.language) {
          filteredResults = filteredResults.filter(
            (finding: any) => finding.extra?.metadata?.language === args.language
          );
        }
    
        if (args.message_pattern) {
          const messageRegex = new RegExp(args.message_pattern);
          filteredResults = filteredResults.filter(
            (finding: any) => messageRegex.test(finding.extra?.message ?? '')
          );
        }
    
        return {
          content: [{ type: 'text', text: JSON.stringify({ results: filteredResults }, null, 2) }]
        };
      } catch (error: any) {
        return {
          content: [{ type: 'text', text: `Error filtering results: ${error.message}` }],
          isError: true
        };
      }
    }
  • The input schema definition for the filter_results tool. Defines properties: results_file (required), severity, rule_id, path_pattern, language, message_pattern.
    {
      name: 'filter_results',
      description: 'Filters scan results by various criteria',
      inputSchema: {
        type: 'object',
        properties: {
          results_file: { type: 'string', description: 'Absolute path to JSON results file' },
          severity: { type: 'string', description: 'Filter by severity (ERROR, WARNING, INFO)' },
          rule_id: { type: 'string', description: 'Filter by rule ID' },
          path_pattern: { type: 'string', description: 'Filter by file path pattern (regex)' },
          language: { type: 'string', description: 'Filter by programming language' },
          message_pattern: { type: 'string', description: 'Filter by message content (regex)' }
        },
        required: ['results_file']
      }
  • src/index.ts:371-395 (registration)
    The CallToolRequestSchema handler that routes 'filter_results' tool calls to handleFilterResults.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      await this.ensureSemgrepAvailable();
    
      switch (request.params.name) {
      case 'scan_directory':
        return await this.handleScanDirectory(request.params.arguments);
      case 'list_rules':
        return await this.handleListRules(request.params.arguments);
      case 'analyze_results':
        return await this.handleAnalyzeResults(request.params.arguments);
      case 'create_rule':
        return await this.handleCreateRule(request.params.arguments);
      case 'filter_results':
        return await this.handleFilterResults(request.params.arguments);
      case 'export_results':
        return await this.handleExportResults(request.params.arguments);
      case 'compare_results':
        return await this.handleCompareResults(request.params.arguments);
      default:
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    });
  • Helper function `getSemgrepFindings` used by handleFilterResults to extract the results array from parsed Semgrep output.
    function getSemgrepFindings(results: SemgrepResults): SemgrepFinding[] {
      return Array.isArray(results.results) ? results.results : [];
  • Helper function `parseSemgrepResults` used by handleFilterResults to parse JSON file content into a SemgrepResults object.
    export function parseSemgrepResults(fileContent: string): SemgrepResults {
      const parsedContent = JSON.parse(fileContent);
    
      if (!parsedContent || typeof parsedContent !== 'object' || Array.isArray(parsedContent)) {
        return {};
      }
    
      return parsedContent as SemgrepResults;
    }
Behavior2/5

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

No annotations provided, so the description carries the full burden. It does not disclose whether the tool modifies the original file, requires authentication, or has side effects. The filtering behavior (e.g., AND vs OR logic) is not explained.

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?

Very short single sentence, efficient but lacking critical details. It is concise but not optimally informative for a 6-parameter tool.

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?

With 6 parameters, no output schema, and no annotations, the description is incomplete. It does not explain return format, behavior when no matches, or how it differs from sibling tools like export_results.

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?

Schema coverage is 100% with parameter descriptions, so the description adds minimal value beyond the schema. It does not clarify how multiple filters interact, which leaves ambiguity for the agent.

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

Purpose3/5

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

The description states it filters scan results, which is clear but lacks specificity about the resource (e.g., scan results file) and does not differentiate from sibling tools like analyze_results or compare_results.

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?

No guidance on when to use this tool versus alternatives (e.g., analyze_results for aggregation, compare_results for comparison). No when-not-to-use or prerequisites mentioned.

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/VetCoders/mcp-server-semgrep'

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