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
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| char | Yes |
Implementation Reference
- char_index_mcp/server.py:52-62 (handler)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]