add_test_case
Add a test case to validate regex patterns by specifying an input string, expected matches, and groups to extract.
Instructions
Add a test case for regex pattern validation. Each test case consists of an input string and the expected match/output.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_string | Yes | The input string to test the regex pattern against | |
| expected_matches | Yes | Array of substrings that should be matched/extracted by the regex | |
| groups | Yes | The groups that should be extracted by the regex. This is an array of numbers | |
| description | No | Optional description of what this test case is checking for |
Implementation Reference
- src/mcpgex/server.py:23-53 (schema)Schema/registration of the add_test_case tool, defining its name, description, inputSchema (with properties input_string, expected_matches, groups, description) and required fields.
types.Tool( name="add_test_case", description="Add a test case for regex pattern validation. Each test case consists of an input string and the expected match/output.", inputSchema={ "type": "object", "properties": { "input_string": { "type": "string", "description": "The input string to test the regex pattern against" }, "expected_matches": { "type": "array", "items": { "type": "string" }, "description": "Array of substrings that should be matched/extracted by the regex" }, "groups": { "type": "array", "items": { "type": "number" }, "description": "The groups that should be extracted by the regex. This is an array of numbers" }, "description": { "type": "string", "description": "Optional description of what this test case is checking for" } }, "required": ["input_string", "expected_matches", "groups"] } - src/mcpgex/server.py:19-92 (registration)Registration of all tools (including add_test_case) via the @server.list_tools() decorator, which returns the Tool definition for listing by the MCP client.
@server.list_tools() async def handle_list_tools() -> List[types.Tool]: """List available tools for regex pattern testing.""" return [ types.Tool( name="add_test_case", description="Add a test case for regex pattern validation. Each test case consists of an input string and the expected match/output.", inputSchema={ "type": "object", "properties": { "input_string": { "type": "string", "description": "The input string to test the regex pattern against" }, "expected_matches": { "type": "array", "items": { "type": "string" }, "description": "Array of substrings that should be matched/extracted by the regex" }, "groups": { "type": "array", "items": { "type": "number" }, "description": "The groups that should be extracted by the regex. This is an array of numbers" }, "description": { "type": "string", "description": "Optional description of what this test case is checking for" } }, "required": ["input_string", "expected_matches", "groups"] } ), 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"] } ), types.Tool( name="get_test_cases", description="Get all current test cases to see what requirements the regex pattern needs to satisfy.", inputSchema={ "type": "object", "properties": {}, "additionalProperties": False } ), types.Tool( name="clear_test_cases", description="Clear all test cases to start fresh with new requirements.", inputSchema={ "type": "object", "properties": {}, "additionalProperties": False } ) ] - src/mcpgex/server.py:101-129 (handler)Handler logic for add_test_case: extracts arguments, validates groups match expected_matches length, appends the test case to global list, and returns a confirmation message.
if name == "add_test_case": input_string = arguments.get("input_string", "") expected_matches = arguments.get("expected_matches", []) groups = arguments.get("groups", []) description = arguments.get("description", "") if len(groups) != len(expected_matches): return [ types.TextContent( type="text", text=f"Error: Invalid test case. Number of groups ({len(groups)}) does not match number of expected matches ({len(expected_matches)}). Perhaps, input string contains multiple matches?" ) ] test_case = { "input_string": input_string, "expected_matches": expected_matches, "groups": groups, "description": description } test_cases.append(test_case) return [ types.TextContent( type="text", text=f"Added test case:\n- Input: '{input_string}'\n- Expected matches: {expected_matches}\n- Groups: {groups}\n- Description: {description or 'None'}\n\nTotal test cases: {len(test_cases)}" ) ] - src/mcpgex/server.py:13-13 (helper)Global storage list for test cases, used by add_test_case (appends) and other tools (reads/clears).
test_cases: List[Dict[str, Any]] = []