Skip to main content
Glama

find_nth_char

Locate the position of the nth occurrence of a specific character within text. Returns the index or -1 if not found.

Instructions

Find index of nth occurrence of a character. Returns -1 if not found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
charYes
nNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'find_nth_char' tool, including decorator for registration and inline schema via Annotated types. Implements iteration over text to count and locate the nth occurrence of the specified character.
    @mcp.tool()
    def find_nth_char(
        text: Annotated[str, "Text to search in"],
        char: Annotated[str, "Single character to find"],
        n: Annotated[int, "Which occurrence to find (1-based)"] = 1
    ) -> int:
        """Find index of nth occurrence of a character. Returns -1 if not found."""
        if len(char) != 1:
            raise ValueError("char must be a single character")
        if n < 1:
            raise ValueError("n must be >= 1")
        
        count = 0
        for i, c in enumerate(text):
            if c == char:
                count += 1
                if count == n:
                    return i
        return -1
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses the return behavior ('Returns -1 if not found'), which is crucial for understanding outcomes. However, it doesn't mention error handling, performance, or other behavioral traits like character encoding or case sensitivity.

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 with two sentences that directly state the purpose and return behavior. Every word earns its place, and it's front-loaded with the core functionality.

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 low complexity and the presence of an output schema (which likely covers return values), the description is somewhat complete but lacks details on parameter usage and behavioral context. With no annotations and 0% schema coverage, it should do more to explain inputs and edge cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions 'nth occurrence' and 'character', which hints at the 'n' and 'char' parameters, but doesn't explain the 'text' parameter or provide details like what 'n' defaults to (though the schema shows default=1) or how 'char' is interpreted (e.g., single character only). It adds minimal meaning beyond the schema.

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 clearly states the specific verb 'Find index' and resource 'nth occurrence of a character', distinguishing it from siblings like 'find_all_char_indices' (which finds all occurrences) and 'find_nth_substring' (which works with substrings). It precisely defines what the tool does.

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 locating a specific occurrence of a character in text, but doesn't explicitly state when to use this tool versus alternatives like 'find_all_char_indices' or 'find_nth_substring'. No guidance on exclusions or prerequisites is provided.

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