Skip to main content
Glama

insert_in_body

Insert new code lines inside a function or method body at the top, bottom, before, or after a unique anchor, using symbol-targeted edits instead of brittle search-and-replace.

Instructions

Insert new_snippet inside a function's body. Set exactly one of at, after or before. at="top" goes after a Python docstring, at="bottom" at body level after the last statement, and in an empty body one level deeper than the function; at is refused for a body on its signature's line (use replace_function_body).

An anchor is matched as replace_in_body matches a snippet and must be unique. One that ends its line (after) or starts it (before) gets new_snippet on lines of its own; after a line that opens a block (if x:, if (x) {), new lines go inside the block. A mid-line anchor gets new_snippet byte for byte.

Use this when: adding lines to a body. Don't use this when: replacing the whole body (replace_function_body), changing existing lines (replace_in_body), or adding a top-level symbol (add_top_level).

Example (both written without indentation): target="handle" new_snippet='auth_check(request)' before='validate(request)'

Input Schema

NameRequiredDescriptionDefault
atNo'top' or 'bottom' of the body; '' (default) leaves this mode unused. Other values are refused.
afterNoAnchor in the body to insert after; '' (default) leaves this mode unused.
beforeNoAnchor in the body to insert before; '' (default) leaves this mode unused.
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_snippetYesText to insert. With at, re-indented as a block to the body's indentation; with after or before, indented like the anchor (as written when already at the file's indentation there).

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed6 schema fields changedv3.2.0
    • addedInput schema / properties / after / description
      Added value: +"Anchor in the body to insert after; '' (default) leaves this mode unused."
    • addedInput schema / properties / at / description
      Added value: +"'top' or 'bottom' of the body; '' (default) leaves this mode unused. Other values are refused."
    • addedInput schema / properties / before / description
      Added value: +"Anchor in the body to insert before; '' (default) leaves this mode unused."
    • addedInput schema / properties / file_path / description
      Added value: +"Absolute path to the source or config file."
    • addedInput schema / properties / new_snippet / description
      Added value: +"Text to insert. With at, re-indented as a block to the body's indentation; with after or before, indented like the anchor (as written when already at the file's indentation there)."
    • 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. First observedv2.0.1

TDQS

A4.6/5.0
Behavior4/5

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

Goes well beyond the annotations: it discloses refusal cases ("`at` is refused for a body on its signature's line"), the uniqueness constraint on anchors, and the empty-body / docstring positioning rules. It does not cover failure behavior for a missing target or unparsable file, so it falls just short of exhaustive.

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 with the action and the one-of-three rule, then when/when-not, then a compact example. Dense but every clause carries information; only the parenthetical language-specific hints slightly interrupt the flow.

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?

An output schema exists, so return values need not be explained, and all six parameters are documented. For a mutation tool with real edge cases (empty body, signature-line body, block-opening anchors), the description supplies the positioning, indentation, and refusal semantics an agent needs to call it correctly.

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 the baseline is 3, but the description adds meaning the schema does not carry: what `at="top"` means relative to a Python docstring, where `at="bottom"` lands in an empty body, and how indentation is applied for anchored versus `at` insertion. Anchor matching semantics (uniqueness, line-opening versus mid-line) are additional and useful.

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 ("Insert new_snippet inside a function's body") and immediately pins the scope with the mutual-exclusion rule for `at`/`after`/`before`. It is clearly distinguishable from replace_in_body and replace_function_body, which it names.

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: adding lines to a body" and "Don't use this when:" enumerating three alternatives with the condition that selects each (replace_function_body, replace_in_body, add_top_level). Nothing about tool selection is left to inference.

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