
RefactorMCP
โ 90from dave-hillier
Automated refactoring tools for C# code transformation using Roslyn.
๐ฅ๐ฅ๐ฅโ VerifiedFreeQuick setup
RefactorMCP
RefactorMCP is a Model Context Protocol server that exposes Roslyn-based refactoring tools for C#.
Available Refactorings
- Extract Method โ create a new method from selected code and replace the original with a call (expression-bodied methods are not supported).
- Introduce Field/Parameter/Variable โ turn expressions into new members; fails if a field already exists.
- Convert to Static โ make instance methods static using parameters or an instance argument.
- Move Static Method โ relocate a static method and keep a wrapper in the original class.
- Move Instance Method โ move one or more instance methods to another class and delegate from the source. If a moved method no longer accesses instance members, it is made static automatically. Provide a
methodNameslist along with optionalconstructor-injectionsandparameter-injectionsto control dependencies. - Move Multiple Methods (instance) โ move several methods and keep them as instance members of the target class. The source instance is injected via the constructor when required.
- Move Multiple Methods (static) โ move multiple methods and convert them to static, adding a
thisparameter. - Make Static Then Move โ convert an instance method to static and relocate it to another class in one step.
- Move Type to Separate File โ move a top-level type into its own file named after the type.
- Make Field Readonly โ move initialization into constructors and mark the field readonly.
- Transform Setter to Init โ convert property setters to init-only and initialize in constructors.
- Constructor Injection โ convert method parameters to constructor-injected fields or properties.
- Safe Delete โ remove fields or variables only after dependency checks.
- Extract Class โ create a new class from selected members and compose it with the original.
- Inline Method โ replace calls with the method body and delete the original.
- Extract Decorator โ create a decorator class that delegates to an existing method.
- Create Adapter โ generate an adapter class wrapping an existing method.
- Add Observer โ introduce an event and raise it from a method.
- Use Interface โ change a method parameter type to one of its implemented interfaces.
- List Tools โ display all available refactoring tools as kebab-case names.
Metrics and summaries are also available via the metrics:// and summary:// resource schemes.
Contributing
- Run
dotnet testto ensure all tests pass. - Format the code with
dotnet formatbefore opening a pull request.
License
Licensed under the Mozilla Public License 2.0.
Usage
Run the console application directly or host it as an MCP server:
Copy & paste โ that's it
dotnet run --project RefactorMCP.ConsoleAppFor usage examples see EXAMPLES.md.
No common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.