String Replace in File
fc_str_replaceReplaces a unique string in a file with another string, ensuring exact single occurrence and returning an error for zero or multiple matches.
Instructions
Replaces a unique string in a file with another.
Args:
path (string): Path to the file
old_str (string): String to replace (must occur exactly once)
new_str (string): New string (empty = delete)
Returns:
Confirmation with context
IMPORTANT: old_str must occur EXACTLY once in the file! An error is returned for 0 or >1 occurrences.
Examples:
Rename function: old_str="def old_name", new_str="def new_name"
Add import: old_str="import os", new_str="import os\nimport sys"
Delete line: old_str="# TODO: remove this\n", new_str=""
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": {
"path": "<path>",
"old_str": "<old_str>"
},
"name": "fc_str_replace"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file | |
| new_str | No | New string (empty = delete) | |
| old_str | Yes | String to replace (must be unique) |