Skip to main content
Glama

extract_function

Extract a selected line range from a function into a new named helper. Uses AST analysis to compute parameters and return value, with dry-run preview before applying.

Instructions

Extract a line range out of an enclosing function into a new named helper (AST-aware, TypeScript/JavaScript). Computes the parameter list via free-variable analysis (identifiers read in the slice but declared outside it, including closure captures) and a return value (a binding declared in the slice and used after it). The helper is inserted after the enclosing function and the slice is replaced by a call. Dry-run by default — preview the edits + extracted_params + return_value, then re-call with dry_run=false to apply. Returns JSON: { success, edits, extracted_params, return_value, confidence, files_modified }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dry_runNoPreview changes without applying (default: true). Set to false to apply.
end_lineYesLast line to extract (1-indexed, inclusive)
file_pathYesFile path (relative to project root)
start_lineYesFirst line to extract (1-indexed, inclusive)
function_nameYesName for the extracted function
Behavior5/5

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

The description goes well beyond annotations by detailing the dry-run default, preview behavior, parameter computation via free-variable analysis, and return JSON structure. No contradiction with annotations.

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 moderately long but well-structured with clear sections for purpose, mechanics, usage pattern, and return format. Every sentence adds value, though could be slightly tighter.

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 complexity of AST-aware extraction with free-variable analysis, the description covers purpose, mechanics, dry-run mode, parameters, and return values. No output schema but return fields are listed, making it complete for agent usage.

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

Parameters3/5

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

Schema coverage is 100%, so baseline is 3. The description adds context for dry_run and function_name, but start_line, end_line, file_path are already well-described in the schema. Minimal additional value.

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 extracts a line range from an enclosing function into a new helper, specifies it is AST-aware for TypeScript/JavaScript, and mentions free-variable analysis. This distinguishes it from the many sibling tools.

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 explains the dry-run workflow and how to apply changes, but does not explicitly mention when not to use this tool or provide alternative tool names. Usage context is clear but excludes.

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/nikolai-vysotskyi/trace-mcp'

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