obsidian_put_active
Replace the body of the currently active note in Obsidian with new content. Uses the local REST API to update the note.
Instructions
Replace the currently active note body through Local REST API.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes |
Implementation Reference
- src/tools.ts:1222-1228 (registration)Registration of the 'obsidian_put_active' tool in registerObsidianTools(). Defines schema (content: string) and handler that calls obsidianRestRequest with PUT method to /active/.
tool( "obsidian_put_active", "Replace the currently active note body through Local REST API.", { content: z.string() }, async (args) => obsidianRestRequest(config, { method: "PUT", path: "/active/", body: args.content, contentType: "text/markdown" }), { destructiveHint: true }, ); - src/tools.ts:1226-1227 (handler)The handler function for obsidian_put_active. Sends a PUT request to the Obsidian Local REST API /active/ endpoint with the provided content as text/markdown.
async (args) => obsidianRestRequest(config, { method: "PUT", path: "/active/", body: args.content, contentType: "text/markdown" }), { destructiveHint: true }, - src/tools.ts:1224-1225 (schema)Input schema for obsidian_put_active: requires a single 'content' string field.
"Replace the currently active note body through Local REST API.", { content: z.string() }, - src/rest.ts:11-62 (helper)The obsidianRestRequest function that executes the actual HTTP request to the Obsidian Local REST API. Used by the obsidian_put_active handler.
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); }