delete_element
Remove specific blocks from Markdown documents using hierarchical paths to delete elements like sections, paragraphs, or lists without manual text editing.
Instructions
Removes a block from the document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| path | Yes |
Implementation Reference
- Top-level asynchronous handler function for the 'delete_element' MCP tool. Delegates to the singleton EditTool instance's delete method to perform the actual operation.
async def delete_element(file_path: str, path: str): return await _instance.delete(file_path, path) - Core implementation of element deletion within the EditTool class. Loads the document, calls Document.delete(path), performs atomic file write with locking, handles errors with rollback, and updates cache.
async def delete(self, file_path: str, path: str) -> Dict[str, Any]: abs_path = resolve_path(file_path) with FileLock(abs_path): doc = self.get_doc(file_path) result = doc.delete(path) 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 - JSON Schema definition for the 'delete_element' tool, specifying input parameters (file_path: string, path: string) and output (success: boolean). Part of the tools list returned by list_tools().
name="delete_element", title="Delete Block", description="Removes a block from the document.", inputSchema={ "type": "object", "properties": { "file_path": {"type": "string", "examples": ["./document.md"]}, "path": { "type": "string", "examples": [ "Introduction > paragraph 3", "Old Section", "Deprecated > list 1", ], }, }, "required": ["file_path", "path"], "additionalProperties": False, }, outputSchema={ "type": "object", "properties": {"success": {"type": "boolean"}}, }, ), - src/markdown_editor/server.py:629-635 (registration)Registration and dispatch handler in the @app.call_tool() method. Matches tool name 'delete_element', extracts arguments, calls the handler function, and returns MCP CallToolResult.
elif name == "delete_element": res = await delete_element(file_path, arguments["path"]) return CallToolResult( content=[TextContent(type="text", text="Element deleted")], structuredContent=res, isError="error" in res, )