Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesRelative path to the note
permanentNoIf true, permanently delete instead of moving to trash

Implementation Reference

  • 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);
      }
    }
  • 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)}`);
        }
      },
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rps321321/obsidian-mcp-pro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server