Repository navigation
Commit a149ec5
committed
fix(filesystem): verify write_file output landed on disk (modelcontextprotocol#4138)
write_file in the filesystem server resolved successfully even when no
bytes reached disk on Windows. Callers (Claude Desktop and any other MCP
client) received "File created successfully" and a normal structured
result, with no way to detect that the file was never written.
Reported in modelcontextprotocol#4138 against Windows 11 with both isUsingBuiltInNodeForMcp
and system Node. Repro ruled out NTFS permissions, Defender, Controlled
Folder Access, OneDrive, and paths-with-spaces. The same paths work for
edit_file, read_file, and list_directory; only write_file silently
no-ops.
The host-side root cause varies by environment and isn't fully nailed
down, but the failure mode is consistent: fs.writeFile resolves with no
error and nothing is on disk afterward. Rather than chase the host
layer, this change closes the gap at the boundary we control by adding
a post-write verification step to writeFileContent:
1. fs.stat the target file after the write completes.
2. Compare on-disk size to Buffer.byteLength(content, 'utf-8').
3. Throw an explicit error on miss / mismatch.
This converts the silent-success failure mode into a clear "write
reported success but the file is missing on disk" error that callers
can surface to the user instead of returning a false-positive success.
The verification runs for both the fresh-write (wx flag) and atomic-
rename (EEXIST) branches.
The fix is platform-agnostic: silent success is a bad failure mode on
any OS, and the same verification protects against partial writes,
antivirus quarantine mid-write, and rename-to-wrong-path bugs in
addition to the original Windows symptom.
Cost is one extra stat per write_file call.
Rebased onto current main. The two modelcontextprotocol#4115 permission tests mock a single
fs.stat for the permission read; they now also mock the verification
stat, since writeFileContent stats the target a second time.1 parent d73f99e commit a149ec5
2 files changed
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
| 349 | + | |
349 | 350 | | |
350 | | - | |
| 351 | + | |
351 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
352 | 385 | | |
353 | 386 | | |
354 | 387 | | |
| |||
360 | 393 | | |
361 | 394 | | |
362 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
363 | 399 | | |
364 | 400 | | |
365 | 401 | | |
| |||
373 | 409 | | |
374 | 410 | | |
375 | 411 | | |
| 412 | + | |
376 | 413 | | |
377 | 414 | | |
378 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
237 | 259 | | |
238 | 260 | | |
239 | 261 | | |
| |||
0 commit comments