obsidian_rest_request
Send custom GET, POST, PUT, PATCH, or DELETE requests to the Obsidian Local REST API for unsupported operations. Requires OBSIDIAN_API_KEY.
Instructions
Escape hatch for Obsidian Local REST API requests. Requires OBSIDIAN_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | No | GET | |
| path | Yes | ||
| body | No | ||
| contentType | No | ||
| timeoutMs | No |
Implementation Reference
- src/rest.ts:11-56 (handler)The core function that executes the REST request logic: builds URL, sets auth headers, handles body serialization, performs fetch with timeout/abort, and returns parsed response.
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); } } - src/rest.ts:3-9 (schema)Type definition for RestRequestOptions used by the obsidianRestRequest function.
export type RestRequestOptions = { method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; path: string; body?: unknown; contentType?: string; timeoutMs?: number; }; - src/tools.ts:1193-1205 (registration)Registration of the 'obsidian_rest_request' tool with its schema (method, path, body, contentType, timeoutMs) and handler that delegates to obsidianRestRequest(config, args).
tool( "obsidian_rest_request", "Escape hatch for Obsidian Local REST API requests. Requires OBSIDIAN_API_KEY.", { method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional().default("GET"), path: z.string(), body: z.unknown().optional(), contentType: z.string().optional(), timeoutMs: z.number().int().min(1000).max(120000).optional().default(15000), }, async (args) => obsidianRestRequest(config, args), { destructiveHint: false }, );