edit_file
Modify and review text in Obsidian vault files stored in iCloud Drive. Preview changes with dry-run mode; original files update only after user confirmation. Works within specified directories.
Instructions
Edit a specific file under /Users/username/Library/Mobile Documents/iCloud~md~obsidian/Documents/my-vault. Display the modified content to the user for review; the original file will only be updated upon user confirmation. Only works within allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dryRun | No | Preview changes before real editing. | |
| newText | Yes | ||
| path | Yes |
Implementation Reference
- src/file-system.ts:251-264 (handler)The editFile function implements the core logic of the 'edit_file' tool: validates input with EditFileArgsSchema, writes new content to the file unless dryRun is true, and returns the new text.export async function editFile(args?: Record<string, unknown>) { const parsed = EditFileArgsSchema.safeParse(args) if (!parsed.success) { throw new Error(`Invalid arguments for edit_file: ${parsed.error}`) } if (!parsed.data.dryRun) { await fs.writeFile(parsed.data.path, parsed.data.newText) } return { content: [{ type: 'text', text: parsed.data.newText }] } }
- src/schemas.ts:25-32 (schema)Zod schema for EditFileArgsSchema defining path (string), newText (string), and optional dryRun (boolean).export const EditFileArgsSchema = z.object({ path: z.string(), newText: z.string(), dryRun: z .boolean() .default(false) .describe('Preview changes before real editing.') })
- src/index.ts:116-118 (registration)Registers the 'edit_file' tool in the ListToolsRequest handler with name, dynamic description from editFilePrompt, and input schema converted to JSON schema.name: 'edit_file', description: editFilePrompt(args), inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput
- src/index.ts:183-185 (registration)In the CallToolRequest switch statement, routes calls to 'edit_file' to the editFile handler function.case 'edit_file': { return editFile(args) }