delete_note
Remove notes from Obsidian vaults by specifying file paths, with options to move to trash or delete permanently.
Instructions
Delete a note (moves to vault trash by default)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Relative path to the note | |
| permanent | No | If true, permanently delete instead of moving to trash |
Implementation Reference
- src/lib/vault.ts:120-140 (handler)The actual implementation of note deletion, handling both trash-moving and permanent deletion logic.
export async function deleteNote( vaultPath: string, relativePath: string, useTrash = true, ): Promise<void> { const fullPath = resolveVaultPath(vaultPath, relativePath); if (useTrash) { const trashDir = path.join(vaultPath, ".trash"); const trashPath = path.join(trashDir, relativePath); const resolvedTrash = path.resolve(trashPath); const resolvedTrashDir = path.resolve(trashDir); if (!resolvedTrash.startsWith(resolvedTrashDir + path.sep) && resolvedTrash !== resolvedTrashDir) { throw new Error(`Invalid trash path: ${relativePath}`); } await fs.mkdir(path.dirname(trashPath), { recursive: true }); await fs.rename(fullPath, trashPath); } else { await fs.unlink(fullPath); } } - src/tools/write.ts:263-289 (registration)Registration and handler wrapper for the "delete_note" tool within the MCP server setup.
// 7. delete_note server.registerTool( "delete_note", { description: "Delete a note (moves to vault trash by default)", inputSchema: { path: z.string().min(1).describe("Relative path to the note"), permanent: z .boolean() .optional() .default(false) .describe("If true, permanently delete instead of moving to trash"), }, }, async ({ path: notePath, permanent }) => { try { const resolvedPath = ensureMdExtension(notePath); const useTrash = !permanent; await deleteNote(vaultPath, resolvedPath, useTrash); const method = useTrash ? "moved to trash" : "permanently deleted"; return textResult(`Note '${resolvedPath}' ${method}.`); } catch (err) { console.error("delete_note error:", err); return errorResult(`Error deleting note: ${err instanceof Error ? err.message : String(err)}`); } }, );