Skip to main content
Glama
KazKozDev
by KazKozDev

Replace Block Content

replace_content

Replace specific content blocks in Markdown files using hierarchical paths while preserving document structure. Update paragraphs, lists, or sections without manual text editing.

Instructions

Overwrites the content of a specific block. Maintains document structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
pathYes
new_contentYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successNo

Implementation Reference

  • Core handler logic for replacing content in a Markdown document element. Performs path resolution, file locking, content replacement via Document.replace, atomic file write, cache update, and error handling with rollback.
    async def replace(
        self, file_path: str, path: str, new_content: str
    ) -> Dict[str, Any]:
        abs_path = resolve_path(file_path)
        with FileLock(abs_path):
            doc = self.get_doc(file_path)
            result = doc.replace(path, new_content)
            if "success" in result:
                try:
                    self._atomic_write(file_path, doc.get_content())
                    self._update_cache_mtime(abs_path)
                    # Confirm journal only after successful file write
                    doc.confirm_journal()
                except Exception as e:
                    # Rollback journal entry on write failure
                    doc.rollback_last_entry()
                    self.invalidate_cache(file_path)
                    return {"error": f"Failed to write file: {e}"}
            # Remove internal field from result
            result.pop("_pending_entry", None)
        return result
  • Async wrapper function that serves as the direct MCP tool handler, delegating to the EditTool instance's replace method.
    async def replace_content(file_path: str, path: str, new_content: str):
        return await _instance.replace(file_path, path, new_content)
  • JSON Schema definitions for input parameters (file_path, path, new_content) and output (success boolean) of the replace_content tool.
    Tool(
        name="replace_content",
        title="Replace Block Content",
        description="Overwrites the content of a specific block. Maintains document structure.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {"type": "string", "examples": ["./document.md"]},
                "path": {
                    "type": "string",
                    "examples": [
                        "Introduction > paragraph 1",
                        "Conclusion",
                        "Features > list 2",
                    ],
                },
                "new_content": {
                    "type": "string",
                    "examples": ["Updated paragraph text", "New content here"],
                },
            },
            "required": ["file_path", "path", "new_content"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {"success": {"type": "boolean"}},
        },
    ),
  • Imports the replace_content tool handler along with other edit tools for use in the MCP server.
    from .tools.edit_tools import (
        get_document_structure,
        read_element,
        replace_content,
        insert_element,
        delete_element,
        undo_changes,
        search_in_document,
        get_element_context,
        move_document_element,
        update_document_metadata,
    )
  • Dispatch logic in call_tool that routes replace_content tool calls to the handler function.
    elif name == "replace_content":
        res = await replace_content(
            file_path, arguments["path"], arguments["new_content"]
        )
        return CallToolResult(
            content=[TextContent(type="text", text="Content replaced")],
            structuredContent=res,
            isError="error" in res,
        )
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It states 'Overwrites' (implying mutation) and 'Maintains document structure', but lacks details on permissions, reversibility (e.g., via 'undo'), error handling, or side effects. This is inadequate for a mutation tool with zero annotation coverage.

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 extremely concise with two sentences that are front-loaded and waste no words. Every phrase ('Overwrites the content', 'specific block', 'Maintains document structure') adds value without redundancy.

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 a mutation tool with 3 parameters, 0% schema coverage, no annotations, but an output schema (which reduces need to explain returns), the description is incomplete. It covers the basic purpose but lacks usage guidelines, behavioral details, and parameter semantics, making it minimally viable but with clear 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 0%, so the description must compensate, but it adds no parameter-specific information beyond what the schema's examples imply. The description doesn't explain 'path' semantics or 'new_content' constraints, leaving parameters largely undocumented. Baseline 3 is applied due to the gap.

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 action ('Overwrites') and target ('content of a specific block'), and distinguishes it from siblings like 'update_metadata' or 'insert_element' by focusing on replacement rather than creation or modification of metadata. However, it doesn't explicitly differentiate from 'delete_element' or 'read_element' in terms of scope.

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 'update_metadata', 'insert_element', or 'delete_element'. It mentions maintaining document structure, but doesn't specify prerequisites, exclusions, or contextual cues for selection among sibling tools.

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