Labsco
MCP SERVER

RefactorMCP

by dave-hillier

Roslyn refactorings for C# as tools — extract, move, inline and safe delete, applied by the compiler's own analysis.

Code Generation, Scaffolding & Migration
Summary
Refactorings the model cannot get subtly wrong.

Asking a model to move a method usually produces plausible code with a broken reference somewhere out of view. Routing the change through Roslyn means the rename, the call sites and the dependency injection are handled by the same analysis the compiler uses — and Safe Delete simply refuses when something still depends on the thing you asked it to remove.

What it is

A Model Context Protocol server exposing Roslyn-based refactorings for C#. The transformations are the ones an IDE performs, driven by the compiler's understanding of the code rather than by text editing, so a move that would break a reference is a move the tool declines.

What you get
  • Extract Method, Extract Class and Inline Method
  • Introduce Field, Introduce Parameter and Introduce Variable from a selected expression
  • Convert to Static, Make Static Then Move, and Move Static Method — the last leaving a wrapper behind in the original class
  • Move Instance Method with `methodNames`, `constructor-injections` and `parameter-injections` to control how dependencies travel, plus bulk variants that move several methods at once as instance members or as statics with an added `this` parameter
  • Move Type to Separate File, naming the file after the type
  • Make Field Readonly and Transform Setter to Init, both moving initialisation into constructors
  • Constructor Injection, turning method parameters into injected fields or properties
  • Safe Delete, which removes a field or variable only after dependency checks pass
  • Extract Decorator, Create Adapter, Add Observer and Use Interface for the structural changes
  • List Tools, which prints every available refactoring as a kebab-case name, plus `metrics://` and `summary://` resources
Requirements

.NET. Run the console application directly with `dotnet run --project RefactorMCP.ConsoleApp`, or host it as the MCP server. Licensed under the Mozilla Public License 2.0. Two documented limits are worth knowing before you plan a large refactor: Extract Method does not handle expression-bodied methods, and Introduce Field fails if a field of that name already exists. The repository also carries a VS Code extension package, `refactor-mcp-extension`.