# RoslynMcpServer [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/JoshuaRamirez/RoslynMcpServer  
**GitHub Stars:** 37  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/roslynmcpserver

## Description
Model Context Protocol server for Roslyn-powered C# refactoring operations

## Tools
Capabilities this server exposes over MCP:

- **move_type_to_file** — Move a C# type declaration to a different file. Updates all references automatically. (`line` disambiguates same-named top-level types by line (the declaration's start line, i.e. its first attribute list or modifier, or the type identifier's line; a line that matches more than one is `SymbolAmbiguo…
- **move_type_to_namespace** — Change the namespace of a C# type. Updates all using directives and qualified references. (`line` disambiguates same-named top-level types by line (the declaration's start line, i.e. its first attribute list or modifier, or the type identifier's line; a line that matches more than one is `SymbolAmb…
- **rename_symbol** — Rename any C# symbol (type, method, property, field, variable, etc.) with automatic reference updates across the solution. Process a single symbol or all files in the solution. `allFiles: true` walks every C# file and renames every eligible declaration whose simple name equals `symbolName` to `newN…
- **rename_file_to_match_type** — Rename a source file so its name matches the primary type declared in it, without renaming the type or its references. Process a single file or all files in the solution. `allFiles: true` walks every C# file and renames each unambiguous mismatched single-type file; optional `sourceFile` when true l…
- **rename_namespace** — Rename a C# namespace across the solution, updating declarations, using directives, and qualified name references. Does not move folders by default. (`column` picks the smallest namespace whose name or declaration span covers that 1-based column when set with `line` — name preferred, then smallest…
- **extract_method** — Extract selected code into a new method. Automatically detects parameters and return values. Process a single site or all files in the solution. `allFiles: true` walks every C# file and extracts every eligible contiguous ≥2-statement proper-subset run inside method/accessor/local-function blocks un…
- **extract_variable** — Extract an expression to a local variable. Process a single site or all files in the solution. `allFiles: true` walks every C# file and extracts every eligible outermost non-trivial expression (invocation / object creation / binary / conditional / element access / await / cast / interpolated string…
- **extract_constant** — Extract a literal value to a named constant. Process a single site or all files in the solution. `allFiles: true` walks every C# file and extracts every eligible compile-time literal (constant named from the literal value); `sourceFile` is optional when true; cannot be combined with `startLine`, `s…
- **extract_interface** — Extract an interface from a class's public members (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps today's typeName `FirstOrDefault` pi…
- **extract_base_class** — Extract members (methods, properties, fields, events, and indexers) to a new base class (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps…
- **pull_members_up** — Move selected members (methods, properties, fields, events, and indexers) from a derived type onto an existing base class or interface (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest contain…
- **push_members_down** — Move selected members (methods, properties, fields, events, and indexers) from a base type down onto derived types (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including…
- **use_base_type** — Replace derived-type references with a compatible base type or interface (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps today's typeNa…
- **introduce_field** — Turn a selected local variable or expression into a class field, optionally initializing it in a constructor. Process a single site or all files in the solution. `allFiles: true` walks every C# file and promotes every eligible local (field named from that local); `sourceFile` is optional when true;…
- **safe_delete** — Delete a selected symbol only when it has no remaining references. If usages exist, reject with their locations. Process a single site or all files in the solution. `allFiles: true` walks every C# file and deletes every eligible unused private (or local) declaration under today's single-site valida…
- **make_static** — Make a selected instance method static when it does not use instance state. Adds the static modifier and updates call sites and method-group conversions to the containing type name. Process a single method or all files in the solution. `allFiles: true` walks every C# file and makes every eligible o…
- **make_non_static** — Make a selected static method an instance method when a valid instance receiver exists. Removes the static modifier and updates type-name call sites and method-group conversions to an instance receiver (or `this` in the same type). Process a single method or all files in the solution. `allFiles: tr…
- **invert_if** — Flip an if-statement condition and swap the if/else branches, preserving semantics. Comparison operators are inverted (`>` ↔ `<=`, `==` ↔ `!=`, …); `&&` /
- **add_braces** — Add braces to control statements (`if`, `else`, `for`, `foreach`, `while`, `using`) that have a single-statement body, preserving semantics. Process a single file or all files in the solution (`allFiles: true` walks every C# file at file scope; optional `sourceFile` when true limits the walk; omitt…
- **remove_braces** — Remove braces from control statements (`if`, `else`, `for`, `foreach`, `while`, `using`) whose body is a single-statement block, preserving semantics. Process a single file or all files in the solution (`allFiles: true` walks every C# file at file scope; optional `sourceFile` when true limits the w…
- **simplify_name** — Remove redundant namespace qualifications from type (and similar) references when a using directive or the current namespace already makes the short name bind to the same symbol. Process a single file or all files in the solution (`allFiles: true` walks every C# file; optional `sourceFile` when tru…
- **inline_method** — Inline a method by replacing call sites with the method body. Optionally remove the method (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line identifier start-line pick so a continuation-line identifier still…
- **inline_variable** — Inline a local variable by replacing all usages with its initializer value (`column` picks the declaration whose identifier or declaration span covers that column; omitted keeps today's variableName + optional line start-line pick so a continuation-line identifier still needs `column` when `line` i…
- **inline_constant** — Inline a const field by replacing references with a formatted literal. Optionally remove the constant (`line` picks the matching const field whose identifier or declaration span covers that 1-based line when several constants share the name — identifier preferred, then smallest covering declarator/…
- **change_signature** — Add, remove, or reorder method parameters and update all call sites (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName and/or line start-line pick so a continuation-line identifier still needs `column` when `line` is the ide…
- **add_parameter** — Add a named parameter to a method and update call sites, overrides, and interface implementations (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line start-line pick so a continuation-line identifier still nee…
- **remove_parameter** — Remove a named parameter from a method and drop matching call-site arguments, updating overrides and interface implementations (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line start-line pick so a continuat…
- **reorder_parameters** — Reorder a method's parameters by a 0-based permutation and update positional call-site arguments, updating overrides and interface implementations (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line start-line…
- **change_return_type** — Change a method's return type and update return statements when the conversion is safe, updating overrides and interface implementations (`column` picks the smallest method whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line start-line pick so a…
- **encapsulate_field** — Convert a field to a property with backing field (`line` picks the field whose identifier or declaration span covers that 1-based line when several fields share the name — identifier preferred, then smallest covering declarator/field, including nested types; omitted keeps today's fieldName first-ma…
- **generate_constructor** — Generate a constructor that initializes fields and/or properties of a type (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps today's type…
- **generate_property** — Generate a property on a type: auto-property `{ get; set; }`, init-only `{ get; init; }`, or a backing-field form when a field is the target (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest c…
- **generate_method_stub** — Generate a method from an undefined call site, inferring the signature from usage (`throwNotImplemented`: default true emits `throw new NotImplementedException();`; false uses default-return / empty void bodies via `SyntaxGenerationHelper.CreateDefaultReturnBody`; async `Task` / `Task<T>` unwrap so…
- **generate_overrides** — Generate override methods, properties/indexers, and events for base class virtual/abstract members (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; om…
- **implement_interface** — Generate interface member implementations for a type (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps today's typeName `FirstOrDefault`…
- **implement_abstract** — Generate implementation stubs for unimplemented abstract members inherited by a selected class — methods, properties, indexers, and events (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest con…
- **convert_to_async** — Convert a synchronous method to async/await pattern (`column` picks the method whose identifier or declaration span covers that column; omitted keeps today's MethodName + Line pick so a continuation-line identifier still needs `column`; `renameToAsync`: default true rewrites call-site identifiers t…
- **convert_expression_body** — Toggle between expression body (`=> expr;`) and block body (`{ return expr; }`) (`direction`: `ToExpressionBody` / `ToBlockBody`; `column` picks the member whose identifier or declaration span covers that column on the given line; omitted keeps today's first-match-on-the-line pick; `preview` descri…
- **convert_to_block_body** — Convert a selected expression-bodied member (`=> expr`) to a block body. Methods become `{ return expr; }` or `{ expr; }` as appropriate; properties and accessors that are expression-bodied are converted too (`column` picks the member whose identifier or declaration span covers that column on the g…
- **convert_property** — Convert between auto-property and full property with backing field (`direction`: `ToAutoProperty` / `ToFullProperty`; `column` picks the smallest property whose identifier or declaration span covers that column on the given line; omitted keeps today's propertyName and/or line start-line pick so ind…
- **convert_foreach_linq** — Convert foreach loops with Add patterns to LINQ (`preferQuerySyntax`: default false keeps today's method syntax `.Where().Select().ToList()`; true emits query syntax (`from … where … select`) for filter / project / filter+project / ToList-after-query, preserving an explicitly typed foreach element…
- **convert_anonymous_to_class** — Convert an anonymous type (`new { ... }`) to a named class or record, replacing same-shape anonymous creations in the solution (`column` picks the anonymous creation whose span covers that 1-based column when set with `line` — exclusive-end covering-span, today's unique covering match, else CannotC…
- **convert_tuple_to_struct** — Convert a tuple (`(int X, int Y)` / `(1, 2)` / `ValueTuple`) to a named struct, replacing same-shape tuple creations in the solution (`column` picks the tuple creation whose span covers that 1-based column when set with `line` — exclusive-end covering-span, today's unique covering match, else Canno…
- **convert_to_pattern_matching** — Convert if/is chains and switch statements to switch expressions (`column` picks the smallest switch or if whose span covers that column on the given line; omitted keeps today's first start-line switch-then-if pick so indented statements still convert; `preview` describes the rewrite and writes not…
- **convert_to_interpolated_string** — Convert string.Format() calls and concatenation to interpolated strings (`column` picks the Format invocation or concatenation whose span covers that column on the given line; omitted keeps today's first-match-on-the-line pick so indented expressions still convert; `preview` describes the rewrite a…
- **introduce_parameter** — Promote a local variable to a method parameter, updating all call sites (`column` picks the matching local whose identifier or declaration span covers that 1-based column when set with `line` — identifier preferred, then smallest covering declarator, same exclusive-end coverage as `encapsulate_fiel…
- **add_missing_usings** — Add missing using directives required to resolve unbound type references. Process a single file or all files in the solution (`allFiles: true` walks every C# file; optional `sourceFile` when true limits the walk; `preview` returns computed changes without applying).
- **remove_unused_usings** — Remove unused using directives. Process a single file or all files in the solution (`allFiles: true` walks every C# file; optional `sourceFile` when true limits the walk; `preview` returns computed changes without applying).
- **sort_usings** — Sort using directives alphabetically in a C# file. Process a single file or all files in the solution (`allFiles: true` walks every C# file; optional `sourceFile` when true limits the walk; `systemFirst` places System / System.* first by default; `preview` returns computed changes without applying).
- **diagnose** — Check the health of the Roslyn MCP server environment and workspace status.
- **find_references** — Find all references to a symbol across the entire solution. Returns file locations, context snippets, and write/definition indicators. Optional `includeDeclaration` (default `true`) set to `false` returns usages only, excluding the symbol's own definition locations before `maxResults` is applied. O…
- **go_to_definition** — Navigate to the source definition of a symbol. Supports partial classes with multiple definition locations. Optional `maxResults` caps the returned Definitions list (omit = no cap; peer of `get_type_hierarchy` / `find_implementations`); result includes `Truncated` when capped. Optional `definitionF…
- **get_symbol_info** — Get detailed metadata for any symbol: kind, accessibility, modifiers, base types, interfaces, members, parameters, return type, and XML documentation. Optional `kindFilter` (same values and case-insensitive parsing as `search_symbols` / `get_document_outline` `kindFilter`) keeps only Members of tha…
- **find_implementations** — Find all implementations of an interface or overrides of an abstract/virtual member. Optional `implementationFile` restricts reported implementations to those declared in that absolute `.cs` file (a partial type matches when any of its parts is in that file and is reported there; applied before `ma…
- **search_symbols** — Search for symbols by name pattern across the entire workspace or a specific file. Filter by kind (class, method, property, etc.). Optional `sourceFile` restricts results to symbols whose in-source declaration location is that file (peer of `get_diagnostics`; omit = whole solution). Optional `caseS…
- **get_diagnostics** — Retrieve compiler diagnostics (errors, warnings, info) filtered by severity and optionally by file. Optional `maxResults` caps the returned list (omit = no cap; peer of `search_symbols` / `find_references`); result includes `Truncated` when capped. Optional `diagnosticIds` (e.g. `["CS0168"]`, case-…
- **get_code_metrics** — Calculate code metrics: cyclomatic complexity, lines of code, maintainability index, class coupling, depth of inheritance. Optional `column` disambiguates same-named symbols the same way `find_callers` does when set with `line`; omitted keeps today's Line-only / file-level path (file-level when nei…
- **analyze_control_flow** — Analyze control flow for a code region: start/end point reachability, return statements, and exit points. Optional `startColumn` / `endColumn` trim the region (1-based; Roslyn `Character = column - 1`; exclusive-ish end as `TextLine.End`); omitted keeps today's whole-line span (start of `startLine`…
- **analyze_data_flow** — Analyze data flow for a code region: variables read/written inside, data flowing in/out, captured variables. Optional `startColumn` / `endColumn` trim the region (1-based; Roslyn `Character = column - 1`; exclusive-ish end as `TextLine.End`); omitted keeps today's whole-line span (start of `startLi…
- **find_callers** — Find all callers of a symbol across the entire solution. Optional `callerFile` restricts reported call sites to callers located in that absolute `.cs` file (applied before `maxResults`, so `totalCount` / `truncated` reflect the filtered set; nonexistent file → `SourceFileNotFound`); omitted keeps t…
- **get_type_hierarchy** — Retrieve the type hierarchy (base types and/or derived types) for a given type. Optional `maxResults` caps the returned DerivedTypes list (omit = no cap; peer of `find_implementations` / `get_diagnostics`); result includes `Truncated` when capped. BaseTypes and Interfaces are not capped. Optional `…
- **get_document_outline** — Get a hierarchical outline of all symbols in a file (namespaces, types, members). Optional `maxDepth` (>= 1) drops entries deeper than N (1 = top-level entries only; omit = no depth cap). Optional `maxResults` caps the returned outline tree via DFS pre-order, applied after `maxDepth` (omit = no cap…
- **generate_equals_hashcode** — Generate Equals() and GetHashCode() overrides for a type based on its fields/properties (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps…
- **generate_tostring** — Generate a ToString() override for a type (`line` picks the type whose identifier or declaration span covers that 1-based line when several types share the name — identifier preferred, then smallest containing type, including nested types; omitted keeps today's typeName `FirstOrDefault` pick so two…
- **format_document** — Format a C# file using Roslyn's built-in formatter. Process a single file or all files in the solution (`allFiles: true` walks every C# file; optional `sourceFile` when true limits the walk; `preview` returns computed changes without applying).
- **add_null_checks** — Add null-check statements (ArgumentNullException.ThrowIfNull or guard clauses) for method or constructor parameters (`column` picks the smallest method or constructor whose identifier or declaration span covers that column; omitted keeps today's methodName + optional line start-line pick so a conti…

## Claude Desktop Quick Installation
No confirmed install details yet, so no config is published. Follow the setup steps in the repository above.

## Documentation

## What RoslynMcpServer does

RoslynMcpServer connects MCP clients to the Roslyn compiler platform for compiler-aware C# development tasks. It exposes 66 tools grouped across five areas: 37 refactoring operations, five navigation tools, six analysis and metrics tools, five code-generation tools, and 13 code-conversion tools.

The server works with a C# solution or project identified by an absolute path to a `.sln`, `.slnx`, or `.csproj` file. Operations can inspect code, apply structural changes, update references, and transform modern C# syntax. Examples include renaming symbols throughout a solution, moving types between files or namespaces, retrieving compiler diagnostics, and extracting a method.

## How it works

MCP clients communicate with the installed `roslyn-mcp` executable over stdio. Each tool receives a `solutionPath`; refactoring tools additionally accept `preview: true` to return the proposed changes without writing them. Symbol changes use Roslyn’s understanding of declarations and references, allowing renames and moves to propagate across the solution instead of relying on plain-text replacement.

File updates are atomic: if a write fails, the server rolls back the changes. The server also tracks references across the solution for supported operations. A separate `roslyn-cli` package exposes the same 66 tools for shell scripts, CI/CD pipelines, and direct terminal use, with JSON output by default and optional text formatting.

## Setup and configuration

Install the MCP server as a global .NET tool:

```bash
dotnet tool install -g RoslynMcp.Server
```

The host machine needs the .NET 9.0 SDK or newer and a C# solution or project to process. For Claude Code, add a `.mcp.json` file in the project root:

```json
{
  "mcpServers": {
    "roslyn-refactor": {
      "type": "stdio",
      "command": "roslyn-mcp",
      "args": []
    }
  }
}
```

Claude Desktop uses the same command in its `claude_desktop_config.json` file. On Windows, that file is under `%APPDATA%/Claude`; on macOS, it is under `~/Library/Application Support/Claude`.

## Tools and capabilities

- Refactor C# symbols, types, namespaces, and methods.
- Rename declarations and update references across a solution.
- Move types to files or namespaces, including supported all-file workflows.
- Navigate code and inspect compiler diagnostics, metrics, and workspace health.
- Generate C# code and convert code to newer syntax forms.
- Preview refactoring changes before applying them.
- Run operations from scripts with the standalone CLI.

The `diagnose` tool can report Roslyn version, MSBuild status, and workspace details. The CLI supports commands such as `get-diagnostics`, `rename-symbol`, and `extract-method`, plus help output for individual tools.

## Limitations and notes

The server requires the .NET 9.0 SDK or later and a local C# solution or project. MCP configuration examples use stdio rather than a network endpoint. Refactoring behavior depends on the selected symbol and operation: constructors, destructors, operators, source-generated documents, linked multi-views, nested types, collisions, and other ineligible targets may be skipped by particular tools. Use preview mode to inspect a proposed change before allowing file writes.

The CLI returns exit code 0 for success, 1 for a tool error, 2 for a CLI error, and 3 for an environment error. Its output is JSON unless text format is requested.

_Full upstream README: https://allmcps.com/mcp/roslynmcpserver/readme_

