Code Refactor

io.github.zhouhengchangPublished by GitHub account zhouhengchangv1.0.4Updated Oct 25, 2026

Refactor legacy code into modern, idiomatic code without changing its behavior.

VerifiedStreamable HTTPWeb executableDeveloper ToolsBusiness & CommerceAI & ML

Overview

AI-generated overview

An MCP server that refactors code and generates code, tests, docs, SQL and other content through a local Ollama model or an OpenAI-compatible cloud endpoint.

What you can do
Refactor source code into modern, idiomatic code while keeping behavior, and check which inference backend is available (README tools). Generate runnable sample code, unit tests with mocked dependencies, and README/API docs/changelogs. Review code with graded suggestions and generate or optimize SQL from a schema, blocking destructive statements. Produce marketing copy, translations, video scripts and resume rewrites. Review contracts for high/medium-risk and missing clauses. Look up single orders and list recent orders for reconciliation, plus skill availability and pricing.
When to use it
Useful when you want an assistant to modernize legacy code, scaffold tests and documentation, or draft SQL, copy, translations and contract reviews, either fully locally with Ollama or with a cloud model for higher quality.
Requirements
Runs as a remote endpoint or as a local npm package (npx workbuddy-code-refactor-connector). Local backend needs a reachable Ollama server via OLLAMA_HOST and OLLAMA_MODEL; cloud backend needs REFACTOR_BACKEND=openai plus OPENAI_BASE_URL, OPENAI_MODEL and OPENAI_API_KEY. REFACTOR_TIMEOUT_MS defaults to 180000 ms.
Before you install
The cloud backend sends your code and prompts to a third-party OpenAI-compatible endpoint; only the local Ollama backend keeps code on your machine. Several tools are billed per call, so usage can cost money, and order tools expose call amounts and status. The API key is read from OPENAI_API_KEY and should be supplied via environment, not committed.

Installation

In SourceWeft

  1. Open Code Refactor in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Web executable via Streamable HTTP. Remote servers run from the web runtime once configured in a workspace.

Use with an agent

Paste this prompt into Claude Code, Codex, Cursor or another agent — or into SourceWeft chat. The agent reads this server's install guide, shows you its publisher, endpoint and sign-in, and adds it to your client once you agree. Keys never go into a command.

Read https://sourceweft.com/mcp/io.github.zhouhengchang%2Fcode-refactor/install.md and connect the MCP server it describes to my client. Before changing any config, show me its publisher, endpoint and sign-in method and wait for my OK. Never put an API key in a command or in a file I would commit; ask me where it should come from.

Read the install guide the agent follows

Other MCP clients

Add this to your client's mcpServers config.

{
  "mcpServers": {
    "code-refactor": {
      "type": "http",
      "url": "https://code-refactor-api.app.workbuddy.host/mcp"
    }
  }
}

README

workbuddy-code-refactor-connector

WorkBuddy 代码重构连接器 —— 一个基于 Model Context Protocol 的 MCP Server,把「代码重构」能力封装成 AI 可直接调用的工具。

支持本地 Ollama 与任意 OpenAI 兼容的云端接口两种推理后端,通过环境变量切换。

功能

暴露两个 MCP 工具:

工具参数说明
refactor_codecode(源代码)、task(重构任务描述)、language(可选,语言提示)执行代码重构,返回重构后的代码与说明
check_status无检查当前推理后端是否可用,并返回后端/模型信息

安装

bash
npm install -g workbuddy-code-refactor-connector

或直接以 npx 运行(无需全局安装):

bash
npx workbuddy-code-refactor-connector

配置

所有配置均通过环境变量读取,包内不硬编码任何密钥。

方式一:本地 Ollama(默认,代码不出本机)

bash
REFACTOR_BACKEND=ollama          # 默认值,可省略OLLAMA_HOST=http://127.0.0.1:11434OLLAMA_MODEL=deepseek-coder

方式二:云端 OpenAI 兼容接口

bash
REFACTOR_BACKEND=openaiOPENAI_BASE_URL=https://api.deepseek.com/v1OPENAI_MODEL=deepseek-flashOPENAI_API_KEY=sk-xxxxxxxxxxxx

全部环境变量

变量默认值说明
REFACTOR_BACKENDollama推理后端:ollama | openai
OLLAMA_HOSThttp://127.0.0.1:11434Ollama 服务地址
OLLAMA_MODELdeepseek-coder本地模型名
OPENAI_BASE_URLhttps://api.deepseek.com/v1OpenAI 兼容接口地址
OPENAI_MODELdeepseek-flash云端模型名
OPENAI_API_KEY无云端接口密钥(openai 后端必填)
REFACTOR_TIMEOUT_MS180000单次推理超时毫秒数(纯 CPU 本地推理较慢,默认放宽到 3 分钟)

接入 WorkBuddy

在 WorkBuddy 的连接器配置(mcp.json)中登记本服务:

json
{  "mcpServers": {    "code-refactor": {      "command": "npx",      "args": ["-y", "workbuddy-code-refactor-connector"],      "env": {        "REFACTOR_BACKEND": "ollama",        "OLLAMA_MODEL": "deepseek-coder"      }    }  }}

若使用云端后端,在 env 中补充 REFACTOR_BACKEND、OPENAI_BASE_URL、OPENAI_MODEL、OPENAI_API_KEY。

设计要点

  • 密钥零硬编码:地址、模型名、密钥全部来自环境变量。
  • 超时保护:所有工具调用都有超时上限,默认 180 秒。
  • 错误可读:任何异常都转换为可读的中文提示,不向调用方抛出原始堆栈。
  • 双后端:本地推理保障代码不出本机;云端接口用于追求更高重构质量。

许可

MIT

Source: workbuddy-connector/server/README.md at commit 53fe79b

Tools

13

codegen

AI 代码生成(按次计费)

根据需求描述生成可运行的示例代码。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParametersstylepromptrequiredlanguagerequestId

review

AI 代码审查(按次计费)

审查代码并给出分级的修改建议。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterscoderequiredfocuslanguagerequestId

copywriter

爆款文案生成(按次计费)

小红书/抖音/公众号等多平台文案,一次给 3 个版本。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterstonebriefrequiredplatformrequestId

translate

翻译与母语级润色(按次计费)

10 种语言,直译+润色+术语表三档输出。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterstextrequiredstyletargetrequiredrequestId

sqlgen

SQL 生成与优化(按次计费)

按表结构生成/优化 SQL,自动拦截破坏性语句。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParametersschemadialectquestionrequiredrequestId

testgen

单元测试生成(按次计费)

为核心代码生成可运行的单元测试(自动 mock 外部依赖)。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterscoderequiredlanguageframeworkrequestId

docgen

技术文档生成(按次计费)

README / API 文档 / 变更日志 / 技术方案一键生成。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterssourcerequireddocTypeaudiencerequestId

resume

简历优化与岗位匹配(按次计费)

按 JD 诊断匹配度并用 STAR 结构重写(绝不虚构经历)。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParametersjdgoalresumerequiredrequestId

contract

合同条款风险审查(按次计费)

标出高/中风险条款与缺失条款,并给出可替换表述。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterstextrequiredpartyrequestId

script

短视频脚本与分镜(按次计费)

开头钩子 3 版 + 分镜表 + 口播文案,可直接拍摄。按次计费:业务成功才确认扣款,内容违规、模型超时或生成失败会自动全额退款。

ParameterstopicrequireddurationplatformrequestId

get_order

查询订单

按订单号查询一笔调用的状态、金额、耗时与失败原因。不收费。

ParametersorderNorequired

list_orders

订单列表

列出最近的调用订单,可按状态或平台过滤,用于对账。不收费。

Parameterslimitstatusplatform

skill_info

技能与定价信息

返回当前技能是否上架、单次价格、支持的编程语言与免责声明。不收费。

Takes no parameters.

Version history

1
  1. v1.0.4LatestOct 18, 2026

Score

100% of the applicable checks met

How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.

  • Reached in the last 30 daysRequired25 pts
  • Auth declaredRequired10 pts
  • Tools listedRequired15 pts
  • DescriptionRequired15 pts
  • Logo10 pts
  • Documentation15 pts
  • License10 pts