Skip to content

Commit 8decb40

Browse files
authored
Merge pull request #5022 from modelcontextprotocol/v2/fix/4512-filesystem-in-place-write
fix(filesystem): overwrite existing files in place (#4512, #3199)
2 parents f6f23d3 + b3310ab commit 8decb40

6 files changed

Lines changed: 375 additions & 193 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-filesystem": patch
3+
---
4+
5+
`write_file` and `edit_file` now overwrite an existing file in place instead of renaming a temp file over it, so the file keeps its inode, creation time (birthtime), hard links and permission bits (#4512), and an overwrite no longer fails with `EPERM` on Windows when another process holds the file open (#3199). A symlink swapped in after the path was validated is still refused rather than written through, now by an `O_NOFOLLOW` open (on POSIX) and a check that the opened file is the one validated (on every platform). The overwrite is no longer crash-atomic. A read-only file is now refused (`EACCES`, or `EPERM` on Windows) instead of being replaced, since writing in place opens the file itself for writing.

‎src/filesystem/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ The server's directory access control follows this flow:
9797
- Inputs:
9898
- `path` (string): File location
9999
- `content` (string): File content
100+
- An existing file is overwritten in place, so it keeps its inode, creation
101+
time, hard links and permissions (`edit_file` writes the same way). The
102+
overwrite is not crash-atomic: a crash mid-write can leave the file partly
103+
written. A read-only file is refused rather than replaced
100104

101105
- **edit_file**
102106
- Make selective edits using advanced pattern matching and formatting

0 commit comments

Comments
 (0)