patch_file
Apply a targeted edit to an existing project file by replacing the first occurrence of an exact old string with a new string. Use this instead of write_file to modify large files without rewriting the entire file.
Instructions
Apply a targeted edit to an existing project file without rewriting the entire file. Finds the first occurrence of old_string and replaces it with new_string. Use this instead of write_file when modifying large files (e.g. HTML) — you only send the changed portion, not the whole file.
The old_string must match exactly (including whitespace). If it's not found, the tool returns an error. To insert at a specific position, use a nearby string as old_string and include it in new_string with your addition.
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": {
"project_id": "<project_id>",
"path": "<path>",
"old_string": "<old_string>",
"new_string": "<new_string>"
},
"name": "patch_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID (e.g. proj_a8Kq7fR2xZ) | |
| path | Yes | File path relative to project root | |
| old_string | Yes | Exact string to find and replace | |
| new_string | Yes | Replacement string |