regexguard
regexguard-mcp-server
一个 MCP 服务器,让任何 AI 代理在发布正则表达式之前,都能对其刚刚生成的正则表达式进行合理性检查——既检查它实际匹配的内容,也检查它是否安全,能否针对不可信输入运行。完全本地化:无需 API 密钥,无需网络调用,除了 MCP SDK 和 Zod 之外没有其他依赖。
为什么
正则表达式是出了名的容易引入 bug 的地方,而且这种 bug 在你碰巧测试的所有示例中看起来都正常。特别是两种失败模式,既常见又容易用肉眼忽略:
它匹配的内容和你认为的不一样。
explain_regex将模式转换为真实的语法树,并用通俗易懂的英语描述它,因此“这真的要求至少一个数字吗?”这个问题能快速得到答案,而不必依赖你自己对嵌套括号的解读。它是一个拒绝服务攻击向量。 带有嵌套量词(
(a+)+)或重复组内歧义交替((a|a)+)的正则表达式,可能使回溯引擎在精心构造(甚至偶然)的不匹配输入上花费指数级时间——这就是 ReDoS,一个真实且被反复利用的漏洞类别,也是任何代理在未针对对抗性输入测试的情况下编写的正则表达式中可能存在的缺陷。check_redos_risk会标记结构形状,而从不执行该模式——对不可信或故意恶意的正则表达式源码运行它是安全的。
Related MCP server: Regex Toolkit MCP Server
工具
explain_regex
将模式解析为 AST,并返回它匹配内容的通俗易懂的英文描述。
check_redos_risk
静态分析模式的结构,查找嵌套量词和重复组内的歧义交替——这是灾难性回溯的两个经典原因。返回 "safe"、"high" 或 "critical",并为发现的每个问题提供具体发现。
两个工具共享一个解析器
(src/services/parser.ts):一个真正的递归下降正则表达式解析器(字面量、字符类、简写类、锚点、捕获/非捕获/命名组、环视、交替、量词、反向引用),而不是针对模式原始源码的字符串匹配启发式方法的集合。
这是一个启发式结构检查,不是形式化验证器——check_redos_risk 可以告诉你一个模式具有教科书式的指数爆炸形状;它不能证明一个模式在所有输入上都是快速的,而且存在它当前检测到的两种形状之外的 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,或项目的 .mcp.json 用于 Claude Code):
{
"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.mjs44 个测试覆盖了解析器语法、解释输出,以及 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。
Maintenance
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceRegexForge 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
- FlicenseAqualityCmaintenanceEnables LLM agents to extract, validate, and mask personally identifiable information using deterministic regular expressions, reducing token usage and hallucination risks.373
- AlicenseAqualityAmaintenanceEnables AI agents to parse, validate, explain, and preview cron expressions, surfacing common silent bugs before deployment.4108MIT
- AlicenseAqualityCmaintenanceProvides 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.9MIT
Related MCP Connectors
The WAF for agents. Pattern-based + heuristic firewall scans prompts, RAG documents, tool argume...
Zero-config MCP security scanner for AI-generated apps. 25K+ vulnerability patterns.
Pay-per-call cybersecurity for AI agents: vuln scans, threat intel, compliance, code security.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/wedo911/regexguard-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server