
用于重构的MCP
概览
行为保留的 Go 重构作为大型语言模型(Claude 或通过 Ollama 的本地模型)的工具展示。模型决定更改内容;该工具一步步安全地保证如何更改。 每一步返回一个统一的差分(或解释原因的拒绝),模型在选择下一次重构前读取该差异。这个循环就是迭代。 - 工作区加载、编辑、差异、撤销、安全引擎、类型感知重命名、黄金测试和光源集成。- MCP服务器(cmd/重构-mcp),支持重命名、检查、撤销和检查,可在Claude代码中使用。- 简化代码的重构。extract_variable、inline_variable和extract_function(extract_function包含参数和结果、返回语句、共享变量指针、方法、导入、本地常量和类型以及泛用)。invert_if(带守卫子句)和 remove_else 完成。 1. 局部模型驱动相同的工具端到端:逐步检查、重构、检查。
概述(AI 翻译)
保持行为的 Go 重构,以及改变行为的编辑 目的,作为大型语言模型的工具(Claude或本地模型)通过 Ollama)。模型决定要更改什么“;该工具保证如何更改; 它安全地一步步改变。目标是完成几乎所有编码 通过这些打字步骤,而不是手动编辑文件。
每一步返回统一的差异(或解释原因的拒绝),其中 模型在选择下一次重构前读取。这个循环就是迭代。
状态
- 步骤1: 工作区加载、编辑、差异、撤销、安全引擎,a
类型感知
rename,黄金测试和CLI。 - 步骤2: MCP服务器(
cmd/refactor-mcp)与rename、inspect,undo和check,可从 Claude Code 中使用。 - 步骤3(进行中): 简化代码的重构。
extract_variable、inline_variable和extract_function已完成 (extract_function,参数和结果,return语句, 共享变量、方法、导入、局部常量和 类型,以及泛型词)。invert_if(带护栏)和remove_else已经完成了。inline_function有一个第一个版本(见路线图)。
本页由 AI 翻译,技术细节请以原文为准。
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 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"gorefactor": { "command": "refactor-mcp" }
}
}