Skip to main content
Glama

extract_variable

Extracts an expression at the given positions into a local variable, returning edits to declare the variable and replace the expression.

Instructions

Extract an expression at the given position into a local variable.

Returns the text edits needed to extract the expression. The caller should apply these edits to perform the extraction.

USAGE: Select expression by providing start and end positions OUTPUT: Variable declaration and replacement edits

An expression of type void, or a null literal alone, is refused (INVALID_PARAMETER): no variable can be declared for it.

IMPORTANT: Uses ZERO-BASED coordinates.

Requires load_project to be called first.

Input Schema

NameRequiredDescriptionDefault
endLineYesZero-based end line of expression
filePathYesPath to source file
endColumnYesZero-based end column of expression
startLineYesZero-based start line of expression
startColumnYesZero-based start column of expression
variableNameNoName for the new variable (optional, will suggest if not provided)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.3.4
  2. Removedv1.3.3
  3. First observedv1.2.0

TDQS

A3.7/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and does well: it discloses that the tool returns text edits rather than applying them ('The caller should apply these edits'), names a specific failure mode with its error code (void expression or null literal -> INVALID_PARAMETER), and flags the zero-based coordinate contract. It stops short of describing edge cases like overlapping/invalid selections or multi-edit ordering, so it is not fully 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?

The block is front-loaded with the core purpose and uses labeled sections (USAGE, OUTPUT, IMPORTANT) that scan quickly. There is mild redundancy between 'Returns the text edits needed to extract the expression' and 'OUTPUT: Variable declaration and replacement edits', which keeps it from a 5.

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?

For a 6-parameter mutation-style refactoring tool with no annotations and no output schema, the description covers the essentials: output shape, caller responsibility, error behavior, coordinate system, and the load_project prerequisite. The main omission is any statement of sibling alternatives, which is a routing gap rather than an invocation gap.

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 description coverage is 100%, so every parameter including the optional variableName is already documented in the schema. The description's zero-based coordinate warning and 'select expression by start/end positions' merely restate what the schema fields already say, adding no new parameter-level meaning beyond the baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The first sentence gives a specific verb (Extract) and resource (an expression at a given position into a local variable), which is concrete and actionable. However, it never distinguishes itself from the closely related siblings extract_method and extract_constant, so the agent must infer the boundary from the name alone.

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

Usage Guidelines3/5

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

The 'USAGE' line tells the agent how to invoke it (select by start/end positions) and the description states the prerequisite 'Requires load_project to be called first', which is useful. But there is no guidance on when to prefer this over extract_method or extract_constant, so usage is only implied.

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