# Code Refactor

> Code Refactor is an open-source MCP server for developer tools. Refactor legacy code into modern, idiomatic code through a local or cloud model backend. It can run locally on your machine or as a hosted remote server.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, self-hosted, API
- **Website:** https://code-refactor-api.app.workbuddy.host
- **Repository:** https://github.com/zhouhengchang/code-refactor/tree/HEAD/workbuddy-connector/server
- **MCP Registry name:** io.github.zhouhengchang/code-refactor
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-11-18

## About

Two tools sit behind this connector. refactor_code takes source code, a description of the refactoring task and an optional language hint, and returns the refactored code with an explanation, while check_status reports whether the inference backend is reachable and which model it uses. The connector was written for WorkBuddy, with Chinese-language documentation.

The model work happens in a backend you pick through environment variables. The default is a local Ollama server, which keeps code on your machine, and the alternative is any OpenAI-compatible cloud endpoint such as DeepSeek, for higher refactoring quality. Calls have a timeout of 180 seconds by default, which is longer to allow slow CPU-only inference, and errors are returned as readable messages instead of stack traces.

It can run over stdio through npx or as a hosted streamable-HTTP endpoint, and no keys are hard-coded. The README states an MIT licence.

## Features

- **Refactor tool:** refactor_code takes code, a task description and an optional language.
- **Backend health check:** check_status shows backend and model availability.
- **Local-first default:** Ollama keeps code on the machine by default.
- **Cloud option:** Any OpenAI-compatible endpoint can be used, such as DeepSeek.
- **Configurable timeout:** Per-call timeout defaults to 180 seconds and can be raised.
- **No hard-coded keys:** Addresses, models and keys come from environment variables.

## Good for

- Modernise an old function without rewriting it by hand
- Run refactoring fully offline with a local model
- Switch to a stronger cloud model for hard refactors
- Check that the model backend is running before a batch

## Install

### Claude Code (Terminal)

```sh
claude mcp add --transport http code-refactor https://code-refactor-api.app.workbuddy.host/mcp
```

### Claude Desktop (Settings → Connectors → Add custom connector)

```sh
https://code-refactor-api.app.workbuddy.host/mcp
```

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "code-refactor": {
      "url": "https://code-refactor-api.app.workbuddy.host/mcp"
    }
  }
}
```

### VS Code (.vscode/mcp.json)

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

### Windsurf (~/.codeium/windsurf/mcp_config.json)

```json
{
  "mcpServers": {
    "code-refactor": {
      "serverUrl": "https://code-refactor-api.app.workbuddy.host/mcp"
    }
  }
}
```

### Other clients (your client's MCP settings (most use this shape))

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

## Tools

- `refactor_code`: Refactors source code given a task description and optional language hint, returning code and notes
- `check_status`: Checks whether the inference backend is available and reports backend and model

## FAQ

### Does my code leave my machine?

Not with the default Ollama backend. Choosing the OpenAI-compatible backend sends code to that endpoint.

### Which models work?

Any Ollama model such as qwen2.5-coder, or any OpenAI-compatible model such as deepseek-chat.

### How is it installed?

Run it with npx workbuddy-code-refactor-connector or install the npm package globally.

### What licence is it?

MIT, according to the README.

### Is Code Refactor free?

Yes. Code Refactor is open source, so you can use and self-host it for free.

### How do I add Code Refactor to Claude Code?

Run this command in your terminal: claude mcp add --transport http code-refactor https://code-refactor-api.app.workbuddy.host/mcp

### What are the best alternatives to Code Refactor?

The closest alternatives to Code Refactor are REA, Context7, Chrome DevTools MCP, Codebase Memory and GitHub.

## Where this comes from

- Description: written from the project's README and the project's website.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [Context7](https://ai-powered.com/mcp/context7): Context7 is a freemium MCP server for developer tools.
- [Chrome DevTools MCP](https://ai-powered.com/mcp/chrome-devtools-mcp-2): Chrome DevTools MCP is an open-source MCP server for browser automation.
- [Codebase Memory](https://ai-powered.com/mcp/codebase-memory): Codebase Memory is an open-source MCP server for knowledge and memory.
- [GitHub](https://ai-powered.com/mcp/github-2): GitHub is an open-source MCP server for developer tools.
- [Serena MCP: the IDE for your agent](https://ai-powered.com/mcp/serena-mcp-the-ide-for-your-agent): Serena MCP: the IDE for your agent is an open-source MCP server for developer tools.
- [awesome-mcp-servers](https://ai-powered.com/mcp/awesome-mcp-servers-2): awesome-mcp-servers is an open-source MCP server for developer tools.
- [XERJ](https://ai-powered.com/mcp/xerj): XERJ is an open-source MCP server for knowledge and memory.

---
Source: https://ai-powered.com/mcp/code-refactor
