Skip to main content
Glama

insert_in_body

Insert a code snippet into a function or method body at the top, bottom, after an anchor, or before an anchor.

Instructions

Insert new_snippet inside a named function/method body. Pass EXACTLY ONE of at, after, or before -- this one tool covers four placement modes that used to be spread across three separate tools.

  • at="top": insert at the top of the body.

  • at="bottom": insert at the bottom of the body.

  • after=: insert immediately after a byte-identical anchor.

  • before=: insert immediately before a byte-identical anchor.

The anchor match (for after/before) is scoped to the target's body and must be unique -- multiple matches raise an error telling you to include more surrounding context. Caller is responsible for any leading/trailing newlines and indentation in new_snippet.

Use this when: You're inserting new lines into a function body. Use at="top"/at="bottom" for simple prepend/append, or after/before for anchored insertion. Don't use this when: You're replacing the whole body -> use replace_function_body. You're adding a top-level symbol -> use add_top_level. You're changing an existing snippet in the body -> use replace_in_body.

Example (prepend): target="handle" new_snippet=' log("start")\n' at="top"

Example (append): target="handle" new_snippet=' log("end")\n' at="bottom"

Example (after anchor): target="handle" new_snippet=' metrics.incr("calls")\n' after=' validate(request)\n'

Example (before anchor): target="handle" new_snippet=' auth_check(request)\n' before=' validate(request)\n'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
targetYes
new_snippetYes
afterNo
beforeNo
atNo

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 key behaviors: only one of at/after/before can be used, anchor match must be unique, error on multiple matches, caller responsible for formatting. Does not cover auth or rate limits but is comprehensive for the tool's scope.

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 bullet points and examples. Front-loaded with main purpose and constraints. Every sentence adds value, no wasted words.

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 tool's complexity (4 placement modes, 6 parameters), the description covers all necessary context: placement semantics, constraints, examples, and output schema existence. No major gaps.

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 0%, but description compensates by explaining each parameter (file_path, target, new_snippet, at, after, before) with detailed semantics and examples, adding significant value beyond the schema.

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's function: inserting a snippet inside a function/method body with four placement options. It distinguishes itself from siblings by naming alternative tools like replace_function_body and add_top_level.

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?

Provides explicit guidance on when to use this tool (inserting into function body) and when not to (replacing body, adding top-level symbol, changing existing snippet), with named alternatives.

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