Skip to main content
Glama

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

Implementation Reference

  • 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
  • The @mcp.tool() decorator registers the split_at_indices function as an MCP tool.
    @mcp.tool()
  • 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]:

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