Skip to main content
Glama

insert_before_symbol

Insert text before a symbol's declaration, using LSP or tree-sitter to locate it. Add functions, methods, or doc comments precisely, avoiding manual line counting. Supports dry-run and diff previews.

Instructions

Insert text immediately before a symbol's declaration.

Useful for adding a new function/method before an existing one, or prepending a doc comment. Locates the symbol via the LSP document symbol tree (no manual line counting). Provide the full text to insert in 'content' — include trailing newline if appropriate.

Set include_doc_comment=true to insert before any existing leading doc comment instead of between the comment and the symbol — useful when adding a new function (with its own doc comment) above a function that already has one.

The response includes a unified diff of the change — a preview in dry-run, the applied change otherwise — unless show_write_diff is disabled.

Works even when the language server is cold or cannot parse the file: it then locates the symbol via a fresh tree-sitter parse (line-granular range, annotated in the output).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriNoAbsolute path, file:// URI, or workspace-relative path.
contentNoText to insert before the symbol.
dry_runNoIf true (default), preview only; do not write.
dirty_okNoAllow editing a file with uncommitted changes. Default false — review/commit first, or pass true to proceed.
name_pathYesSlash-separated symbol path within the file (e.g. "ClassName/methodName", or just "funcName" for top-level).
include_doc_commentNoIf true, extend the operation to cover any contiguous comment lines (//, #, /*, *) directly above the symbol declaration. Lets you replace/delete a function together with its doc comment, or insert a new block above an existing doc comment instead of between the comment and its symbol. A WRAPPED declaration (an exported ES declaration under its export statement, a decorated Python def under its @decorator) keeps its doc comment above the wrapper, so WHEN SUCH A COMMENT EXISTS insert_before_symbol and replace_symbol_body extend past the wrapper — replacement content must then reproduce the export keyword or the decorator, or it is dropped. With no doc comment above the wrapper the range starts at the declaration and the wrapper is untouched; safe_delete_symbol never extends past the declaration at all.
Behavior5/5

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

With no annotations provided, the description fully carries the burden of behavioral disclosure. It covers how symbol location works (LSP document symbol tree), the fallback to tree-sitter when the language server is cold or cannot parse, the response format (unified diff, preview vs. applied), and the effect of include_doc_comment on comment ranges and wrappers. This is rich, actionable transparency.

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?

The description is a moderately long paragraph, but each sentence contributes distinct, useful information: purpose, use cases, parameter guidance, output behavior, and graceful fallback. It is not as minimal as a two-sentence description, but given the tool's complexity, the length is justified and there is no obvious filler.

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?

For a tool with no output schema and no annotations, the description is remarkably complete. It explains the operation, the location mechanism, the output (unified diff), the dry-run behavior, and the fallback path. It covers the nuanced doc-comment and wrapper behavior, and it even warns about trailing newlines. An agent can select and invoke this tool correctly with high confidence.

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 description coverage is 100%, so the baseline is 3. The description adds practical meaning beyond the schema by specifying that 'content' should be the full text with an appropriate trailing newline, that dry_run produces a diff preview, and by elaborating on include_doc_comment behavior (inserting before a doc comment, wrapper handling). It does not add much for uri, dirty_ok, or name_path, but those are already well described in 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 opens with a specific verb+resource: 'Insert text immediately before a symbol's declaration.' This clearly distinguishes it from siblings like insert_after_symbol, replace_symbol_body, and safe_delete_symbol, and the use cases ('adding a new function/method... or prepending a doc comment') reinforce the tool's specific purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use the tool ('Useful for adding a new function/method before an existing one, or prepending a doc comment') and explains how include_doc_comment changes the operation. However, it does not explicitly name alternatives or state when not to use this tool versus siblings, so it stops short of a perfect 5.

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/plumbkit/plumb'

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