Extract MethodLABSCO 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-injectionsandparameter-injectionsto control how dependencies travel, plus bulk variants that move several methods at once as instance members or as statics with an addedthisparameter - 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://andsummary://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.
Setup effort
Follow the published steps — dotnet run --project RefactorMCP.ConsoleApp
USE CASES
Breaking up a class that grew too large
Extract the cohesive members into a new class, then move the methods that belong with them and let the source delegate.
Moving behaviour without breaking its dependencies
Relocate instance methods to another class, choosing whether each dependency travels by constructor injection or as a parameter.
Tightening a type after the design settled
Make fields readonly, convert setters to init-only, and let the initialisation move into constructors for you.
Removing code you think is dead
Ask for a safe delete and let the dependency check decide, instead of deleting and running the build.
20 tools
Listed in project docs. Your client may show a different list.
Introduce Field/Parameter/VariableConvert to StaticMove Static MethodMove Instance MethodMove Multiple Methods (instance)Move Multiple Methods (static)Make Static Then MoveMove Type to Separate FileMake Field ReadonlyTransform Setter to InitConstructor InjectionSafe DeleteExtract ClassInline MethodExtract DecoratorCreate AdapterAdd ObserverUse InterfaceList ToolsBEFORE YOU INSTALL
What to know first
Tools you get
20 tools named in the project's documentation. These are refactoring labels; the server lists its actual tools under kebab-case names the documentation doesn't print. One entry, Introduce Field/Parameter/Variable, covers three refactorings, so the real count may be higher.
Requires
.NET 9 SDK (dotnet on PATH)
Where it runs
The documented client runs the server on your machine.
INSTALLATION
Connect your client
Server setup
git clone https://github.com/dave-hillier/refactor-mcp
cd refactor-mcp
dotnet run --project RefactorMCP.ConsoleAppMCP Clients
Any MCP client
The server talks over stdio, so the client starts it with the same dotnet run command. <YOUR_PATH_TO_REFACTOR_MCP_REFACTOR_MCP> is the RefactorMCP.ConsoleApp folder in your clone.
{
"mcpServers": {
"refactor-mcp": {
"command": "dotnet",
"args": [
"run",
"--project",
"<YOUR_PATH_TO_REFACTOR_MCP_REFACTOR_MCP>"
]
}
}
}