fix(filesystem): handle Windows EPERM when renaming over locked files#3296
Open
MattBenesch wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(filesystem): handle Windows EPERM when renaming over locked files#3296MattBenesch wants to merge 1 commit intomodelcontextprotocol:mainfrom
MattBenesch wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
On Windows, fs.rename() fails with EPERM when the target file is locked by another process (e.g., open in an editor). This adds a fallback that uses fs.cp() + fs.unlink() when EPERM is encountered, allowing edits to succeed even when the file is open. Fixes modelcontextprotocol#3199
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, fs.rename() fails with EPERM when the target file is locked by another process (e.g., open in an editor). This adds a fallback that uses fs.cp() + fs.unlink() when EPERM is encountered, allowing edits to succeed even when the file is open.
Fixes #3199
Description
Adds atomicReplaceFile() helper that falls back to fs.cp() when fs.rename() fails with EPERM.
Publishing Your Server
Note: We are no longer accepting PRs to add servers to the README. Instead, please publish your server to the MCP Server Registry to make it discoverable to the MCP ecosystem.
To publish your server, follow the quickstart guide. You can browse published servers at https://registry.modelcontextprotocol.io/.
Server Details
Motivation and Context
On Windows, files open in editors (VS Code, Notepad, etc.) are locked. The current fs.rename() approach fails with EPERM when trying to atomically replace these locked files. This prevents users from editing files they have open.
How Has This Been Tested?
Unit tests added for EPERM fallback behavior. All 46 lib.test.ts tests pass.
Breaking Changes
None - existing behavior unchanged on Linux/macOS. Windows users will now have edits succeed where they previously failed.
Types of changes
Checklist
Additional context