update_file
Modify file content by performing targeted search-and-replace operations using specified search-replace blocks. Supports regex and multiple replacements for precise, localized updates.
Instructions
Performs targeted search-and-replace operations within an existing file using an array of {search, replace} blocks. Preferred for smaller, localized changes. For large-scale updates or overwrites, consider using write_file
. Accepts relative or absolute paths. File must exist. Supports optional useRegex
(boolean, default false) and replaceAll
(boolean, default false).
Input Schema
Name | Required | Description | Default |
---|---|---|---|
blocks | Yes | An array of objects, each with a `search` (string) and `replace` (string) property. | |
path | Yes | The path to the file to update. Can be relative or absolute (resolved like readFile). The file must exist. | |
replaceAll | No | If true, replace all occurrences matching the SEARCH criteria within the file. If false, only replace the first occurrence. Defaults to false. | |
useRegex | No | If true, treat the `search` field of each block as a JavaScript regular expression pattern. Defaults to false (exact string matching). |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"blocks": {
"description": "An array of objects, each with a `search` (string) and `replace` (string) property.",
"items": {
"additionalProperties": false,
"properties": {
"replace": {
"type": "string"
},
"search": {
"minLength": 1,
"type": "string"
}
},
"required": [
"search",
"replace"
],
"type": "object"
},
"minItems": 1,
"type": "array"
},
"path": {
"description": "The path to the file to update. Can be relative or absolute (resolved like readFile). The file must exist.",
"minLength": 1,
"type": "string"
},
"replaceAll": {
"default": false,
"description": "If true, replace all occurrences matching the SEARCH criteria within the file. If false, only replace the first occurrence. Defaults to false.",
"type": "boolean"
},
"useRegex": {
"default": false,
"description": "If true, treat the `search` field of each block as a JavaScript regular expression pattern. Defaults to false (exact string matching).",
"type": "boolean"
}
},
"required": [
"path",
"blocks"
],
"type": "object"
}