
tychofreeman/go-refactor-mcp
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
An MCP for refactoring
概要
Behavior-preserving Go refactorings exposed as tools for an LLM (Claude or a local model through Ollama). The model decides what to change; this tool guarantees how it's changed safely, one step at a time. Each step returns a unified diff (or a refusal explaining why), which the model reads before choosing the next refactoring. That loop is the iteration. - workspace loading, edits, diffs, undo, the safety engine, a type-aware rename, golden tests and a CLI. - MCP server (cmd/refactor-mcp) with rename, inspect, undo and check, usable from Claude Code. - refactorings that simplify code. extract_variable, inline_variable and extract_function are done (extract_function with parameters and results, return statements, pointers for shared variables, methods, imports, local constants and types, and generics). invert_if (with guard clauses) and remove_else are done. 1. A local model drives the same tools end to end: inspect, refactor one step at a time, check.
README
以下は原文 README の抜粋です。原文を見る。
go-refactor-mcp
You know the discipline (small behavior-preserving steps, make the change easy then make the easy change, two hats), and gorefactor gives it to an AI coding assistant. It’s an MCP server with about 45 Go refactorings and edits, much of Fowler’s catalog as type-checked tools: the model picks the step, and the engine checks preconditions (evaluation order, side effects, panics, name capture), applies it everywhere with the type checker, and rolls back anything that doesn’t compile. Refactorings refuse anything that would change behavior, behavior changes go through separate edit tools, and test-first works because what a failing test calls is stubbed so the code still compiles. Like junior developers, models don’t refactor on their own: they extend what’s there, unless “make the change easy” is a step of its own, which found the right design in all 15 runs we tried. And because writing code costs a model almost nothing, refactoring first pays off where a change reaches many places, not on small local edits, so the open question is the one you’d ask: can the craft be taught to the machine, not just handed to it as tools?
model ──(tool call: rename {...})──▶ engine: check preconditions
apply byte-range edits
re-type-check, roll back on error
model ◀──(APPLIED + diff | REFUSED + reason)──┘
Each step returns a unified diff, or a refusal saying why, which the model
reads before choosing the next step. A batch sends several steps as one
change, rolled back as a whole, and every step can be undone.
Status
- Refactorings: rename and move declarations; extract and inline
functions and variables; add, remove, move and introduce parameters,
change parameter, result and field types (an interface method with its
implementations); method to function and back, move a method, extract a
struct;
fold(replace code that does what a function does with calls to it),parameterize, merge duplicate functions; a type switch into methods; invert if, remove else, slide statements, remove dead code. - Edits, which change behavior on purpose and are still type-checked
and undoable: create, move and delete files, add declarations, fields,
cases and elements, replace statements, expressions, declarations and
text, and
create_from_usage, which declares what a test written first uses. - TypeScript: most of the same tools under the same names, chosen by the file’s extension, built on the Go port of the TypeScript compiler.
- Releases: tagged by CI from v0.3.0 (
docs/releases/). - Evidence: A/B runs against editing by hand in
docs/cost-history.md, every hand edit indocs/friction-log.md, and the derivations found so far indocs/derivations.md. - Roadmap:
docs/roadmap.md.
Layout
cmd/refactor-mcp/ the MCP server (stdio), for Claude Code and other MCP clients
インストール
This server does not publish a one-line install command.
Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →設定
{
"mcpServers": {
"gorefactor": { "command": "refactor-mcp" }
}
}