zk_delete_note
Remove specific notes from the Zettelkasten knowledge management system using the note ID, ensuring efficient organization and maintenance of atomic notes.
Instructions
Delete a note. Args: note_id: The ID of the note to delete
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note_id | Yes |
Implementation Reference
- MCP tool handler implementing zk_delete_note: validates note existence and delegates deletion to ZettelService.def zk_delete_note(note_id: str) -> str: """Permanently delete a note and all its associated links from the Zettelkasten. Args: note_id: The unique ID of the note to permanently delete """ try: # Check if note exists note = self.zettel_service.get_note(note_id) if not note: return f"Note not found: {note_id}" # Delete the note self.zettel_service.delete_note(str(note_id)) return f"Note deleted successfully: {note_id}" except Exception as e: return self.format_error_response(e)
- src/zettelkasten_mcp/server/mcp_server.py:258-265 (registration)Registration of the zk_delete_note tool in the MCP server.name="zk_delete_note", description="Permanently delete a note and all its associated links from the Zettelkasten.", annotations={ "readOnlyHint": False, "destructiveHint": True, "idempotentHint": True, }, )
- ZettelService.delete_note delegates deletion to NoteRepository.def delete_note(self, note_id: str) -> None: """Delete a note.""" self.repository.delete(note_id)
- Core deletion logic in NoteRepository: removes MD file and purges DB records for links, tags, and note.def delete(self, id: str) -> None: """Delete a note by ID.""" # Check if note exists file_path = self.notes_dir / f"{id}.md" if not file_path.exists(): raise ValueError(f"Note with ID {id} does not exist") # Delete from file system try: with self.file_lock: os.remove(file_path) except IOError as e: raise IOError(f"Failed to delete note {id}: {e}") # Delete from database with self.session_factory() as session: # Delete note and its relationships session.execute(text(f"DELETE FROM links WHERE source_id = '{id}' OR target_id = '{id}'")) session.execute(text(f"DELETE FROM note_tags WHERE note_id = '{id}'")) session.execute(text(f"DELETE FROM notes WHERE id = '{id}'")) session.commit()