Skip to main content
Glama

replace_symbol_body

Replace a symbol's entire declaration (signature + body) via LSP or tree-sitter fallback. Optionally include its doc comment. Preview with dry-run and view a unified diff.

Instructions

Replace the entire declaration of a symbol with new content.

The replacement spans the symbol's full Range as reported by the LSP — for a function, this is from 'func' keyword through the closing '}'. Provide the complete new declaration (signature + body) in 'content'.

Set include_doc_comment=true to also cover any contiguous doc comment above the symbol — gopls and most LSP servers report the symbol range starting at the declaration keyword, so without this flag the old doc comment is left orphaned. With it on, your 'content' must include the new doc comment too (or the symbol will have none).

Use rename_symbol if you only want to change the symbol's name. Use this tool when changing logic, signature, or both — addressed by name_path, no line/character coordinates to compute like edit_file's range mode.

The response includes a unified diff of the change — a preview in dry-run, the applied change otherwise — unless show_write_diff is disabled.

Works even when the language server is cold or cannot parse the file: it then locates the symbol via a fresh tree-sitter parse (line-granular range, annotated in the output).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriNoAbsolute path, file:// URI, or workspace-relative path.
contentNoThe full replacement declaration.
dry_runNoIf true (default), preview only; do not write.
dirty_okNoAllow editing a file with uncommitted changes. Default false — review/commit first, or pass true to proceed.
name_pathYesSlash-separated symbol path within the file (e.g. "ClassName/methodName", or just "funcName" for top-level).
include_doc_commentNoIf true, extend the operation to cover any contiguous comment lines (//, #, /*, *) directly above the symbol declaration. Lets you replace/delete a function together with its doc comment, or insert a new block above an existing doc comment instead of between the comment and its symbol. A WRAPPED declaration (an exported ES declaration under its export statement, a decorated Python def under its @decorator) keeps its doc comment above the wrapper, so WHEN SUCH A COMMENT EXISTS insert_before_symbol and replace_symbol_body extend past the wrapper — replacement content must then reproduce the export keyword or the decorator, or it is dropped. With no doc comment above the wrapper the range starts at the declaration and the wrapper is untouched; safe_delete_symbol never extends past the declaration at all.
Behavior5/5

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

With no annotations provided, the description fully carries the transparency burden. It discloses the LSP range semantics (from 'func' keyword through closing '}'), the orphaned doc comment behavior when include_doc_comment is false, the tree-sitter fallback when LSP is cold, and the unified diff/dry-run response behavior. This is rich, actionable behavioral detail.

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?

Although long, the description is appropriately sized for the tool's complexity. It is front-loaded with the core purpose, then systematically covers usage alternatives, response behavior, fallback modes, and edge cases. Every sentence earns its place; there is no filler or repetition of schema details.

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?

The description is complete for a complex mutation tool. It covers the diff response and dry-run behavior, the cold-LSP fallback with annotated output, doc comment edge cases including wrappers, and distinguishes itself from related siblings. No output schema exists, but the described return value (unified diff) suffices.

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

Parameters5/5

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

Schema coverage is 100%, giving a baseline of 3, but the description adds substantial meaning beyond the schema: what 'entire declaration' means, the need to include full signature and body, the doc comment flag's wrapper/export/decorator implications, and the name_path addressing model compared to edit_file. This goes well beyond the individual parameter 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 opens with a specific verb+resource+scope: 'Replace the entire declaration of a symbol with new content.' It clearly distinguishes itself from rename_symbol ('Use rename_symbol if you only want to change the symbol's name') and positions itself for logic/signature changes, making the purpose unmistakable.

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?

Explicitly names alternatives and gives when-to-use guidance: use rename_symbol for name-only changes, use this for logic/signature changes, and contrasts with edit_file's coordinate-based range mode. Also explains when to set include_doc_comment and the wrapper/decorator caveat, providing clear context for decision-making.

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/plumbkit/plumb'

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