write_file
Create or modify files in Obsidian vaults by writing content with options to overwrite, append, or prepend text to existing files.
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 |
|---|---|---|---|
| path | Yes | Path to the file | |
| content | Yes | Content to write | |
| mode | No | Write mode | overwrite |
Implementation Reference
- src/index.ts:116-121 (handler)Core handler function in ObsidianApiClient that performs the HTTP POST request to the Obsidian REST API's /files/write endpoint, passing path, content, and mode parameters to write or update the file.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)Input schema and metadata definition for the write_file tool, including required path and content, optional mode (overwrite/append/prepend), description, and name.{ 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 CallToolRequestSchema handler's switch statement, which maps incoming write_file tool calls to the client.writeFile execution.case "write_file": result = await this.client.writeFile( args?.path as string, args?.content as string, args?.mode as string ); break;