Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYes
substringYes

Implementation Reference

  • 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

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