Skip to main content
Glama

Refactor Code

refactor_code
Read-only

Apply a requested refactoring to code while preserving its external behavior. Rename, extract methods, or convert patterns through an AI review loop.

Instructions

Apply a specific refactoring to existing code.

The local model will apply the requested transformation while preserving external API and behavior. Useful for mechanical refactors like renaming, extracting methods, converting patterns, etc.

IMPORTANT: Always review the returned code before accepting it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe existing code to refactor.
languageYesProgramming language of the code.
max_tokensNoMax tokens override.
constraintsNoRules or restrictions for the refactor.
temperatureNoTemperature override.
refactor_descriptionYesWhat refactoring to apply — e.g. 'extract method', 'rename variables to snake_case', 'convert class to dataclass', 'split into smaller functions'.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNoThe generated artefact (code, tests, documentation). None on failure.
errorNoHuman-readable error message. None on success.
successYesWhether the generation completed successfully.
metadataNoAuxiliary data: token usage, elapsed time, quality warnings, etc.
Behavior4/5

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

Annotations already mark readOnlyHint=true, and the description adds useful behavioral context: the model preserves external API/behavior and the result must be reviewed before acceptance. The warning 'Always review the returned code before accepting it' communicates uncertainty quality without contradicting the read-only annotation.

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 compact and front-loaded: action first, then context, examples, and a critical safety warning. Every sentence contributes and there is no repetition of schema details.

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?

The tool has a full input schema, output schema, and annotations; the description supplies the missing practical context—when to use it, what to preserve, and the need for review. Nothing essential for safe and correct invocation is absent.

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 100%, so the baseline is 3. The description adds value by giving concrete refactoring examples and framing refactor_description within preserving behavior, which helps an agent formulate meaningful transformation requests.

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 description opens with a specific verb and resource: 'Apply a specific refactoring to existing code.' It clarifies the scope with examples like renaming and extracting methods, and distinguishes from bug-fixing or implementation by emphasizing preservation of external API and behavior, though it does not name a sibling explicitly.

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?

It states that the tool is useful for mechanical refactors, giving clear context for when it applies. However, it does not explicitly say when not to use it or name alternatives such as fix_code or implement_code, leaving exclusion to inference.

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/shreyashp77/Llama-Bridge'

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