-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The filesystem_edit_file MCP tool failed on Windows operating systems with the following error:
To Reproduce
Steps to reproduce the behavior:
- Create a text file
test.txtwith some content - Open the file in a text editor (e.g., VS Code, Notepad) - this adds a file read lock
- Attempt to run the following Node.js script to overwrite the file:
import fs from "fs/promises";
import { randomBytes } from 'crypto';
const filePath = './test.txt';
const tempPath = `${filePath}.${randomBytes(16).toString('hex')}.tmp`;
async function editFile() {
await fs.writeFile(tempPath, 'updated content', 'utf-8');
await fs.rename(tempPath, filePath); // Throws EPERM on Windows
}
editFile();- Observe the
EPERMerror
Expected behavior
The tool should successfully overwrite files on Windows, just as it does on Linux and macOS platforms.
Logs
Error: EPERM: operation not permitted, rename 'C:\test.txt.abc123.tmp' -> 'C:\test.txt'.
Additional context
On Windows, fs.rename() cannot overwrite existing files when the file is locked (e.g., opened in an editor), resulting in EPERM error. This is a Windows-specific limitation of the Node.js fs.rename() function.
Solution Applied
Replaced fs.rename() with fs.cp() which supports the force: true option to overwrite existing files:
const tempPath = `${filePath}.${randomBytes(16).toString('hex')}.tmp`;
try {
await fs.writeFile(tempPath, modifiedContent, 'utf-8');
// Use cp with force option - works on all platforms including Windows
await fs.cp(tempPath, filePath, { force: true });
} finally {
try {
await fs.unlink(tempPath);
} catch {}
}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working