split_at_indices
Split text at specified character positions to extract or manipulate segments. Automatically sorts and removes duplicate indices for precise text handling.
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. It splits the input text at the specified indices, sorting and deduplicating them first, with validation for out-of-bounds indices.@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
- char_index_mcp/server.py:117-117 (registration)The @mcp.tool() decorator registers the split_at_indices function as an MCP tool.@mcp.tool()
- char_index_mcp/server.py:119-121 (schema)Input schema defined by Annotated type hints: text (str), indices (list[int]). Output is list[str].text: Annotated[str, "Text to split"], indices: Annotated[list[int], "Split positions (auto-sorted & deduplicated)"] ) -> list[str]: