obsidian_delete_active
Delete the currently active note in an Obsidian vault using the Local REST API. Requires a confirmation string 'DELETE' to proceed.
Instructions
Delete the active note through Local REST API. Commands/delete must be explicitly enabled by configuration.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirmation | Yes |
Implementation Reference
- src/tools.ts:1246-1255 (registration)Tool registration for 'obsidian_delete_active' in the registerObsidianTools function. Defines schema (confirmation: 'DELETE') and handler.
tool( "obsidian_delete_active", "Delete the active note through Local REST API. Commands/delete must be explicitly enabled by configuration.", { confirmation: z.literal("DELETE") }, async () => { if (!config.enableCommands) throw new Error("Set OBSIDIAN_ENABLE_COMMANDS=1 to enable active-note delete."); return obsidianRestRequest(config, { method: "DELETE", path: "/active/" }); }, { destructiveHint: true }, ); - src/tools.ts:1247-1255 (handler)Handler function for obsidian_delete_active: checks enableCommands config, then sends DELETE request to /active/ via obsidianRestRequest.
"obsidian_delete_active", "Delete the active note through Local REST API. Commands/delete must be explicitly enabled by configuration.", { confirmation: z.literal("DELETE") }, async () => { if (!config.enableCommands) throw new Error("Set OBSIDIAN_ENABLE_COMMANDS=1 to enable active-note delete."); return obsidianRestRequest(config, { method: "DELETE", path: "/active/" }); }, { destructiveHint: true }, ); - src/tools.ts:1249-1249 (schema)Input schema for obsidian_delete_active: requires confirmation field with literal 'DELETE' value.
{ confirmation: z.literal("DELETE") }, - src/rest.ts:11-62 (helper)obsidianRestRequest helper function that performs the actual HTTP DELETE request to the Obsidian Local REST API.
export async function obsidianRestRequest(config: ObsidianMcpConfig, options: RestRequestOptions): Promise<{ status: number; ok: boolean; contentType: string; body: unknown; }> { if (!config.restApiKey) throw new Error("OBSIDIAN_API_KEY is not configured"); if (config.restInsecureTls) process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; const url = new URL(options.path.replace(/^\/+/, ""), `${config.restUrl.replace(/\/+$/, "")}/`); const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? 15000); try { const headers: Record<string, string> = { Authorization: `Bearer ${config.restApiKey}`, }; let body: string | undefined; if (options.body !== undefined) { if (typeof options.body === "string") { body = options.body; headers["Content-Type"] = options.contentType ?? "text/markdown"; } else { body = JSON.stringify(options.body); headers["Content-Type"] = options.contentType ?? "application/json"; } } const response = await fetch(url, { method: options.method ?? "GET", headers, body, signal: controller.signal, }); const contentType = response.headers.get("content-type") ?? ""; const text = await response.text(); let parsed: unknown = text; if (contentType.includes("application/json")) { try { parsed = JSON.parse(text); } catch { parsed = text; } } return { status: response.status, ok: response.ok, contentType, body: parsed }; } finally { clearTimeout(timeout); } } export async function getRestText(config: ObsidianMcpConfig, path: string): Promise<string> { const response = await obsidianRestRequest(config, { path }); if (!response.ok) throw new Error(`Obsidian REST returned ${response.status}: ${String(response.body)}`); return typeof response.body === "string" ? response.body : JSON.stringify(response.body); } - src/config.ts:21-22 (helper)enableCommands config field in ObsidianMcpConfig type, used by the handler to gate active-note delete functionality.
enableCommands: boolean; enableUiOpen: boolean;