edit_file_at_line
Modify text files by editing specific lines with actions like replace, insert, or delete, enabling precise content changes while supporting verification, offsets, and dry runs for accuracy and control.
Instructions
Edit specific lines in a text file.
Args:
path: Path to the file
line_edits: List of edits to apply. Each edit is a dict with:
- line_number: Line number to edit (0-based if relative_line_numbers=True, otherwise 1-based)
- action: "replace", "insert_before", "insert_after", "delete"
- content: New content for replace/insert operations (optional for delete)
- expected_content: (Optional) Expected content of the line being edited for verification
offset: Line offset (0-based) to start considering lines
limit: Maximum number of lines to consider
relative_line_numbers: Whether line numbers in edits are relative to offset
abort_on_verification_failure: Whether to abort all edits if any verification fails
encoding: Text encoding (default: utf-8)
dry_run: If True, returns what would be changed without modifying the file
ctx: MCP context
Returns:
Edit results summary
Input Schema
Name | Required | Description | Default |
---|---|---|---|
abort_on_verification_failure | No | ||
dry_run | No | ||
encoding | No | utf-8 | |
limit | No | ||
line_edits | Yes | ||
offset | No | ||
path | Yes | ||
relative_line_numbers | No |
Input Schema (JSON Schema)
{
"properties": {
"abort_on_verification_failure": {
"default": false,
"title": "Abort On Verification Failure",
"type": "boolean"
},
"dry_run": {
"default": false,
"title": "Dry Run",
"type": "boolean"
},
"encoding": {
"default": "utf-8",
"title": "Encoding",
"type": "string"
},
"limit": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Limit"
},
"line_edits": {
"items": {
"type": "object"
},
"title": "Line Edits",
"type": "array"
},
"offset": {
"default": 0,
"title": "Offset",
"type": "integer"
},
"path": {
"title": "Path",
"type": "string"
},
"relative_line_numbers": {
"default": false,
"title": "Relative Line Numbers",
"type": "boolean"
}
},
"required": [
"path",
"line_edits"
],
"title": "edit_file_at_lineArguments",
"type": "object"
}