Skip to main content
Glama

Replace Symbol Body

replace_symbol_body
Destructive

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.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate destructiveHint=true and readOnlyHint=false, which the description aligns with by implying a mutation ('Replaces'). The description adds valuable context beyond annotations: it clarifies that the body excludes 'preceding docstrings/comments or imports,' specifies a prerequisite (previous retrieval via find_symbol), and warns about misuse if the body is unclear. This enhances behavioral understanding without contradicting annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by usage guidelines and a critical warning. Each sentence earns its place by providing essential information without redundancy, resulting in a well-structured and efficient text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (destructive mutation with 3 required parameters), the description is complete: it covers purpose, usage context, prerequisites, and critical warnings. With annotations providing safety cues and an output schema present (implying return values are documented elsewhere), no additional information is needed for effective tool selection and invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing detailed parameter documentation (e.g., 'body' includes the definition excluding docstrings). The description adds minimal semantics beyond the schema, such as linking 'name_path' to 'find_symbol' logic, but does not significantly enhance parameter understanding. With high schema coverage, a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Replaces the body of the symbol') and identifies the target resource ('symbol with the given name_path'). It distinguishes from siblings like 'rename_symbol' (which changes the name) and 'replace_content' (which replaces file content rather than symbol bodies), establishing a unique purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use ('to replace symbol bodies that have been previously retrieved via find_symbol') and when not to use ('Do not use this tool if you do not know what exactly constitutes the body of the symbol'). It also references a specific alternative tool ('find_symbol') for preparation, offering clear context for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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