Skip to main content
Glama

find_regex_matches

Locate all regular expression matches with their exact character positions in text. Returns start, end, and match details for precise text analysis.

Instructions

Find all regex matches with positions. Returns list of {start, end, match} dicts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
patternYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registers the find_regex_matches tool using the @mcp.tool() decorator from FastMCP.
    @mcp.tool()
  • The handler function that implements the tool logic: finds all non-overlapping regex matches in the text, returns list of dicts with start index, end index, and matched string. Handles re.error by raising ValueError.
    def find_regex_matches(
        text: Annotated[str, "Text to search in"],
        pattern: Annotated[str, "Regular expression pattern"]
    ) -> list[dict]:
        """Find all regex matches with positions. Returns list of {start, end, match} dicts."""
        try:
            matches = []
            for match in re.finditer(pattern, text):
                matches.append({
                    "start": match.start(),
                    "end": match.end(),
                    "match": match.group()
                })
            return matches
        except re.error as e:
            raise ValueError(f"Invalid regex pattern: {e}")
  • Input schema defined via Annotated types and descriptions, output is list[dict] with match positions.
        text: Annotated[str, "Text to search in"],
        pattern: Annotated[str, "Regular expression pattern"]
    ) -> list[dict]:
        """Find all regex matches with positions. Returns list of {start, end, match} dicts."""
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the return format ('list of {start, end, match} dicts'), which is helpful, but lacks critical details like whether the search is case-sensitive, how overlapping matches are handled, or what happens with invalid regex patterns. For a regex tool with zero annotation coverage, this leaves significant behavioral gaps.

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 extremely concise and front-loaded: two sentences with zero waste. The first sentence states the purpose, and the second specifies the return format, making it efficient and easy to parse.

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?

Given the tool's moderate complexity (regex matching), no annotations, and an output schema that likely covers return values, the description is minimally adequate. It explains what the tool does and the return format, but lacks details on parameter usage, error handling, or behavioral nuances, leaving room for improvement in completeness.

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?

The schema description coverage is 0%, so the description must compensate. It doesn't mention the 'text' or 'pattern' parameters at all, nor does it explain their roles or constraints (e.g., pattern syntax). However, with only 2 parameters and an output schema present, the baseline is 3, as the description adds some value by hinting at the return structure but doesn't fully address parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Find all regex matches with positions.' It specifies the verb ('Find'), resource ('regex matches'), and scope ('all'), but doesn't explicitly differentiate from sibling tools like 'find_all_substring_indices' or 'find_all_char_indices' which serve similar search functions.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention sibling tools or suggest scenarios where regex matching is preferable to substring or character-based searches, leaving the agent without contextual usage direction.

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/agent-hanju/char-index-mcp'

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