Skip to main content
Glama

test_regex

Validate a regex pattern by testing it against all defined test cases to ensure it meets requirements.

Instructions

Test a regex pattern against all current test cases to see if it satisfies the requirements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesThe regex pattern to test
flagsNoOptional regex flags (e.g., 'i' for case-insensitive, 'm' for multiline, 's' for dotall). Default is no flags.

Implementation Reference

  • Schema definition for test_regex tool: registers the tool with name 'test_regex', description, and input schema requiring 'pattern' (string) and optional 'flags' (string).
    types.Tool(
        name="test_regex",
        description="Test a regex pattern against all current test cases to see if it satisfies the requirements.",
        inputSchema={
            "type": "object",
            "properties": {
                "pattern": {
                    "type": "string",
                    "description": "The regex pattern to test"
                },
                "flags": {
                    "type": "string",
                    "description": "Optional regex flags (e.g., 'i' for case-insensitive, 'm' for multiline, 's' for dotall). Default is no flags.",
                    "default": ""
                }
            },
            "required": ["pattern"]
        }
    ),
  • Handler logic for test_regex tool: compiles the regex pattern with optional flags, iterates over all test cases, performs re.search on each input string, compares matched groups against expected matches, and returns a detailed results report.
    elif name == "test_regex":
        pattern = arguments.get("pattern", "")
        flags_str = arguments.get("flags", "")
    
        if not test_cases:
            return [
                types.TextContent(
                    type="text",
                    text="No test cases defined. Please add test cases first using add_test_case."
                )
            ]
    
        # Convert flags string to regex flags
        flags = 0
        if flags_str:
            if 'i' in flags_str.lower():
                flags |= re.IGNORECASE
            if 'm' in flags_str.lower():
                flags |= re.MULTILINE
            if 's' in flags_str.lower():
                flags |= re.DOTALL
            if 'x' in flags_str.lower():
                flags |= re.VERBOSE
    
        try:
            compiled_pattern = re.compile(pattern, flags)
        except re.error as e:
            return [
                types.TextContent(
                    type="text",
                    text=f"Invalid regex pattern: {e}"
                )
            ]
    
        results = []
        passed = 0
        failed = 0
        no_match = 0
    
        results.append(f"Testing regex pattern: {pattern}")
        if flags_str:
            results.append(f"Flags: {flags_str}")
        results.append("-" * 50)
    
        for i, test_case in enumerate(test_cases, 1):
            input_str = test_case["input_string"]
            groups = test_case["groups"]
            expected_matches = test_case["expected_matches"]
            description = test_case.get("description", "")
    
            # Try to find the expected match in the input string
            match = compiled_pattern.search(input_str)
    
            if match:
                # Check if the match contains the expected substring
                matched_texts = [match.group(g) for g in groups] if groups else [match.group(0)] # Where groups  = e.g. [1,2]
                if sorted(matched_texts) == sorted(expected_matches):
                    results.append(f"✅ Test case {i}: PASSED")
                    results.append(f"   Input: '{input_str}'")
                    results.append(f"   Expected: {expected_matches}")
                    results.append(f"   Groups: '{groups}'")
                    results.append(f"   Matched: {matched_texts}")
                    if description:
                        results.append(f"   Description: {description}")
                    passed += 1
                else:
                    results.append(f"🛑 Test case {i}: FAILED")
                    results.append(f"   Input: '{input_str}'")
                    results.append(f"   Expected: '{expected_matches}'")
                    results.append(f"   Groups: '{groups}'")
                    results.append(f"   Matched: '{matched_texts}' (doesn't match expected)")
                    if description:
                        results.append(f"   Description: {description}")
                    failed += 1
            else:
                results.append(f"0️⃣ Test case {i}: NO MATCHES FOUND")
                results.append(f"   Input: '{input_str}'")
                results.append(f"   Expected: '{expected_matches}'")
                results.append(f"   Groups: '{groups}'")
                results.append(f"   Matched: '{[]}'")
                if description:
                    results.append(f"   Description: {description}")
                no_match += 1
    
            results.append("")
    
        results.append("-" * 50)
        results.append(f"Summary: {passed} passed, {failed} failed, {no_match} with no match")
    
        if failed == 0:
            results.append("🎉 All test cases passed! The regex pattern is working correctly.")
        else:
            results.append("💡 Some test cases failed. Consider adjusting the regex pattern.")
    
        return [
            types.TextContent(
                type="text",
                text="\n".join(results)
            )
        ]
  • Registration of test_regex as a tool via the @server.list_tools() decorator, returning it as a Tool object in the list of available tools.
    types.Tool(
        name="test_regex",
        description="Test a regex pattern against all current test cases to see if it satisfies the requirements.",
        inputSchema={
            "type": "object",
            "properties": {
                "pattern": {
                    "type": "string",
                    "description": "The regex pattern to test"
                },
                "flags": {
                    "type": "string",
                    "description": "Optional regex flags (e.g., 'i' for case-insensitive, 'm' for multiline, 's' for dotall). Default is no flags.",
                    "default": ""
                }
            },
            "required": ["pattern"]
        }
    ),
Behavior4/5

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

With no annotations provided, the description carries full burden. It discloses that the tool tests against 'all current test cases', which is key behavioral info. However, it does not mention side effects or return behavior.

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?

Single sentence, no filler, front-loaded with the action and resource.

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

Completeness3/5

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

The description explains the main purpose but lacks details on return value and what 'satisfies the requirements' means. Given the simplicity, it is adequate but incomplete.

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%, so the description adds minimal value beyond schema. It mentions 'satisfies the requirements' but doesn't elaborate. Baseline 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 uses a specific verb 'Test' and clearly identifies the resource 'regex pattern' and context 'against all current test cases', distinguishing it from sibling tools like add_test_case and clear_test_cases.

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

Usage Guidelines3/5

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

The description implies usage for testing regex patterns against existing test cases, but does not explicitly state when to use or when to avoid, nor does it compare with siblings. It provides adequate but not thorough guidance.

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/PatzEdi/MCPGex'

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