Skip to content

fix(filesystem): strip trailing whitespace on write and edits - #4672

Open
nikitagrover19 wants to merge 2 commits into
modelcontextprotocol:mainfrom
nikitagrover19:fix/filesystem-trailing-whitespace
Open

fix(filesystem): strip trailing whitespace on write and edits#4672
nikitagrover19 wants to merge 2 commits into
modelcontextprotocol:mainfrom
nikitagrover19:fix/filesystem-trailing-whitespace

Conversation

@nikitagrover19

Copy link
Copy Markdown

Fixes #1590.

Description

writeFileContent and applyFileEdits now strip trailing horizontal
whitespace before writing. Scoped narrowly:

  • writeFileContent cleans the full content being written.
  • applyFileEdits only cleans the newText an edit introduces — untouched
    lines elsewhere in the file are unaffected.

Server Details

  • Server: filesystem
  • Changes to: tools (write_file, edit_file behavior)

Motivation and Context

Many linters/repos reject trailing whitespace, and the assistant was
producing it on every write, triggering repeated cleanup loops (see #1590).
A similar normalization system was previously removed in b477af5 for being
over-engineered fuzzy matching — this is intentionally much narrower.

How Has This Been Tested?

Added unit tests for stripTrailingWhitespace, writeFileContent, and
applyFileEdits (including a test confirming lines outside an edit are
left untouched). Ran npm test (161/161 passing) and npm run build
(clean) locally.

Breaking Changes

None. No MCP client config changes needed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • New and existing tests pass locally
  • I have added appropriate error handling

nikitagrover19 and others added 2 commits August 20, 2026 13:39
Fixes modelcontextprotocol#1590. writeFileContent and applyFileEdits now strip trailing
horizontal whitespace from content before writing. Scoped narrowly:
writeFileContent cleans the full content being written, while
applyFileEdits only cleans the newText an edit introduces, leaving
untouched lines elsewhere in the file unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Whitespace issues in filesystem server

1 participant