Skip to main content
Glama
KazKozDev
by KazKozDev

Insert New Element

insert_element

Adds new headings, paragraphs, lists, or other content blocks to Markdown documents at specified locations relative to existing elements.

Instructions

Inserts a new block (heading, paragraph, etc.) relative to an existing one.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
pathYesReference path
element_typeYes
contentYes
whereNoafter
heading_levelNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successNo

Implementation Reference

  • Core implementation of the insert_element tool logic within the EditTool class. Handles path resolution, file locking, document insertion (before/after), atomic file writing, cache updates, and journal confirmation/rollback on errors.
    async def insert(
        self,
        file_path: str,
        path: str,
        element_type: str,
        content: str,
        where: str = "after",
        heading_level: int = 1,
    ) -> Dict[str, Any]:
        abs_path = resolve_path(file_path)
        with FileLock(abs_path):
            doc = self.get_doc(file_path)
            if where == "before":
                result = doc.insert_before(path, element_type, content, heading_level)
            else:
                result = doc.insert_after(path, element_type, content, heading_level)
            if "success" in result:
                try:
                    self._atomic_write(file_path, doc.get_content())
                    self._update_cache_mtime(abs_path)
                    doc.confirm_journal()
                except Exception as e:
                    doc.rollback_last_entry()
                    self.invalidate_cache(file_path)
                    return {"error": f"Failed to write file: {e}"}
        return result
  • Top-level async handler function for the insert_element MCP tool, delegating to the singleton EditTool instance's insert method.
    async def insert_element(
        file_path: str,
        path: str,
        element_type: str,
        content: str,
        where: str = "after",
        heading_level: int = 1,
    ):
        return await _instance.insert(
            file_path, path, element_type, content, where, heading_level
        )
  • Registration of the insert_element tool in the MCP server's list_tools() response, including detailed input and output schemas.
        name="insert_element",
        title="Insert New Element",
        description="Inserts a new block (heading, paragraph, etc.) relative to an existing one.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {"type": "string", "examples": ["./document.md"]},
                "path": {
                    "type": "string",
                    "description": "Reference path",
                    "examples": ["Introduction", "Features > paragraph 2"],
                },
                "element_type": {
                    "type": "string",
                    "enum": [
                        "heading",
                        "paragraph",
                        "list",
                        "code_block",
                        "blockquote",
                    ],
                    "examples": ["paragraph", "heading"],
                },
                "content": {
                    "type": "string",
                    "examples": ["New paragraph content", "## New Section"],
                },
                "where": {
                    "type": "string",
                    "enum": ["before", "after"],
                    "default": "after",
                    "examples": ["after", "before"],
                },
                "heading_level": {
                    "type": "integer",
                    "default": 1,
                    "examples": [1, 2, 3],
                },
            },
            "required": ["file_path", "path", "element_type", "content"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {"success": {"type": "boolean"}},
        },
    ),
  • Input schema definition for the insert_element tool, specifying parameters, types, enums, defaults, and requirements.
    inputSchema={
        "type": "object",
        "properties": {
            "file_path": {"type": "string", "examples": ["./document.md"]},
            "path": {
                "type": "string",
                "description": "Reference path",
                "examples": ["Introduction", "Features > paragraph 2"],
            },
            "element_type": {
                "type": "string",
                "enum": [
                    "heading",
                    "paragraph",
                    "list",
                    "code_block",
                    "blockquote",
                ],
                "examples": ["paragraph", "heading"],
            },
            "content": {
                "type": "string",
                "examples": ["New paragraph content", "## New Section"],
            },
            "where": {
                "type": "string",
                "enum": ["before", "after"],
                "default": "after",
                "examples": ["after", "before"],
            },
            "heading_level": {
                "type": "integer",
                "default": 1,
                "examples": [1, 2, 3],
            },
        },
        "required": ["file_path", "path", "element_type", "content"],
        "additionalProperties": False,
    },
  • Dispatch handler in the MCP server's call_tool method that invokes the insert_element function with parsed arguments and returns the result.
    elif name == "insert_element":
        res = await insert_element(
            file_path,
            arguments["path"],
            arguments["element_type"],
            arguments["content"],
            arguments.get("where", "after"),
            arguments.get("heading_level", 1),
        )
        return CallToolResult(
            content=[TextContent(type="text", text="Element inserted")],
            structuredContent=res,
            isError="error" in res,
        )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is an insertion operation but doesn't mention whether this modifies files in-place, requires write permissions, has side effects, or what happens on failure. For a tool that modifies documents, this lack of behavioral context is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action. Every word earns its place by specifying what's inserted (new block), what types are possible, and the relative positioning. There's no wasted verbiage or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that an output schema exists (though not shown), the description doesn't need to explain return values. However, for a tool with 6 parameters, low schema coverage (17%), and no annotations, the description should provide more context about the insertion behavior, error conditions, and relationship to sibling tools. It's minimally adequate but leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is only 17%, with only one parameter ('path') having a description. The description adds minimal value by mentioning 'relative to an existing one' which hints at the 'path' and 'where' parameters, but doesn't explain the purpose of 'file_path', 'element_type', 'content', or 'heading_level'. The baseline is 3 since the description provides some context but doesn't compensate for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'inserts' and resource 'new block' with examples of block types. It specifies the action is relative to an existing element, which distinguishes it from tools like 'create_file' or 'replace_content'. However, it doesn't explicitly differentiate from similar tools like 'move_element' or 'update_metadata'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'create_file', 'replace_content', 'move_element', or 'update_metadata'. It mentions the action is 'relative to an existing one' but doesn't clarify when this specific insertion approach is preferred over other content modification methods.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/KazKozDev/markdown-editor-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server