Skip to main content
Glama

extract_variable

Extract a selected expression into a named variable, replacing it with the variable name. Supports replacing similar occurrences and global scope, with dry-run preview before applying.

Instructions

Extract a selected expression into a named variable, replacing the expression with the name. Pass the file and the selection Range (start_line/start_character to end_line/end_character, 0-based, UTF-16 units) covering exactly one expression. replace_similar also substitutes other occurrences of the same expression; to_global_scope creates the variable at module level. 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
end_characterYes
replace_similarNo
start_characterYes
to_global_scopeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

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

Without annotations, the description carries full burden. It discloses defaults ('Defaults to a Dry Run preview; set apply=true to write'), side effects of flags ('replace_similar... to_global_scope...'), and dependencies ('Read the code with your LSP first; leave formatting to black/ruff'). This is excellent behavioral disclosure.

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 two sentences, front-loaded with the core action, then efficiently packs parameter semantics and usage guidance. No filler; every clause adds valuable information.

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?

Despite 10 parameters, the description covers the core behavior, defaults, preconditions, and external dependencies. With an output schema present, not explaining return values is acceptable. The description is sufficiently complete for a complex refactoring tool.

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 description coverage is 0%, yet the description explains the meaning of all key parameters: the Range coordinates (0-based, UTF-16 units), name, apply, replace_similar, to_global_scope. It adds essential semantics to raw schema fields and even specifies the units for line/character offsets.

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 uses a specific verb ('Extract') and resource ('selected expression into a named variable'), clearly distinguishing this from sibling tools like extract_method or introduce_parameter. It states the action and effect in the first sentence.

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 usage context: 'Pass the file and the selection Range... covering exactly one expression' and 'Read the code with your LSP first; leave formatting to black/ruff.' It does not explicitly list alternative tools or when not to use it, but the conditions are implied. A 4 is appropriate for clear context without explicit exclusions.

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