Skip to main content
Glama

replace_in_body

Replace a specific snippet inside a function or method body without altering surrounding code. Scopes the match to the target body to prevent accidental matches 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
Behavior3/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 the target's body and error behavior. However, it does not mention return value, side effects beyond replacement, or authentication/permissions.

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 well-structured with separate sections for purpose, usage guidance, and an example. Each sentence adds value without redundancy.

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 the complexity and lack of schema parameter descriptions, the description covers scoping, error conditions, and usage context. It does not explain the output schema, but that is acceptable per rules. Slight gap in parameter semantics for file_path.

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

Parameters2/5

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

Schema coverage is 0% with no parameter descriptions. The example illustrates target, old_snippet, and new_snippet, but file_path is not explained. Agents must infer from parameter names, which is insufficient for clarity.

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 it replaces a byte-identical snippet inside a named function/method body, scoped to avoid accidental matches elsewhere. It distinguishes from sibling tools like replace_function_body and includes an example.

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 describes when to use (changing a specific statement inside a large function body) and when not to use (entire body -> replace_function_body, ambiguous sub-expression -> default Edit tool). Also notes error conditions for multiple/not found snippets.

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/ast-editor'

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