edit_cell_source
Perform a precise find-and-replace in a Jupyter cell's source code, replacing an exact string with another. Supports single or multiple occurrences and shows a diff of changes.
Instructions
Perform a surgical find-and-replace within a cell's source (like an editor's Edit tool).
Finds old_string in the cell and replaces it with new_string. Matching is literal
(not regex) and may span multiple lines. By default, old_string must appear exactly once;
set replace_all=True for multiple occurrences. Returns a diff of the changes made.
Prefer this over overwrite_cell_source for small, targeted edits — it is safer because
unchanged parts of the cell are left untouched. Use read_cell first to see the current
source and construct an accurate old_string.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": {
"cell_index": "<cell_index>",
"old_string": "<old_string>",
"new_string": "<new_string>"
},
"name": "edit_cell_source"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cell_index | Yes | Index of the cell to edit (0-based) | |
| new_string | Yes | Replacement string | |
| old_string | Yes | Exact string to find in cell source | |
| replace_all | No | Replace all occurrences (default: first only) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes | Success message with diff showing changes made |