Skip to main content
Glama

insert_in_body

Insert a code snippet into a function body at a specified position: top, bottom, after, or before an exact anchor snippet.

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?

With no annotations, the description carries the full burden. It discloses key behaviors: the requirement to pass exactly one of at/after/before, the uniqueness requirement for anchored matches, and the caller's responsibility for newlines and indentation. However, it does not specify error handling for invalid combinations or missing target, which slightly reduces completeness.

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, starting with a concise purpose statement, followed by bullet points for modes, usage guidelines, and examples. Every sentence adds value without redundancy, achieving high information density with no wasted words.

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 tool's complexity (6 parameters, 0% schema coverage) and the presence of an output schema, the description covers essential usage patterns and constraints. It could have addressed edge cases like missing target or conflicting placements more explicitly, but overall it is sufficiently complete for effective agent use.

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%, so the description must compensate, and it does so thoroughly. It explains the meaning of each parameter (file_path implied, target, new_snippet, at, after, before), their usage constraints, and provides concrete examples. The constraint that exactly one placement mode must be used is clearly communicated.

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 purpose with specific verb and resource: 'Insert new_snippet inside a named function/method body.' It further distinguishes its four placement modes and explicitly differentiates from sibling tools like replace_function_body, add_top_level, and replace_in_body, making the purpose unambiguous.

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?

The description provides explicit when-to-use and when-not-to-use guidance, including direct references to alternative tools (e.g., 'use replace_function_body' for replacing the whole body). This makes the selection criteria very clear for an AI agent.

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