delete_note
Remove a note from the Obsidian vault by specifying its path, enabling direct management of notes through the MCP server for efficient knowledge base organization.
Instructions
Delete a note from the Obsidian vault
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the note within the vault |
Implementation Reference
- src/index.ts:1117-1130 (registration)Registration of the 'delete_note' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.{ name: 'delete_note', description: 'Delete a note from the Obsidian vault', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the note within the vault', }, }, required: ['path'], }, },
- src/index.ts:1494-1509 (handler)The main handler function for the 'delete_note' tool that validates the input arguments and delegates to the deleteNote method.private async handleDeleteNote(args: any) { if (!args?.path) { throw new Error('Path is required'); } await this.deleteNote(args.path); return { content: [ { type: 'text', text: `Note deleted successfully: ${args.path}`, }, ], }; }
- src/index.ts:2322-2347 (handler)Core implementation of note deletion using Obsidian API with filesystem fallback, including cleanup of empty parent directories.private async deleteNote(notePath: string): Promise<void> { try { // First try using the Obsidian API await this.api.delete(`/vault/${encodeURIComponent(notePath)}`); } catch (error) { console.warn('API request failed, falling back to file system:', error); // Fallback to file system if API fails const fullPath = path.join(VAULT_PATH, notePath); if (!fs.existsSync(fullPath)) { throw new Error(`Note not found: ${notePath}`); } fs.unlinkSync(fullPath); // Check if parent directory is empty and remove it if it is const dir = path.dirname(fullPath); if (dir !== VAULT_PATH) { const items = fs.readdirSync(dir); if (items.length === 0) { fs.rmdirSync(dir); } } } }
- src/index.ts:1121-1129 (schema)Input schema definition for the 'delete_note' tool specifying the required 'path' parameter.type: 'object', properties: { path: { type: 'string', description: 'Path to the note within the vault', }, }, required: ['path'], },