write_file
Create or update files for revenue tracking and business management. Automatically creates backups and supports complex multi-location edits within allowed directories.
Instructions
Write or update entire file. Creates backup automatically. Use for complex multi-location edits or new files. Only works in allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | File content to write | |
| path | Yes | Full file path |
Implementation Reference
- index.js:577-594 (registration)Registration of the write_file tool in the ListTools response, including name, description, and input schema definition.{ name: "write_file", description: "Write or update entire file. Creates backup automatically. Use for complex multi-location edits or new files. Only works in allowed directories.", inputSchema: { type: "object", properties: { path: { type: "string", description: "Full file path" }, content: { type: "string", description: "File content to write" } }, required: ["path", "content"] } },
- index.js:826-848 (handler)Handler implementation for write_file tool. Validates path access, creates timestamped backup if file exists, writes new content using fs.writeFileSync, and returns success details.case "write_file": { const { path, content } = args; if (!isPathAllowed(path)) { throw new Error(`Access denied: Path not in allowed directories`); } // Create backup if file exists if (fs.existsSync(path)) { const backupPath = `${path}.backup-${Date.now()}`; fs.copyFileSync(path, backupPath); debugLog(`Created backup: ${backupPath}`); } fs.writeFileSync(path, content, 'utf8'); result = { success: true, path: path, bytesWritten: content.length, message: "File written successfully" }; break; }
- index.js:58-63 (helper)Helper function used by write_file (and other FS tools) to validate if the target path is within allowed directories for security.function isPathAllowed(filePath) { const normalized = filePath.replace(/\//g, '\\'); return ALLOWED_PATHS.some(allowedPath => normalized.startsWith(allowedPath) ); }