Skip to main content
Glama

encapsulate_field

Generate getter and setter for a Java field and automatically rewrite all direct accesses across files to use them. Requires project loaded first.

Instructions

Encapsulate a field: generate a getter/setter pair and rewrite all direct accesses (in this and other files) to go through them.

USAGE: Position on the field name; optionally name the accessors. OUTPUT: editsByFile with all required text edits; warnings from JDT's own condition checking, by the place each names (file, then position; those naming one place in JDT's order, those naming none last). Edits are returned as text - apply them yourself.

IMPORTANT: Uses ZERO-BASED coordinates.

Requires load_project to be called first.

Input Schema

NameRequiredDescriptionDefault
lineYesZero-based line number of the field declaration
columnYesZero-based column number (on the field name)
filePathYesPath to source file containing the field
getterNameNoGetter name (default: getX for field x)
setterNameNoSetter name (default: setX for field x)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.4.1

TDQS

A4.1/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 edits are returned as text and must be applied by the caller ('apply them yourself'), that warnings come from JDT's condition checking, and that coordinates are zero-based. It lacks permission/scope or reversibility notes, so not a 5.

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 labeled sections (USAGE, OUTPUT, IMPORTANT) front-load the purpose and make scanning easy with zero filler sentences. The OUTPUT paragraph is dense but earns its place by describing a structure with no output schema.

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 mutation/refactoring tool with no annotations and no output schema, the description covers the critical gaps: output shape (editsByFile, text edits, warnings), the prerequisite (load_project), and the coordinate convention. It could say more about cross-file side effects, but the essentials are present.

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 the schema already documents all five parameters including getterName/setterName defaults. The description only restates 'position on the field name' and 'optionally name the accessors,' adding no syntax or format detail beyond the schema. Baseline 3 is appropriate.

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 gives a specific verb and resource ('Encapsulate a field') and immediately defines the mechanics: 'generate a getter/setter pair and rewrite all direct accesses (in this and other files) to go through them.' This clearly distinguishes it from siblings like rename_symbol, extract_method, or inline_method.

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?

'USAGE: Position on the field name; optionally name the accessors' tells the agent how to invoke it, and 'Requires load_project to be called first' gives a concrete prerequisite. It does not name a when-not condition or an explicit alternative refactoring, 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.