mcpField
C
Code Refactor

Code Refactor

Remote
code-refactor-api.app.workbuddy.hostDeveloper Tools0Updated 2w ago

About Code Refactor

Code Refactor is an MCP server that provides code-refactoring tools for developers working with legacy code. It can switch between local Ollama and OpenAI-compatible cloud endpoints, returning revised code with an explanation.

Key features

  1. 01Refactor code from a task description
  2. 02Return revised code and an explanation
  3. 03Check backend availability and model details
  4. 04Use local Ollama or a cloud endpoint
  5. 05Configure credentials and models through environment variables

Use cases

  1. 01Modernize legacy code
  2. 02Restructure code for a specific task
  3. 03Check whether the current inference backend is available

MCP support

The MCP server exposes the `refactor_code` and `check_status` tools to clients and can be registered in WorkBuddy connector configuration.

Configuration

Remote servers need no local install. Pick your client, then copy the config or install in one click.

Endpointhttps://code-refactor-api.app.workbuddy.host/mcp
Copy install command
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

Run commands in a terminal; paste JSON into the client’s MCP config and restart. Servers that need sign-in will prompt on first connect.

Packages
npmworkbuddy-code-refactor-connector1.0.4

Tools

Details

From the project README

workbuddy-code-refactor-connector

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

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

功能

暴露两个 MCP 工具:

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

安装

npm install -g workbuddy-code-refactor-connector

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

npx workbuddy-code-refactor-connector

配置

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

方式一:本地 Ollama(默认,代码不出本机)
REFACTOR_BACKEND=ollama          # 默认值,可省略
OLLAMA_HOST=http://127.0.0.1:11434
OLLAMA_MODEL=deepseek-coder
方式二:云端 OpenAI 兼容接口
REFACTOR_BACKEND=openai
OPENAI_BASE_URL=https://api.deepseek.com/v1
OPENAI_MODEL=deepseek-flash
OPENAI_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)中登记本服务:

{
  "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

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.