Skip to content

fix(filesystem): add guidance for failed edit matches#4501

Open
Joosboy wants to merge 1 commit into
modelcontextprotocol:mainfrom
Joosboy:improve-edit-file-no-match-guidance
Open

fix(filesystem): add guidance for failed edit matches#4501
Joosboy wants to merge 1 commit into
modelcontextprotocol:mainfrom
Joosboy:improve-edit-file-no-match-guidance

Conversation

@Joosboy

@Joosboy Joosboy commented Jul 9, 2026

Copy link
Copy Markdown

Description

Improves the filesystem server's edit_file failure message when an edit cannot be matched. The error now keeps the original failed oldText context and adds a short hint to inspect the current file contents with read_file before retrying.

Server Details

  • Server: filesystem
  • Changes to: edit_file error handling and unit tests

Motivation and Context

When oldText does not match the current file contents, the previous error only reported that no exact match was found. Issue #2034 describes this as difficult to recover from when the mismatch is caused by whitespace, indentation, or line-ending differences.

This keeps the edit behavior unchanged and makes the failure easier to act on.

Refs #2034.

How Has This Been Tested?

  • npm test --workspace @modelcontextprotocol/server-filesystem -- __tests__/lib.test.ts
  • npm run build --workspace @modelcontextprotocol/server-filesystem

Breaking Changes

No breaking changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

The README and environment-variable checklist items are not applicable because this only changes an existing runtime error message and its test coverage.

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.

1 participant