find_all_substring_indices
Locate every occurrence of a substring within text, including overlapping matches, to identify all starting positions for precise text analysis.
Instructions
Find all starting indices where a substring appears (includes overlaps).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| substring | Yes |
Implementation Reference
- char_index_mcp/server.py:91-110 (handler)The handler function for the 'find_all_substring_indices' tool. It is decorated with @mcp.tool() for registration and implements the logic to find all starting indices of the substring in the text, including overlaps, using a loop with str.find.@mcp.tool() def find_all_substring_indices( text: Annotated[str, "Text to search in"], substring: Annotated[str, "Substring to find"] ) -> list[int]: """Find all starting indices where a substring appears (includes overlaps).""" if not substring: raise ValueError("substring cannot be empty") indices = [] start = 0 while True: index = text.find(substring, start) if index == -1: break indices.append(index) start = index + 1 return indices