Skip to main content
Glama

extract_method

Extract selected statements or an expression into a new method or function, with parameters and return values inferred from data flow.

Instructions

Extract a selected block of statements (or an expression) into a new method or function, with parameters and return values inferred from the data flow. Pass the file and the selection Range — start_line/start_character to end_line/end_character, 0-based, character in UTF-16 units, exactly as an editor selection. The selection must be complete statements or one complete expression. Options: replace_similar replaces other occurrences of the same pattern; to_global_scope extracts to module level; method_kind makes a classmethod or staticmethod. Defaults to a Dry Run preview; set apply=true to write. Read the code with your LSP first; leave formatting to black/ruff.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
nameYes
rootNo
applyNo
end_lineYes
start_lineYes
method_kindNo
end_characterYes
replace_similarNo
start_characterYes
to_global_scopeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior4/5

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

With no annotations provided, the description carries the burden of disclosing behavior. It does so well by stating the dry-run default, the apply flag to actually write, that parameters/returns are inferred from data flow, and that formatting is left to black/ruff. It does not cover failure modes or side effects, but the safety-critical dry-run behavior is clearly conveyed.

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 information-dense and front-loaded with the core purpose. Each sentence adds new valuable information, from the selection requirements to the options to the dry-run default. There is no redundant or vague phrasing, and the structure flows logically from what the tool does to how to invoke it.

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 (11 parameters, no annotations) and the presence of an output schema, the description covers the essential aspects: purpose, selection semantics, options, and the safety default. It does not delve into error cases or exact return behavior, but those are partly covered by the output schema. Overall, it is quite complete for the tool's complexity.

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 0%, so the description must compensate. It explains the range parameters (0-based, UTF-16 units), the options (replace_similar, to_global_scope, method_kind), and the apply flag. However, it does not mention the required 'name' parameter or the optional 'root' parameter, which are left unexplained. Still, the majority of parameters are semantically clarified.

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: 'Extract a selected block of statements (or an expression) into a new method or function'. It distinguishes itself from sibling tools like extract_variable by emphasizing method/function extraction and complete statements/expressions. The mention of inferred parameters and return values adds specificity.

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?

Provides clear context on how to use the tool, including the exact range format, the requirement for complete statements or one expression, and the dry-run/apply flow. It also gives advice to read code with LSP first and leave formatting to black/ruff. However, it does not explicitly name alternative tools or state when not to use this tool, so it falls short of a 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/andrewesweet/ropey'

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