Skip to main content
Glama

replace_in_body

Destructive

Replace a snippet within one function body, scoped so text elsewhere never matches; ambiguous or missing snippets are rejected to prevent unintended edits.

Instructions

Replace a snippet inside a function's body; the match is scoped to that body, so text elsewhere in the file never matches. A snippet found nowhere is refused; one found in several places is refused with their line numbers: add context.

Use this when: changing one statement or block in a long body. Don't use this when: replacing the whole body (replace_function_body), or editing a sub-expression no unique snippet can locate (your normal edit tool).

Example (a block written without its indentation): target="handle" old_snippet="if retry:\n wait()" new_snippet="if retry:\n backoff()\n wait()"

Input Schema

NameRequiredDescriptionDefault
targetYesFunction or method name as list_symbols lists it, dotted for nesting ('LRUCache.get'); overloads take parameter types ('A.m(int)').
file_pathYesAbsolute path to the source or config file.
new_snippetYesReplacement text; its lines move with the match's indentation, keeping their relative indentation, and text already at the file's indentation goes in as written. '' deletes the snippet.
old_snippetYesText in the target's body, matching one place: its exact text at token boundaries, or else whole lines with the same indentation added to or removed from each.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv3.2.0
    • addedInput schema / properties / file_path / description
      Added value: +"Absolute path to the source or config file."
    • addedInput schema / properties / new_snippet / description
      Added value: +"Replacement text; its lines move with the match's indentation, keeping their relative indentation, and text already at the file's indentation goes in as written. '' deletes the snippet."
    • addedInput schema / properties / old_snippet / description
      Added value: +"Text in the target's body, matching one place: its exact text at token boundaries, or else whole lines with the same indentation added to or removed from each."
    • addedInput schema / properties / target / description
      Added value: +"Function or method name as list_symbols lists it, dotted for nesting ('LRUCache.get'); overloads take parameter types ('A.m(int)')."
  2. Addedv2.10.0

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true and readOnlyHint=false, so the safety profile is covered. The description adds real behavioral content beyond that: ambiguous matches are refused with line numbers, zero matches are refused, and new-snippet lines follow the match's indentation. It doesn't say what the refusal looks like (error vs. status), which keeps it off a 5.

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

Conciseness4/5

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

Front-loaded purpose, then clearly labeled use/don't-use blocks and one worked example. Slightly long because of the multi-line example, but each block carries information an agent needs.

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

Completeness4/5

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

Output schema exists so return values needn't be explained, and all four params are documented in-schema. The description closes the main remaining gaps (scoping, uniqueness, refusal conditions, indentation). Only the shape of a refusal response is left implicit.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description goes further by explaining the uniqueness requirement for old_snippet with a concrete example, including the indentation-relaxed writing style, which is the non-obvious part agents get wrong.

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?

States a specific verb and resource ('replace a snippet inside a function's body') plus the scoping constraint that distinguishes it from a plain text replace. It also names the sibling it is not (replace_function_body) so an agent can route without opening schemas.

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?

Explicit 'Use this when' / 'Don't use this when' sections with two named alternatives: replace_function_body for whole-body replacement, and the normal edit tool for sub-expressions no unique snippet can locate. The selection condition is fully spelled out.

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