Skip to main content
Glama

replace_symbol_body

Update symbol definitions in code by replacing their bodies with new content, using name paths and relative file paths to locate symbols.

Instructions

Replaces the body of the symbol with the given name_path.

The tool shall be used to replace symbol bodies that have been previously retrieved (e.g. via find_symbol). IMPORTANT: Do not use this tool if you do not know what exactly constitutes the body of the symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
name_pathYesFor finding the symbol to replace, same logic as in the `find_symbol` tool.
relative_pathYesThe relative path to the file containing the symbol.
bodyYesThe new symbol body. The symbol body is the definition of a symbol in the programming language, including e.g. the signature line for functions. IMPORTANT: The body does NOT include any preceding docstrings/comments or imports, in particular.

Implementation Reference

  • The ReplaceSymbolBodyTool class provides the core implementation of the 'replace_symbol_body' tool. Its 'apply' method executes the tool logic by creating a CodeEditor instance and calling 'replace_body' to perform the symbol body replacement in the specified file.
    class ReplaceSymbolBodyTool(Tool, ToolMarkerSymbolicEdit): """ Replaces the full definition of a symbol using the language server backend. """ def apply( self, name_path: str, relative_path: str, body: str, ) -> str: r""" Replaces the body of the symbol with the given `name_path`. The tool shall be used to replace symbol bodies that have been previously retrieved (e.g. via `find_symbol`). IMPORTANT: Do not use this tool if you do not know what exactly constitutes the body of the symbol. :param name_path: for finding the symbol to replace, same logic as in the `find_symbol` tool. :param relative_path: the relative path to the file containing the symbol :param body: the new symbol body. The symbol body is the definition of a symbol in the programming language, including e.g. the signature line for functions. IMPORTANT: The body does NOT include any preceding docstrings/comments or imports, in particular. """ code_editor = self.create_code_editor() code_editor.replace_body( name_path, relative_file_path=relative_path, body=body, ) return SUCCESS_RESULT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/oraios/serena'

If you have feedback or need assistance with the MCP directory API, please join our Discord server