modelcontextprotocol / modelcontextprotocol/servers
edit_file tool fails when exact text match not found due to whitespace differences
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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