obsidian_delete_file
Remove files or directories from an Obsidian vault by specifying the filepath and confirming the deletion. Part of the Advanced Obsidian MCP Server for vault management tasks.
Instructions
Delete a file or directory from the vault.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | Yes | Confirmation to delete the file (must be true) | |
| filepath | Yes | Path to the file or directory to delete (relative to vault root) |
Implementation Reference
- The run_tool method in DeleteFileToolHandler class that implements the core logic of the obsidian_delete_file tool: validates arguments, calls api.delete_file, and returns success message.def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if "filepath" not in args: raise RuntimeError("filepath argument missing in arguments") if not args.get("confirm", False): raise RuntimeError("confirm must be set to true to delete a file") api.delete_file(args["filepath"]) return [ TextContent( type="text", text=f"Successfully deleted {args['filepath']}" ) ]
- The get_tool_description method defining the input schema for the obsidian_delete_file tool, requiring filepath and confirm boolean.def get_tool_description(self): return Tool( name=self.name, description="Delete a file or directory from the vault.", inputSchema={ "type": "object", "properties": { "filepath": { "type": "string", "description": "Path to the file or directory to delete (relative to vault root)", "format": "path" }, "confirm": { "type": "boolean", "description": "Confirmation to delete the file (must be true)", "default": False } }, "required": ["filepath", "confirm"] } )
- src/mcp_obsidian_advanced/server.py:25-43 (registration)TOOL_MAPPING dictionary registers 'obsidian_delete_file' (TOOL_DELETE_FILE) to DeleteFileToolHandler class, used in register_tools() to instantiate and add to the MCP server.# Tool mapping between tool constants and their handler classes TOOL_MAPPING = { tools.TOOL_LIST_FILES_IN_DIR: tools.ListFilesInDirToolHandler, tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler, tools.TOOL_PATCH_CONTENT: tools.PatchContentToolHandler, tools.TOOL_PUT_CONTENT: tools.PutContentToolHandler, tools.TOOL_APPEND_CONTENT: tools.AppendContentToolHandler, tools.TOOL_DELETE_FILE: tools.DeleteFileToolHandler, tools.TOOL_COMPLEX_SEARCH: tools.ComplexSearchToolHandler, tools.TOOL_BATCH_GET_FILES: tools.BatchGetFilesToolHandler, tools.TOOL_PERIODIC_NOTES: tools.PeriodicNotesToolHandler, tools.TOOL_RECENT_PERIODIC_NOTES: tools.RecentPeriodicNotesToolHandler, tools.TOOL_RECENT_CHANGES: tools.RecentChangesToolHandler, tools.TOOL_UNDERSTAND_VAULT: tools.UnderstandVaultToolHandler, tools.TOOL_GET_ACTIVE_NOTE: tools.GetActiveNoteToolHandler, tools.TOOL_OPEN_FILES: tools.OpenFilesToolHandler, tools.TOOL_LIST_COMMANDS: tools.ListCommandsToolHandler, tools.TOOL_EXECUTE_COMMANDS: tools.ExecuteCommandsToolHandler, }
- The Obsidian API client method delete_file that sends HTTP DELETE request to Obsidian's REST API to remove the specified file or directory.def delete_file(self, filepath: str) -> Any: """Delete a file or directory from the vault. Args: filepath: Path to the file to delete (relative to vault root) Returns: None on success """ url = f"{self.get_base_url()}/vault/{filepath}" def call_fn(): response = requests.delete(url, headers=self._get_headers(), verify=self.verify_ssl, timeout=self.timeout) response.raise_for_status() return None return self._safe_call(call_fn)
- src/mcp_obsidian_advanced/server.py:95-108 (registration)register_tools function iterates over tools (including obsidian_delete_file if selected), instantiates the handler from TOOL_MAPPING, and adds it to tool_handlers for MCP server registration.def register_tools(): """Register the selected tools with the server.""" tools_to_include = parse_include_tools() registered_count = 0 for tool_name in tools_to_include: if tool_name in TOOL_MAPPING: handler_class = TOOL_MAPPING[tool_name] handler_instance = handler_class() add_tool_handler(handler_instance) registered_count += 1 logger.debug(f"Registered tool: {tool_name}") logger.info(f"Successfully registered {registered_count} tools")