edit
Replaces exact text in files while preserving original encoding, line endings, and indentation. Supports preview via dry-run and replacing all occurrences for safe, accurate updates.
Instructions
Replaces old_string with new_string in the specified file. Smart indentation: auto-converts between tabs and spaces to match the file's style. Encoding-aware: preserves original file encoding (UTF-8, EUC-KR, Shift-JIS, UTF-8 BOM, etc.). Line-ending aware: matches old_string regardless of CRLF/LF, and inserted lines follow the newline style of the region being edited (mixed-newline files stay intact). Reads .editorconfig for indentation settings. Use dry_run=true to preview changes without modifying the file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Alias for file_path | |
| dry_run | No | Preview changes without modifying the file: true or false. Default: false | |
| file_path | No | File to edit. Relative paths use the configured workspace or MCP client root | |
| new_string | No | Replacement text (must differ from old_string) | |
| old_string | No | Exact text to find in the file | |
| new_content | No | Alias for new_string | |
| old_content | No | Alias for old_string | |
| replace_all | No | Replace all occurrences instead of just the first: true or false. Default: false | |
| indent_style | No | Override indentation style. Values: tabs or spaces-N (e.g. spaces-4). Empty = auto-detect (default) | |
| expected_hash | No | Optional SHA-256 hash of the file. If provided and mismatched, edit is rejected (optimistic concurrency). |