replace_in_file
Performs targeted text replacement in remote files without reading entire content. Includes dry-run preview and errors when the exact text isn't found.
Instructions
Replace a specific text passage in a remote file without loading the full content. Preferred over write_file for editing large files. Returns error if old_text not found. Supports dry_run preview.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"server": "<server>",
"path": "<path>",
"old_text": "<old_text>",
"new_text": "<new_text>"
},
"name": "replace_in_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path | |
| count | No | Max replacements (default: 1, 0 = all) | |
| reason | No | Human-readable explanation of what is being changed and why (for audit log) | |
| server | Yes | Server name | |
| dry_run | No | Preview changes without applying | |
| new_text | Yes | Replacement text | |
| old_text | Yes | Exact text to find (multi-line supported) |