Skip to main content
Glama

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

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, )

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