Skip to main content
Glama

find_all_char_indices

Locate every occurrence of a specific character within a text string. Returns a list of positions for precise character-level indexing and text manipulation.

Instructions

Find all indices where a character appears. Returns empty list if not found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
charYes

Implementation Reference

  • The handler function decorated with @mcp.tool() implements the find_all_char_indices tool. It takes text and a single character, validates the character length, and returns a list of all indices where the character appears using enumerate and list comprehension.
    @mcp.tool()
    def find_all_char_indices(
        text: Annotated[str, "Text to search in"],
        char: Annotated[str, "Single character to find"]
    ) -> list[int]:
        """Find all indices where a character appears. Returns empty list if not found."""
        if len(char) != 1:
            raise ValueError("char must be a single character")
        
        return [i for i, c in enumerate(text) if c == char]

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