Skip to main content
Glama

split_at_indices

Split text at specified character positions. Automatically sorts and removes duplicate indices to ensure precise segmentation for position-based text operations.

Instructions

Split text at exact index positions. Indices auto-sorted and deduplicated.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
indicesYes

Implementation Reference

  • The handler function for the 'split_at_indices' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Takes text and list of indices, sorts/deduplicates/validates indices, and splits the text into parts at those positions, returning list of strings.
    @mcp.tool() def split_at_indices( text: Annotated[str, "Text to split"], indices: Annotated[list[int], "Split positions (auto-sorted & deduplicated)"] ) -> list[str]: """Split text at exact index positions. Indices auto-sorted and deduplicated.""" if not indices: return [text] # Sort and remove duplicates sorted_indices = sorted(set(indices)) # Validate for idx in sorted_indices: if idx < 0 or idx > len(text): raise ValueError(f"Index {idx} out of bounds [0, {len(text)}]") result = [] start = 0 for idx in sorted_indices: result.append(text[start:idx]) start = idx result.append(text[start:]) return result

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