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
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| indices | Yes |
Implementation Reference
- char_index_mcp/server.py:117-143 (handler)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