edit_symbol
Replace, insert, or delete Python functions, methods, and classes by name, with previews plus import and error checks.
Instructions
Replace, add or delete a function, method or class by name. Examples:
edit_symbol(action="replace", name="Cart.total", source="def total(self): ..."),
edit_symbol(action="insert", file_path="src/utils.py", name="parse", source="def helper(): ..."),
edit_symbol(action="delete", name="legacy_parse").
action="replace":name(the symbol; dottedClass.methodok) andsource(the complete new definition, decorators included: anything not given is dropped and the result says so). Re-indented to the old one's place, file style kept. A changed signature shows up as errors at call sites; to change a signature and its callers together usechange_signature.action="insert":source(the new definition) andfile_path.positionsays where, relative toname: "after" (default whennameis given) / "before" a symbol defined in the file (a method likeCart.totalplaces it inside that class), "into" a class (appended to its body), or "end" of the file (default withoutname). PEP 8 blank lines, matching indentation. Refuses a name that already exists in that scope (use "replace").action="delete":nameonly. Deletes only when nothing uses it, otherwise lists the users and writes nothing (force=truedeletes anyway and shows what breaks). Imports that are the only remaining users are removed (prune_imports). Uses the type checker cannot see (strings,getattr, docs) are listed and the deletion is previewed. Comments directly above a definition are kept.
file_path narrows name when several symbols share it. imports (replace/insert) is a
list of import statements the new code needs, added if missing. Writes when the new errors
stay within max_new_errors (default 0, null = no limit); else previews with an id for
apply_edit; apply=false always previews. undo_edit reverts.
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": {
"action": "<action>"
},
"name": "edit_symbol"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | ||
| apply | No | ||
| force | No | ||
| action | Yes | ||
| source | No | ||
| imports | No | ||
| position | No | ||
| file_path | No | ||
| prune_imports | No | ||
| max_new_errors | No |