Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYes
indexYes
insertionYes

Implementation Reference

  • 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:]

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