Skip to main content
Glama
wedo911

regexguard

regexguard-mcp-server

Glama score

あらゆるAIエージェントが、生成したばかりの正規表現を出荷する前に検証できるようにするMCPサーバーです。実際に何にマッチするか、そして信頼できない入力に対して実行しても安全かどうかを確認できます。完全にローカルで動作し、APIキーもネットワーク呼び出しも不要で、依存関係はMCP SDKとZodのみです。

なぜ必要か

正規表現は、たまたまテストしたすべての例で問題なく見えるバグを混入させやすいことで有名です。特に、目視では見逃しやすい一般的な障害モードが2つあります。

  1. 思っているものにマッチしない。 explain_regex はパターンを実際の構文木に変換し、平易な英語で説明します。そのため、「これには実際に数字が1つ以上必要か?」という疑問に対して、入れ子になった括弧を自分で読むことに頼らずに、素早く答えを得られます。

  2. サービス拒否のベクトルになる。 入れ子になった量指定子((a+)+)や、繰り返しグループ内の曖昧な選択((a|a)+)を含む正規表現は、バックトラッキングエンジンが巧妙に(あるいは偶然に)作られた非マッチ入力に対して指数関数的な時間を要する可能性があります。これはReDoSとして知られる、実際に繰り返し悪用されてきた脆弱性クラスであり、敵対的な入力をテストせずにエージェントが書いた正規表現にはあり得る欠陥です。check_redos_risk は、パターンを実行することなく構造的な形状をフラグ付けします。つまり、信頼できない、または意図的に悪意のある正規表現ソースに対して安全に実行できます。

Related MCP server: cron-mcp

ツール

explain_regex

パターンをASTに解析し、何にマッチするかを平易な英語で説明します。

check_redos_risk

パターンの構造を静的に解析し、入れ子になった量指定子と、繰り返しグループ内の曖昧な選択(破滅的なバックトラッキングの2大原因)を検出します。"safe"、"high"、"critical" のいずれかを返し、見つかった各問題について具体的な所見を示します。

両方のツールは1つのパーサー(src/services/parser.ts)を共有しています。これは、リテラル、文字クラス、省略形クラス、アンカー、キャプチャ/非キャプチャ/名前付きグループ、先読み、選択、量指定子、後方参照を扱う本格的な再帰下降正規表現パーサーであり、パターンの生のソーステキストに対する文字列マッチングのヒューリスティックの集まりではありません。

これはヒューリスティックな構造チェックであり、正式な検証器ではありません。 check_redos_risk は、パターンが教科書的な指数爆発の形状を持っていることを示せますが、すべての入力で高速であることを証明することはできません。また、現在検出している2つの形状以外にもReDoSパターンは存在します。"safe" という結果は「明らかな問題は見つからなかった」という意味であり、保証ではありません。

インストールと設定

git clone https://github.com/wedo911/regexguard-mcp-server.git
cd regexguard-mcp-server
npm install
npm run build

MCPクライアントの設定に追加します(例:claude_desktop_config.json、またはClaude Codeのプロジェクトの.mcp.json)。

{
  "mcpServers": {
    "regexguard": {
      "command": "node",
      "args": ["/absolute/path/to/regexguard-mcp-server/dist/index.js"]
    }
  }
}

テストを実行する

npm run build
node --test tests/parser.test.mjs tests/explain.test.mjs tests/redosCheck.test.mjs

44のテストが、パーサーの文法、説明出力、そしてReDoSチェックの真陽性((a+)+、(a*)*、(a|a)+、(a|ab)+、非キャプチャグループ内に入れ子になったパターン)と真陰性((cat|dog)+、現実的なユーザー名パターン、現実的なメールアドレスパターン、兄弟(入れ子ではない)繰り返し)をカバーしているため、通常のパターンに対する誤検出率はテストされた特性であり、期待ではありません。

クライアントなしで試す

npx @modelcontextprotocol/inspector --cli node dist/index.js \
  --method tools/call --tool-name check_redos_risk \
  --tool-arg pattern='^(([a-zA-Z0-9])+([\.-]?([a-zA-Z0-9])+)*)$'

ライセンス

MIT — LICENSE を参照してください。

Available Tools

2 tools
check_redos_riskCheck Regex for Catastrophic Backtracking (ReDoS) RiskA
Read-onlyIdempotent

Statically analyze a regex's structure for the two classic causes of catastrophic backtracking: nested quantifiers (e.g. "(a+)+") and ambiguous alternation inside a repeated group (e.g. "(a|a)+"). Both can make a backtracking regex engine take exponential time on a crafted or even accidental non-matching input -- a real, exploitable denial-of-service vector, and a common defect in regexes generated without testing against adversarial input.

This tool NEVER executes the pattern -- it only parses and inspects the pattern's source structure, so it's safe to run on untrusted or deliberately malicious patterns without risk of hanging.

Args:

  • pattern (string, 1-1000 chars): the regex source, without delimiters.

Returns: For JSON format: { "parsed": boolean, "error": string | null, "risk": "safe" | "high" | "critical", "findings": [ { "category": "nested_quantifier" | "ambiguous_alternation", "severity": "high" | "critical", "message": string } ] }

Examples:

  • Use when: "is this regex I just generated safe to run against user input?" -> pass the pattern before using it

  • Use when: reviewing a regex from an untrusted source before adding it to a codebase

  • Don't use when: you need proof a regex is fast on all inputs -- this is a heuristic structural check (no false negatives are guaranteed to be caught), not a formal verifier

Error Handling:

  • Returns an error (not an exception) if the pattern doesn't parse.

ParametersJSON Schema
NameRequiredDescriptionDefault
patternYesThe regex source, without the surrounding slashes, e.g. "^(a+)+$".

TDQS

A4.7/5.0
Behavior5/5

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

Annotations already indicate read-only, idempotent, non-destructive. The description adds critical behavioral context: the tool never executes the pattern, is safe on untrusted or malicious input, returns errors rather than exceptions on parse failure, and is heuristic with possible missed risks. This is significant added transparency with no contradiction.

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 with headings for purpose, usage, arguments, return format, examples, and error handling. Every section contributes useful operational information and the purpose is front-loaded within the first sentence.

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?

Since no output schema exists, the description provides the full JSON return structure, error behavior, and usage boundaries, making the tool actionable. Minor ambiguity about regex flavor is acceptable given the structural check nature, and the description is otherwise complete.

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%: the pattern parameter is fully described with type, min/max length, and an example in the schema. The description repeats the 'without delimiters' point but adds no new semantic meaning beyond what the schema already provides. Baseline 3 applies.

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?

The description states a specific verb and resource: statically analyzing a regex's structure for the two classic causes of catastrophic backtracking (nested quantifiers and ambiguous alternation). This clearly distinguishes it from a generic regex explainer like the sibling explain_regex, even without naming it.

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?

Provides explicit 'Use when' scenarios (generated regex before use, reviewing untrusted regex) and a clear 'Don't use when' caution that it is a heuristic structural check, not a formal verifier. This gives the agent clear selection criteria and exclusions.

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

explain_regexExplain a RegexA
Read-onlyIdempotent

Parse a regular expression into a real syntax tree and describe in plain English what it matches. Use this to sanity-check a regex you (or someone else) wrote actually does what you intended, before shipping it.

Args:

  • pattern (string, 1-1000 chars): the regex source, without delimiters (no leading/trailing "/").

Returns: For JSON format: { "explanation": string, "parsed": boolean, "error": string | null } explanation is empty and error is set if the pattern could not be parsed (e.g. unbalanced parentheses, unsupported syntax).

Examples:

  • Use when: "does this regex actually require the string to start with a letter?" -> pass the pattern, read the explanation

  • Don't use when: you need to actually run the regex against text -- this tool never executes the pattern, only analyzes its source

Error Handling:

  • Returns an error (not an exception) if the pattern doesn't parse, with the parser's best guess at where the problem is.

ParametersJSON Schema
NameRequiredDescriptionDefault
patternYesThe regex source, without the surrounding slashes, e.g. "^[a-z0-9_]{3,16}$".

TDQS

A4.4/5.0
Behavior5/5

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

Beyond the annotations, the description discloses important behavioral traits: the tool never executes the pattern, returns a parsed boolean, returns an error rather than throwing an exception on unparseable input, and provides the parser's best guess at the problem. This adds real context beyond the readOnly/idempotent hints and contains no contradiction.

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 well-structured with Args, Returns, Examples, and Error Handling sections, and it front-loads the core purpose. It is slightly redundant with the schema in the Args section, but the overall organization makes it easy for an agent to parse and apply.

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?

With only one parameter and no output schema, the description fully compensates by specifying the exact JSON return shape, the meaning of each field, error behavior, and a concrete usage example. An agent has enough information to call the tool correctly and interpret its result.

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 description coverage is 100%, and the description's Args section essentially repeats the schema: pattern string, 1-1000 chars, no delimiters. It adds no new semantic information beyond what the input schema already provides, so the baseline score of 3 is appropriate.

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?

The description states a specific verb and resource: 'Parse a regular expression into a real syntax tree and describe in plain English what it matches.' It also clearly differentiates the tool from running a regex by explicitly saying it 'never executes the pattern, only analyzes its source,' which distinguishes it from execution-oriented tools.

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

Usage Guidelines4/5

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

The description gives explicit use guidance: 'Use this to sanity-check a regex... before shipping it' and includes both a 'Use when' example and a 'Don't use when' exclusion. It does not explicitly name check_redos_risk as the alternative for security risk assessment, so it misses the full when/when-not/alternatives pattern, but the context is otherwise clear.

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv1.0.0
    • First observedcheck_redos_risk
    • First observedexplain_regex

TDQS

A4.6/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: explain_regex describes what a pattern matches, while check_redos_risk analyzes vulnerability to catastrophic backtracking. They share input format but have no functional overlap, making misselection unlikely.

Naming Consistency5/5

Both tools follow a consistent verb_noun snake_case pattern (explain_regex and check_redos_risk). The naming is predictable and aligns with the domain.

Tool Count4/5

With only two tools, the server is minimally scoped, but for a dedicated regex-analysis utility this is reasonable and each tool addresses a core need. Slightly under typical range but appropriate for the narrow focus.

Completeness5/5

The server covers the essential aspects of regex analysis: comprehension (explain_regex) and security risk (check_redos_risk). Syntax validation is implicitly handled via parse errors. There are no obvious missing operations within the stated purpose.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    RegexForge gives AI agents a reliable way to get a regex without asking an LLM to hallucinate one. Pass in labeled examples (strings that should match, strings that shouldn't) plus an optional description; get back the regex, a proof matrix showing it handles every example, and a backtracking-risk audit flagging catastrophic-backtracking patterns. Pure symbolic synthesis over a template bank with
    -
  • A
    license
    A
    quality
    D
    maintenance
    Provides tools to test regex patterns for correctness, performance (ReDoS), and memory usage, and suggests safe rewrites. Enables LLMs to iterate on regex generation with verifiable feedback.
    9
    MIT