insert_at_index
Insert text at a specific character position in a string without replacing existing content. Supports positive and negative indices for precise character-level string manipulation.
Instructions
Insert text at index position without replacing. Supports negative indices.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| index | Yes | ||
| insertion | Yes |
Implementation Reference
- char_index_mcp/server.py:150-161 (handler)The handler function for the 'insert_at_index' tool. It inserts the specified text at the given index in the original text, handling negative indices by adjusting from the end. The @mcp.tool() decorator registers the tool and defines the input schema via type annotations.@mcp.tool() def insert_at_index( text: Annotated[str, "Original text"], index: Annotated[int, "Position to insert at (negative = from end)"], insertion: Annotated[str, "Text to insert"] ) -> str: """Insert text at index position without replacing. Supports negative indices.""" if index < 0: index = max(0, len(text) + index + 1) return text[:index] + insertion + text[index:]