Skip to main content
Glama
KazKozDev
by KazKozDev

Move Structural Block

move_element

Move document sections or elements to new positions in Markdown files using hierarchical paths. Specify source and target locations to reorganize content structure.

Instructions

Moves an element (and its children) to a new location in the document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
source_pathYes
target_pathYes
whereNoafter

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successNo

Implementation Reference

  • Core handler implementing the logic to move an element from source_path to target_path (before/after) in the document structure, updating the element tree and raw content.
    def move_element(
        self, src_path: str, dst_path: str, where: str = "after"
    ) -> Dict[str, Any]:
        """Move element"""
        src = self.find_by_path(src_path)
        dst = self.find_by_path(dst_path)
    
        if not src or not dst:
            return {"error": "Source or target path not found"}
    
        # Remove from old location
        if src.parent:
            src.parent.children.remove(src)
        else:
            self.elements.remove(src)
    
        # Insert into new one
        if dst.parent:
            siblings = dst.parent.children
            idx = siblings.index(dst)
            if where == "after":
                siblings.insert(idx + 1, src)
            else:
                siblings.insert(idx, src)
            src.parent = dst.parent
        else:
            idx = self.elements.index(dst)
            if where == "after":
                self.elements.insert(idx + 1, src)
            else:
                self.elements.insert(idx, src)
            src.parent = None
    
        self._rebuild_raw_content()
        return {"success": True, "new_path": src.path}
  • MCP tool registration for 'move_element', defining title, description, input schema (file_path, source_path, target_path, where), and output schema.
    Tool(
        name="move_element",
        title="Move Structural Block",
        description="Moves an element (and its children) to a new location in the document.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {"type": "string", "examples": ["./document.md"]},
                "source_path": {
                    "type": "string",
                    "examples": ["Old Section", "Introduction > paragraph 2"],
                },
                "target_path": {
                    "type": "string",
                    "examples": ["Conclusion", "Features"],
                },
                "where": {
                    "type": "string",
                    "enum": ["before", "after"],
                    "default": "after",
                    "examples": ["after", "before"],
                },
            },
            "required": ["file_path", "source_path", "target_path"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {"success": {"type": "boolean"}},
        },
    ),
  • Helper wrapper that applies file locking, calls the core move_element, handles atomic write to file, updates cache, and confirms journal entry.
    async def move(
        self, file_path: str, src_path: str, dst_path: str, where: str = "after"
    ) -> Dict[str, Any]:
        abs_path = resolve_path(file_path)
        with FileLock(abs_path):
            doc = self.get_doc(file_path)
            result = doc.move_element(src_path, dst_path, where)
            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:
                    self.invalidate_cache(file_path)
                    return {"error": f"Failed to write file: {e}"}
        return result
  • Dispatch handler in MCP call_tool function that routes 'move_element' calls to the move_document_element wrapper, returning structured result.
    elif name == "move_element":
        res = await move_document_element(
            file_path,
            arguments["source_path"],
            arguments["target_path"],
            arguments.get("where", "after"),
        )
        return CallToolResult(
            content=[TextContent(type="text", text="Element moved")],
            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 the full burden of behavioral disclosure. It mentions moving 'an element (and its children)', implying hierarchical effects, but fails to detail critical traits like whether the operation is destructive (e.g., overwrites target), requires specific permissions, or has side effects like updating references. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 and resource. Every word earns its place by specifying the move operation, the element scope (including children), and the destination context, with no redundant or vague phrasing.

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 the tool's complexity (a mutation with 4 parameters) and the presence of an output schema (which alleviates need to explain return values), the description is minimally adequate. However, with no annotations and low schema coverage, it lacks completeness in behavioral and parameter details, making it just sufficient for basic understanding but insufficient for robust agent decision-making.

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?

The description adds no specific meaning beyond the input schema, which has 0% description coverage. It implies parameters for source, target, and file context but doesn't explain semantics like path formats or the 'where' enum's effect. With low schema coverage, the description fails to compensate, resulting in a baseline score due to the lack of parameter details in either source.

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 ('Moves'), the resource ('an element (and its children)'), and the context ('to a new location in the document'). It distinguishes from siblings like 'delete_element' or 'insert_element' by specifying relocation rather than removal or addition. However, it doesn't explicitly differentiate from 'replace_content' which might involve movement, keeping it from a perfect score.

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 'insert_element' for adding new content or 'delete_element' for removal. It lacks context on prerequisites, such as needing an existing element to move, or exclusions, like not being suitable for non-structural changes. This leaves the agent with minimal usage direction.

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