Skip to main content
Glama

Check regular expressions for ReDoS (catastrophic backtracking)

sieve_check_redos
Read-onlyIdempotent

Use when a regular expression will run on user input or untrusted data (form validation, request routing, log parsing, WAF or search rules) and must not hang the server, or when reviewing a codebase's regexes for ReDoS (signals: "is this regex safe", "ReDoS", "catastrophic backtracking", "regex hangs", "CPU spike on validation", "security review of regexes", "(a+)+"). Analyzes 1 to 20 patterns with recheck (automaton analysis with a fuzzing fallback) for backtracking engines with JavaScript syntax, and returns per pattern: safe (proven linear, or no attack found when backreferences or lookarounds force fuzzing), or vulnerable with the complexity (exponential, or polynomial with its degree), a concrete attack string (repr like 'a'.repeat(31) + '\x00', plus the string itself when short), the hot part of the pattern and a fix hint. Example: {"patterns":["^(a+)+$","/^([a-z]+\s)*$/","^[\w.+-]+@[\w-]+\.[\w.-]+$"]}. Python re, PCRE, Java, .NET and Ruby backtrack the same way on these constructs; RE2, Go regexp and Rust regex are linear-time and not affected. To also run the pattern on test strings, use sieve_test_regex.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "patterns": "<patterns>"
    },
    "name": "sieve_check_redos"
  }
}

Input Schema

NameRequiredDescriptionDefault
flagsNoFlags for every pattern given as a raw source (literals keep their own). JavaScript flags d g i m s u v y.
patternsYesRegex sources ("^(a+)+$") or JavaScript literals ("/^(a+)+$/i").

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive/closed-world, and the description goes well beyond them: it explains the underlying engine (recheck automaton analysis with fuzzing fallback), the JavaScript syntax scope, the 1-20 pattern cap, and the caveat that backreferences/lookarounds force fuzzing so 'safe' means no attack found rather than proven linear.

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?

Everything is front-loaded in a single dense paragraph: use-when first, then output shape, then example, then engine applicability. No sentence is filler, though the unbroken block makes the return-value semantics harder to scan than bulleted output would.

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

Completeness5/5

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

There is no output schema, and the description fully compensates by describing per-pattern returns: safe vs. vulnerable, complexity type and polynomial degree, a concrete attack string with repr, the hot part of the pattern, and a fix hint. It also clarifies which engines are and are not affected, which an agent needs to decide whether the tool applies at all.

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?

Schema coverage is 100%, so the baseline is 3, but the description adds accepted input forms ('patterns' as raw sources or JavaScript literals) and a concrete example payload mixing '^(a+)+$', '/^([a-z]+\\s)*$/', and an email regex. It does not elaborate on the 'flags' parameter beyond what the schema already documents.

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?

States a specific verb and resource ('Analyzes 1 to 20 patterns with recheck ... for backtracking engines') and immediately frames it as a ReDoS/catastrophic-backtracking safety check, a distinct purpose from the sibling sieve_test_regex which runs patterns on strings.

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

Usage Guidelines5/5

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

Gives explicit triggers ('will run on user input or untrusted data', 'form validation, request routing, log parsing, WAF or search rules', 'reviewing a codebase's regexes') plus the user phrasings that signal the need. It also names the alternative and the condition that selects it: 'To also run the pattern on test strings, use sieve_test_regex.'

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources