Skip to main content
Glama

Insert After Symbol

insert_after_symbol
Destructive

Insert new code after existing symbol definitions in source files to add classes, functions, methods, or variable assignments.

Instructions

Inserts the given body/content after the end of the definition of the given symbol (via the symbol's location). A typical use case is to insert a new class, function, method, field or variable assignment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
name_pathYesName path of the symbol after which to insert content (definitions in the `find_symbol` tool apply).
relative_pathYesThe relative path to the file containing the symbol.
bodyYesThe body/content to be inserted. The inserted code shall begin with the next line after the symbol.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler: InsertAfterSymbolTool.apply() delegates to CodeEditor.insert_after_symbol after creating the editor instance.
    class InsertAfterSymbolTool(Tool, ToolMarkerSymbolicEdit):
        """
        Inserts content after the end of the definition of a given symbol.
        """
    
        def apply(
            self,
            name_path: str,
            relative_path: str,
            body: str,
        ) -> str:
            """
            Inserts the given body/content after the end of the definition of the given symbol (via the symbol's location).
            A typical use case is to insert a new class, function, method, field or variable assignment.
    
            :param name_path: name path of the symbol after which to insert content (definitions in the `find_symbol` tool apply)
            :param relative_path: the relative path to the file containing the symbol
            :param body: the body/content to be inserted. The inserted code shall begin with the next line after
                the symbol.
            """
            code_editor = self.create_code_editor()
            code_editor.insert_after_symbol(name_path, relative_file_path=relative_path, body=body)
            return SUCCESS_RESULT
  • Core logic for inserting content after a symbol's body end position, handling newlines and positioning correctly using symbol location from language server.
    def insert_after_symbol(self, name_path: str, relative_file_path: str, body: str) -> None:
        """
        Inserts content after the symbol with the given name in the given file.
        """
        symbol = self._find_unique_symbol(name_path, relative_file_path)
    
        # make sure body always ends with at least one newline
        if not body.endswith("\n"):
            body += "\n"
    
        pos = symbol.get_body_end_position_or_raise()
    
        # start at the beginning of the next line
        col = 0
        line = pos.line + 1
    
        # make sure a suitable number of leading empty lines is used (at least 0/1 depending on the symbol type,
        # otherwise as many as the caller wanted to insert)
        original_leading_newlines = self._count_leading_newlines(body)
        body = body.lstrip("\r\n")
        min_empty_lines = 0
        if symbol.is_neighbouring_definition_separated_by_empty_line():
            min_empty_lines = 1
        num_leading_empty_lines = max(min_empty_lines, original_leading_newlines)
        if num_leading_empty_lines:
            body = ("\n" * num_leading_empty_lines) + body
    
        # make sure the one line break succeeding the original symbol, which we repurposed as prefix via
        # `line += 1`, is replaced
        body = body.rstrip("\r\n") + "\n"
    
        with self.edited_file_context(relative_file_path) as edited_file:
            edited_file.insert_text_at_position(PositionInFile(line, col), body)
  • Input schema and documentation for the insert_after_symbol tool parameters.
    def apply(
        self,
        name_path: str,
        relative_path: str,
        body: str,
    ) -> str:
        """
        Inserts the given body/content after the end of the definition of the given symbol (via the symbol's location).
        A typical use case is to insert a new class, function, method, field or variable assignment.
    
        :param name_path: name path of the symbol after which to insert content (definitions in the `find_symbol` tool apply)
        :param relative_path: the relative path to the file containing the symbol
        :param body: the body/content to be inserted. The inserted code shall begin with the next line after
            the symbol.
        """
Behavior4/5

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

Annotations already indicate destructiveHint=true and readOnlyHint=false, but the description adds valuable behavioral context: it specifies that insertion occurs 'after the end of the definition' and that 'the inserted code shall begin with the next line after the symbol.' This clarifies the exact positioning behavior beyond what annotations provide.

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 perfectly concise with two sentences: the first states the core functionality, the second provides a typical use case. Every word earns its place, and the most important information (what the tool does) is front-loaded.

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 presence of both annotations (destructiveHint=true, readOnlyHint=false) and an output schema (implied by context signals), the description provides complete contextual information. It covers the tool's purpose, typical usage, and behavioral specifics without needing to explain return values or safety characteristics that are already documented elsewhere.

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?

With 100% schema description coverage, all parameters are already documented in the input schema. The description adds some context by mentioning 'symbol's location' and referencing 'find_symbol' for name_path, but doesn't provide significant additional semantic meaning beyond what's in the schema descriptions.

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 ('inserts') and target ('after the end of the definition of the given symbol'), with explicit mention of the content being inserted ('body/content'). It distinguishes from sibling 'insert_before_symbol' by specifying 'after' positioning, and from 'replace_symbol_body' by indicating insertion rather than replacement.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('to insert a new class, function, method, field or variable assignment') and references the 'find_symbol' tool for determining symbol locations. However, it doesn't explicitly state when NOT to use it or directly compare with alternatives like 'insert_before_symbol' or 'replace_content'.

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