Edits source code via Serena MCP server using symbol-aware and regex-based tools. Use for replacing symbol bodies, inserting code before/after symbols, renaming symbols across the codebase, or doing targeted regex/literal replacements within files.
| Tool | Purpose |
|---|---|
replace_content | Replace text in a file via literal string or regex (Python re, DOTALL + MULTILINE) |
replace_symbol_body | Replace the entire definition of a symbol |
insert_after_symbol | Insert code immediately after a symbol's definition |
insert_before_symbol | Insert code immediately before a symbol's definition |
rename_symbol | Rename a symbol everywhere in the codebase via LSP |
Serena provides two approaches. Choose based on the scope of the change:
Use when you need to replace an entire function, method, class, or other symbol, or insert new ones adjacent to existing symbols.
find_symbol (see serena-code-intelligence skill) to locate and confirm the symbol's name_pathreplace_symbol_body to replace its definition, or insert_after_symbol / insert_before_symbol to add adjacent codefind_referencing_symbols to verify backward compatibility — if the change breaks callers, update all referencesrename_symbol for safe codebase-wide renames via LSPUse when you need to change just a few lines within a larger symbol, or do search-and-replace across a file.
replace_content with mode=regex is the primary tool. Use non-greedy wildcards to avoid quoting large blocks of code: