RoslynMcpServer
Model Context Protocol server for Roslyn-powered C# refactoring operations
Install / Use
/learn @JoshuaRamirez/RoslynMcpServerQuality Score
Category
Development & EngineeringSupported Platforms
README
Roslyn MCP Server
Let AI assistants like Claude safely refactor your C# codebase using the same Roslyn compiler platform that powers Visual Studio.
Roslyn MCP Server is a Model Context Protocol (MCP) server that exposes 41 Roslyn-powered tools to AI assistants and other MCP clients. It combines 19 refactoring operations, 5 code navigation tools, 6 analysis and metrics tools, 4 code generation tools, and 7 code conversion tools -- giving your AI deep code intelligence, comprehensive refactoring, and modern C# syntax transformations with full solution-wide reference tracking and preview support.
Table of Contents
- Why RoslynMcpServer?
- Prerequisites
- Quick Start
- Standalone CLI
- Configuration
- Available Tools
- Preview Mode
- Troubleshooting
- NuGet Libraries
- Contributing
- License
Why RoslynMcpServer?
- 41 tools -- refactoring, navigation, analysis, generation, and conversion tools, the most comprehensive Roslyn MCP server available
- Preview mode on every operation -- see exactly what will change before applying
- Atomic file writes with rollback -- if any file write fails, all changes are reverted
- Solution-wide reference updates -- renames and moves propagate across your entire solution
- Single command install --
dotnet tool install -g RoslynMcp.Server, no repo cloning needed - Cross-platform -- works on Windows, Linux, and macOS
Prerequisites
Before installing, make sure you have:
- .NET 9.0 SDK or later -- Download here
- A C# solution (
.slnor.slnx) or project (.csproj) to work with
Verify your .NET SDK version:
dotnet --version
The output should be 9.0.x or higher.
Quick Start
1. Install
dotnet tool install -g RoslynMcp.Server
2. Configure
Create a .mcp.json file in your project root (for Claude Code):
{
"mcpServers": {
"roslyn-refactor": {
"type": "stdio",
"command": "roslyn-mcp",
"args": []
}
}
}
Then restart Claude Code or run /mcp to connect.
3. Verify
Ask Claude:
"Run the roslyn diagnose tool for my solution at C:/path/to/MySolution.sln"
You should see a health report with Roslyn version, MSBuild status, and workspace details.
4. Try It
Ask Claude:
"Rename the class UserService to AccountService in C:/path/to/MySolution.sln"
Claude will use the rename_symbol tool to rename the class and update every reference across your entire solution.
Standalone CLI
All 41 tools are also available as a standalone CLI for use in scripts, CI/CD pipelines, and terminals without an AI assistant.
Install
dotnet tool install -g RoslynMcp.Cli
Usage
roslyn-cli <solution-path> <tool-name> [--option value ...]
roslyn-cli <tool-name> --help
roslyn-cli --help
Examples
# Check environment health
roslyn-cli C:/path/to/MySolution.sln diagnose --format text
# Rename a symbol across the entire solution
roslyn-cli C:/path/to/MySolution.sln rename-symbol --source-file C:/path/to/Foo.cs --symbol-name Bar --new-name Baz
# Get compiler diagnostics (errors only), pipe to jq
roslyn-cli C:/path/to/MySolution.sln get-diagnostics --severity-filter Error | jq '.data'
# Preview a refactoring without applying
roslyn-cli C:/path/to/MySolution.sln extract-method --source-file Foo.cs --start-line 10 --end-line 20 --method-name DoWork --preview
Output is JSON by default (pipeable to jq). Use --format text for human-readable output. Exit codes: 0=success, 1=tool error, 2=CLI error, 3=environment error.
Configuration
Claude Code
Create .mcp.json in your project root:
{
"mcpServers": {
"roslyn-refactor": {
"type": "stdio",
"command": "roslyn-mcp",
"args": []
}
}
}
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"roslyn-refactor": {
"command": "roslyn-mcp",
"args": []
}
}
}
Config file locations:
| OS | Path |
|---------|-------------------------------------------------------------|
| Windows | %APPDATA%\Claude\claude_desktop_config.json |
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
Available Tools
All tools accept a solutionPath parameter (absolute path to a .sln, .slnx, or .csproj file). Refactoring tools also accept a preview parameter (set to true to see changes without applying them).
Move and Rename
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| move_type_to_file | Move a C# type declaration to a different file. Updates all references automatically. | sourceFile, symbolName, targetFile, createTargetFile |
| move_type_to_namespace | Change the namespace of a C# type. Updates all using directives and qualified references. | sourceFile, symbolName, targetNamespace, updateFileLocation |
| rename_symbol | Rename any C# symbol (type, method, property, field, variable, etc.) with automatic reference updates across the solution. | sourceFile, symbolName, newName, line, column, renameOverloads, renameFile |
Extract
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| extract_method | Extract selected code into a new method. Automatically detects parameters and return values. | sourceFile, startLine, startColumn, endLine, endColumn, methodName, visibility |
| extract_variable | Extract an expression to a local variable. | sourceFile, startLine, startColumn, endLine, endColumn, variableName, useVar |
| extract_constant | Extract a literal value to a named constant. | sourceFile, startLine, startColumn, endLine, endColumn, constantName, visibility, replaceAll |
| extract_interface | Extract an interface from a class's public members. | sourceFile, typeName, interfaceName, members, targetFile |
| extract_base_class | Extract members to a new base class. | sourceFile, typeName, baseClassName, members, targetFile, makeAbstract |
Inline
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| inline_variable | Inline a local variable by replacing all usages with its initializer value. | sourceFile, variableName, line |
Signature and Encapsulation
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| change_signature | Add, remove, or reorder method parameters and update all call sites. | sourceFile, methodName, parameters (array of changes), line |
| encapsulate_field | Convert a field to a property with backing field. | sourceFile, fieldName, propertyName, readOnly |
Generate
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| generate_constructor | Generate a constructor that initializes fields and/or properties of a type. | sourceFile, typeName, members, addNullChecks |
| generate_overrides | Generate override methods for base class virtual/abstract members. | sourceFile, typeName, members, callBase |
| implement_interface | Generate interface member implementations for a type. | sourceFile, typeName, interfaceName, explicitImplementation, members |
Convert
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| convert_to_async | Convert a synchronous method to async/await pattern. | sourceFile, methodName, line, renameToAsync |
| convert_expression_body | Toggle between expression body (=> expr;) and block body ({ return expr; }). | sourceFile, direction, memberName, line |
| convert_property | Convert between auto-property and full property with backing field. | sourceFile, direction, propertyName, line |
| convert_foreach_linq | Convert foreach loops with Add patterns to LINQ Select/Where expressions. | sourceFile, line |
| convert_to_pattern_matching | Convert if/is chains and switch statements to switch expressions. | sourceFile, line |
| convert_to_interpolated_string | Convert string.Format() calls and concatenation to interpolated strings. | sourceFile, line |
| introduce_parameter | Promote a local variable to a method parameter, updating all call sites. | sourceFile, variableName, line |
Using Directives
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| add_missing_usings | Add missing using directives required to resolve unbound type references. Process a single file or all files in the solution. | sourceFile, allFiles |
| remove_unused_usings | Remove unused using directives. Process a single file or all files in the solution. | sourceFile, allFiles |
| sort_usings | Sort using directives alphabetically in a C# file. | sourceFile
