write_file
Write or update files for revenue tracking and business management, automatically creating backups for complex edits or new files in 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 |
|---|---|---|---|
| path | Yes | Full file path | |
| content | Yes | File content to write |
Implementation Reference
- index.js:826-847 (handler)Handler for the 'write_file' tool. Validates the path is in allowed directories, creates a timestamped backup if the file exists, writes the new content using fs.writeFileSync, and returns a success response with file 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:577-594 (registration)Registration of the 'write_file' tool in the ListTools response, including name, description, and input schema requiring 'path' and 'content'.{ 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:58-63 (helper)Helper function used by write_file (and other FS tools) to validate if the file path is within the allowed directories defined in ALLOWED_PATHS.function isPathAllowed(filePath) { const normalized = filePath.replace(/\//g, '\\'); return ALLOWED_PATHS.some(allowedPath => normalized.startsWith(allowedPath) ); }
- index.js:29-33 (helper)Configuration array defining the allowed directories for file operations, used by isPathAllowed helper.const ALLOWED_PATHS = [ 'C:\\Users\\Node1\\revenue-engine-mcp', 'C:\\Users\\Node1\\Documents\\revenue-engine\\mcp-server', 'C:\\Users\\Node1\\Documents\\revenue-engine\\apps-script', ];