modelcontextprotocol / modelcontextprotocol/servers

edit_file tool fails when exact text match not found due to whitespace differences

Open
#2,034 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug server-filesystem
Dominant language
TypeScript
Stars
90.5k
Forks
11.7k
Avg merge
2d 2h
Merged PRs (30d)
5

Description

Describe the bug
The edit_file tool throws "Could not find exact match for edit" error when the oldText parameter doesn't exactly match the file content, typically due to whitespace, line ending, or formatting differences between expected and actual text.
To Reproduce
Steps to reproduce the behavior:

Use edit_file with oldText parameter containing text that differs in whitespace from actual file content
Tool attempts to find exact match in file
Error occurs: "Could not find exact match for edit"
Edit operation fails completely

Expected behavior
The edit_file tool should either handle minor whitespace differences or provide clear guidance on exact text matching requirements. Alternative: tool should show snippet of actual file content around failed match location.
Logs
Error: Could not find exact match for edit:
[oldText content that failed to match]
Additional context
This occurs frequently when working with code files where whitespace, indentation, or line endings may vary. The tool requires perfect character-by-character matching including all whitespace. Recommendation: always use read_file before edit_file to ensure exact text matching.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the edit_file implementation and trace how it handles exact-match failures; reproduce the issue with whitespace, indentation, and line-ending variations. Clarify whether the intended outcome is tolerant matching, clearer exact-matching guidance, or a context snippet, then add coverage for the selected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.