delete_note
Remove notes from your Obsidian vault by moving them to trash or deleting permanently to manage your knowledge base and maintain organized content.
Instructions
Delete a note (moves to .trash by default)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| permanent | No |
Implementation Reference
- src/obsidian_mcp/server.py:680-714 (handler)MCP tool handler for 'delete_note' that validates input and calls the vault's delete_note method, handling errors and returning formatted responses.@mcp.tool(name="delete_note", description="Delete a note (moves to .trash by default)") def delete_note(path: str, permanent: bool = False) -> str: """ Delete a note from the vault. Args: path: Relative path to the note permanent: If true, permanently delete; otherwise move to .trash folder Returns: Success message """ if not path or not path.strip(): return "Error: Path cannot be empty" if len(path) > 1000: return "Error: Path too long" context = _get_context() try: context.vault.delete_note(path, use_trash=not permanent) if permanent: return f"✓ Permanently deleted note: {path}" else: return f"✓ Moved note to trash: {path}" except FileNotFoundError: return f"Error: Note not found: {path}" except VaultSecurityError as e: return f"Error: Security violation: {e}" except Exception as e: logger.exception(f"Error deleting note {path}") return f"Error deleting note: {e}"
- src/obsidian_mcp/vault.py:583-620 (helper)Core implementation of note deletion in ObsidianVault class, either moving to .trash or permanent delete with path validation.def delete_note(self, relative_path: str, use_trash: bool = True) -> None: """ Delete a note from the vault. Args: relative_path: Path to the note use_trash: If True, move to .trash folder instead of permanent delete Raises: VaultSecurityError: If path is invalid FileNotFoundError: If note doesn't exist """ file_path = self._validate_path(relative_path) if not file_path.exists(): raise FileNotFoundError(f"Note not found: {relative_path}") if use_trash: # Move to .trash folder at vault root trash_dir = self.vault_path / ".trash" trash_dir.mkdir(exist_ok=True) # Create unique name if needed trash_path = trash_dir / file_path.name counter = 1 while trash_path.exists(): name_parts = file_path.stem, counter, file_path.suffix trash_path = trash_dir / f"{name_parts[0]}.{name_parts[1]}{name_parts[2]}" counter += 1 # Move file file_path.rename(trash_path) logger.info(f"Moved to trash: {relative_path} -> {trash_path.name}") else: # Permanent delete file_path.unlink() logger.info(f"Deleted note: {relative_path}")
- src/obsidian_mcp/server.py:680-680 (registration)MCP tool registration decorator for the delete_note tool.@mcp.tool(name="delete_note", description="Delete a note (moves to .trash by default)")