write_file
Create or update files in an Obsidian vault by writing content. Choose modes: overwrite, append, or prepend. Simplifies file management via REST API.
Instructions
Write file content with different modes: overwrite (default), append, or prepend. Handles both create and update operations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content to write | |
| mode | No | Write mode | overwrite |
| path | Yes | Path to the file |
Implementation Reference
- src/index.ts:116-121 (handler)Core handler function in ObsidianApiClient that executes the write_file tool by making a POST request to the Obsidian REST API's /files/write endpoint.async writeFile(path: string, content: string, mode: string = "overwrite") { return this.request("/files/write", { method: "POST", body: JSON.stringify({ path, content, mode }), }); }
- src/index.ts:301-313 (schema)Schema and definition for the write_file tool, including input schema with parameters path (required), content (required), and mode (optional with enum).{ name: "write_file", description: "Write file content with different modes: overwrite (default), append, or prepend. Handles both create and update operations.", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the file" }, content: { type: "string", description: "Content to write" }, mode: { type: "string", enum: ["overwrite", "append", "prepend"], description: "Write mode", default: "overwrite" }, }, required: ["path", "content"], }, },
- src/index.ts:464-470 (registration)Registration and dispatching logic in the CallToolRequestHandler switch statement that routes write_file tool calls to the client.writeFile method.case "write_file": result = await this.client.writeFile( args?.path as string, args?.content as string, args?.mode as string ); break;