Skip to main content
Glama

Verified Regex Generator

Typing SVG

Python Tests MCP FastAPI Groq

MCP → Verified Regex Generator. 사용자가 평범한 영어로 패턴을 설명합니다. LLM이 정규식을 생성합니다. 에이전트가 실제 샘플 문자열(긍정 예시 + 부정 예시)을 생성하고, 실제 re 엔진으로 정규식을 테스트한 뒤, 틀렸다면 반복합니다. 정규식은 맞아 보이면서 미묘하게 틀린 경우가 악명 높습니다 — 여기서 핵심 가치는 생성이 아니라 검증입니다.

Groq에서 실행됩니다(기본값 openai/gpt-oss-120b) — 빠르고 무료 티어 친화적이라 공개 데모로 운영하기 저렴합니다.

이것은 "LLM에게 정규식을 물어보고 기대하기"가 아닙니다. 닫힌 검증 루프입니다:

description  ──►  LLM writes a candidate regex
                        │
description  ──►  LLM writes real test strings (incl. tricky near-misses)
                        │
                        ▼
              Python's `re` engine checks the candidate
              against every test string — ground truth,
              not the model's opinion of itself
                        │
              ┌─────────┴─────────┐
          all pass             something failed
              │                     │
              ▼                     ▼
           done               feed the exact failures
                               back to the model, try again

데모

실제 실행: "미국 전화번호" → 에이전트가 16개의 테스트 문자열을 작성하고, 후보 정규식을 제안하며, Python의 실제 re 엔진으로 확인하고, 2회 반복으로 검증된 패턴에 수렴합니다.

Demo

Screenshot

Related MCP server: RegexForge

구성 요소

  • regex_agent/core.py — 실제 에이전트 루프(전송 방식과 무관한 모델). 그 외의 모든 것은 이 주변의 얇은 래퍼입니다.

  • mcp_server/ — generate_verified_regex를 도구로 노출하는 실제 MCP 서버로, Claude Desktop 또는 Claude Code에서 직접 사용할 수 있습니다.

  • web/ — 두 부분으로 구성된 FastAPI + 바닐라 JS 데모:

    1. 에이전트의 추론 과정을 실시간 애니메이션으로 보여주는 뷰: 테스트 케이스, 각 후보 정규식, 반복별 통과/실패 표.

    2. 아래쪽의 regex101 스타일 라이브 테스터 — 플래그(g/i/m/s/전체 일치)가 있는 편집 가능한 패턴 필드, 사용자 테스트 문자열에 대한 라이브 일치 강조, 캡처 그룹이 포함된 일치 목록, 정규식의 평범한 영어 토큰별 분석(모두 클라이언트 측에서 처리, API 호출 없음). 에이전트가 방금 검증한 내용으로 자동 채워지지만, 붙여넣은 어떤 정규식이든 독립적으로 작동합니다 — 정규식을 이미 잘 알아서 테스트만 하고 싶은 경우에도 유용합니다.

    MCP 클라이언트가 필요 없습니다 — 브라우저에서 실행됩니다.

설정

pip install -r requirements.txt
cp .env.example .env   # then add your GROQ_API_KEY

웹 데모 실행

cd web
python server.py

http://127.0.0.1:8000을 엽니다.

MCP 서버 실행

MCP 클라이언트 설정에 다음을 추가합니다(예: Claude Desktop의 claude_desktop_config.json, 또는 Claude Code의 .claude/settings.json):

{
  "mcpServers": {
    "verified-regex-generator": {
      "command": "python",
      "args": ["/absolute/path/to/2 project/mcp_server/server.py"]
    }
  }
}

그런 다음 Claude에게 *"verified regex generator를 사용해서 미국 전화번호용 정규식을 만들어 줘"*라고 요청하세요 — 도구를 호출하고, 서버 측에서 전체 생성 → 테스트 → 검증 루프를 실행한 뒤 JSON 보고서를 반환합니다.

이것이 좋은 쇼케이스인 이유

대부분의 "AI가 코드를 작성" 데모는 생성에서 멈춥니다. 이 프로젝트는 LLM의 첫 답변을 답이 아니라 가설로 취급합니다 — 그리고 실제 근거(실제 문자열에 대한 실제 정규식 엔진, 모델이 직접 제안하는 적대적 근접 오답 포함)에 대해 검증된 경우에만 성공을 주장합니다. 이 루프 — 생성 → 검증 → 수정 — 은 신뢰할 수 있는 에이전트 도구의 핵심 패턴이며, regex_agent/core.py에서 처음부터 끝까지 읽을 수 있을 만큼 작습니다.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables LLMs to systematically develop and validate regex patterns by defining test cases with expected matches, testing patterns against them, and iteratively refining until all requirements are satisfied.
    4
    6
    MIT
  • 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
  • A
    license
    Not graded
    quality
    A
    maintenance
    Provides a tool to extract and validate regex patterns from text content, including flags, positions, and ReDoS risk assessment. Enables AI agents to identify potentially dangerous regular expressions in code or files without needing filesystem access.
    2
    MIT