Skip to main content
Glama

replace_in_body

Replace a specific snippet inside a function or method body without affecting surrounding code. Scopes the match to the target's body to prevent accidental changes elsewhere.

Instructions

Replace a byte-identical snippet inside a named function/method body, without touching the surrounding code. The match is scoped to the target's body so accidental matches elsewhere in the file cannot happen.

Raises if the snippet is not found, or if it appears more than once in the body (include more surrounding context to disambiguate).

Use this when: You need to change a specific statement or block inside a large function body without rewriting the whole body. The single biggest token-saver for long functions with ~30 similar lines where you only want to change one of them. Don't use this when: You're replacing the entire body -> use replace_function_body. You need to change a sub-expression inside a method chain that string matching can't uniquely locate -> use the default Edit tool instead.

Example: target="init" old_snippet="viper.BindPFlag("port", cmd.Flags().Lookup("port"))" new_snippet="viper.BindPFlag("port", cmd.PersistentFlags().Lookup("port"))"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
targetYes
old_snippetYes
new_snippetYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses scoping to function body to prevent accidental matches, and raises on missing/duplicate snippet. It implies mutation but doesn't explicitly state file-saving behavior; however, output schema exists to cover return values. Overall good transparency.

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?

Well-structured with clear sentences: purpose first, then error conditions, usage guidelines, and a concrete example. No redundant or irrelevant information; every sentence earns its place.

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?

Given 4 required params and existence of output schema, description covers purpose, usage, error cases, and example. It does not explain return value (but output schema exists) or prerequisites (e.g., file must exist, target must be defined), but these are implied. Adequate for effective use.

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 0%, so description compensates by explaining each parameter: file_path, target (name of function/method), old_snippet and new_snippet (byte-identical snippets). An example illustrates usage. Could add more on file_path requirements, but sufficient for clear understanding.

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 tool replaces a byte-identical snippet inside a named function/method body without affecting surrounding code. It distinguishes itself from sibling tools like replace_function_body (entire body replacement) and Edit (for sub-expressions in method chains).

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 provides when to use (changing a specific statement in a long function) and when not to use (entire body -> use replace_function_body; sub-expression in method chain -> use Edit). Also explains error conditions (raises if not found or duplicate) and how to disambiguate (add more context).

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/kambleakash0/agent-skills'

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