Install
$ agentstack add mcp-vudz-roslynmcpserver ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
RoslynMcpServer
[🇷🇺 Читать на русском (Russian Version)](#russian-version)
Why use this over standard FileSystem MCPs? Unlike basic file-reading servers, this Model Context Protocol (MCP) server leverages Roslyn. Your AI agent (Cursor, Cline, etc.) doesn't just read plain text—it sees C# code through the eyes of the compiler. It can get precise diagnostics without a full rebuild, apply built-in Roslyn code fixes (add using, implement interface, fix typos), find symbol references, and perform safe semantic refactoring, drastically reducing LLM hallucinations.
It is designed for AI-driven C# development (with secondary Python support), focusing on:
- Parsing and analyzing
*.sln/*.csprojvia Roslyn. - Safe, context-aware file read/write operations.
- CLI integration: running
dotnet build,dotnet test, and custom commands. - Compact responses optimized for LLM context windows, backed by detailed server-side logging.
⚠️ Security Disclaimer
This server grants the AI agent read, write, and execution privileges (via the dotnet CLI) within your workspace. Always use source control (Git) to track changes. Do not run the server as Administrator.
Prerequisites
- Strictly .NET 10 SDK installed on your machine. (Earlier SDK versions are not supported and will fail to build).
- An MCP-compatible IDE or client (e.g., Cursor, OpenCode, VS Code with Cline).
Setup & Connection (Local)
It is highly recommended to run the published executable. This ensures instant startup without the overhead of dotnet run. The project is configured with ReadyToRun enabled and PublishSingleFile disabled (to ensure Roslyn can dynamically load MSBuild and analyzer dependencies).
1. Publish the Server (Run once or after code updates)
From the repository root (replace the RID if you are not on Windows x64):
dotnet publish RoslynMcpServer.csproj -c Release -r win-x64
Your compiled binary will be at:
- Windows x64:
bin/Release/net10.0/win-x64/publish/RoslynMcpServer.exe - Linux/macOS: Same relative path under your specified
-rflag.
2. Configure the MCP Client
Option A: Via Cursor UI
- Go to Cursor Settings -> Features -> MCP -> + Add New MCP Server.
- Type:
stdio. - Command: Enter the absolute path to your published executable (e.g.,
D:\Devel\RoslynMcpServer\bin\Release\net10.0\win-x64\publish\RoslynMcpServer.exe).
Option B: Via mcp.json Add the absolute path to your configuration file (see the provided mcp.json and .cursor/mcp.json examples in the repo). Optional: Pass env with ROSLYN_MCP_WORKSPACE set to the repository root (folder containing global.json) so MSBuild.Locator and run_dotnet_build use the same SDK as your solution.
Option C: OpenCode (install2opencode.ps1)
After dotnet publish, the publish folder contains [install2opencode.ps1](install2opencode.ps1) and [AGENTS.md.sample](AGENTS.md.sample) next to RoslynMcpServer.exe.
From the root of the project you want to configure (your application repo):
cd D:\Devel\YourApp
& "D:\Devel\RoslynMcpServer\bin\Release\net10.0\win-x64\publish\install2opencode.ps1"
The script:
- Creates or updates
opencode.jsonin the target directory, registeringRoslynMcpServeras a local MCP server (type: local,enabled: true). - Creates or updates
AGENTS.md: if Roslyn MCP behavioral rules are not already present, merges content from the bundledAGENTS.md.sample(creates a new file or appends to an existing one).
| Parameter | Description | | --- | --- | | -BinaryPath | Optional. Absolute path to RoslynMcpServer.exe. When omitted, the script uses the binary next to itself. | | -ProjectPath | Optional. Target project root. Defaults to the current working directory. |
Restart OpenCode or reload MCP servers after running the script.
Agent tools by version
Tracks MCP tools relevant to [AGENTS.md.sample](AGENTS.md.sample) (copy into app repos as AGENTS.md). Current server version: see RoslynMcpServer.csproj.
v1.0.14
| Tool / behavior | Notes | |-----------------|--------| | run_dotnet_run | SDK-pinned dotnet run, separate stdout/stderr, timeout, truncated output (stderr tail for progress) | | run_nuget_audit | Structured vulnerability table from dotnet list package --vulnerable | | get_changed_files | Git porcelain status + suggested test projects (no diff body) | | load_workspace | Workspace health block: SDK/global.json, restore assets, tool count | | execute_dotnet_command | SDK pinning + truncated stdout/stderr | | find_usages / find_symbol_references | find_references family; prefer find_usages when only symbolName is known | | get_project_graph / list_projects | Project dependency graph | | rename_symbol | previewOnly=true default workflow | | run_format | dotnet format wrapper |
v1.0.13
| Tool / behavior | Notes | |-----------------|--------| | AssemblyReferenceResolver | Exact {name}.dll; deps.json + NuGet fallback | | DecompilerHost | NuGet / BCL / runtime pack resolver for ILSpy tools |
v1.0.10–v1.0.12
Build/test SDK pinning, VSTest parser, decompiler assemblyPath, MCP_MSBUILD_SDK_MISMATCH — see git history.
Not implemented (see AGENTS.md §7)
- Read-only TFS / HTTP probe MCP tools
- MCP «secret configured: yes/no» without reading values
- Unified diff in
get_changed_files(use host/shellgit diffwhen allowed)
Agent Initialization (How to force tool usage)
Even if the MCP is active, AI clients don't always load the tools into the current chat context. To ensure the agent utilizes RoslynMcpServer reliably, add the following instructions to your project rules (e.g., .cursor/rules/mcp.mdc or AGENTS.md).
OpenCode users: install2opencode.ps1 (see Option C above) writes or merges these rules into AGENTS.md automatically.
Canonical copy-paste file: this repo ships [AGENTS.md.sample](AGENTS.md.sample) with the same rules—copy it into your application repository as AGENTS.md or merge fragments into Cursor rules. When changing these instructions, update AGENTS.md.sample and the two collapsible AI Agent Behavioral Rules blocks below (English + Russian) together so they stay identical.
INITIALIZATION SEQUENCE: AI Agent Behavioral Rules — expand to read (same text as AGENTS.md.sample)
INITIALIZATION SEQUENCE: AI Agent Behavioral Rules
You are a Senior C# Developer and Architect. You have access to a specialized Roslyn MCP Server. To interact with this codebase safely and efficiently, you MUST strictly adhere to the following rules. Failure to do so will result in context window collapse or broken code.
Every time you start a new conversation or receive the first prompt in this project, you MUST silently perform the following steps before answering the user. THIS IS A STRICT BLOCKER:
- Call the MCP server to list available tools.
- Call
load_workspacewithworkspacePathset to the absolute path of the solution or project file (e.g.,d:/Devel/YourRepo/YourSolution.sln). CRITICAL: Tools likefind_symbol_definitionwill fail or hallucinate if you skip this step. In MCP config, setROSLYN_MCP_WORKSPACEto the repo root (folder withglobal.json) when possible. - Use
manage_agent_scratchpadwithaction: readto recall previous state notes (omit if you do not use the scratchpad).
1. The Terminal Ban (Strict Tool Enforcement)
Do not run searches through raw shells (PowerShell, Bash, CMD) — the workspace might be locked or too large. Never invoke grep, Select-String, find, or similar from a terminal session.
- Semantic search (after
load_workspace): You MUST callfind_symbol_definitionwithsymbolName. If you are looking for where an interface, class, or method is declared, DO NOT use text search. Do not invent generic tool names likesearch. - Text search: Use the built-in
greptool provided by your environment. Do NOT usebashorPowerShellto run grep/Select-String. - Directory layout: Use
list_directory_tree.
2. Build & Test Protocol
NEVER use raw terminal commands (PowerShell, Bash, CMD) to execute dotnet build or dotnet test. Doing so bypasses our diagnostic parsers and can crash the context window with raw MSBuild output.
- To Build: YOU MUST use
run_dotnet_build. Analyze the structured diagnostics (and any truncated console excerpt — head + tail when output is long) the tool returns. - To Test: YOU MUST use
run_dotnet_testfor full suites. For a single test class or method during TDD/bug fixes, userun_specific_test— never hand-write VSTest--filterviaexecute_dotnet_command.
3. Explore Before Build (Global Context Awareness)
Before writing new utility classes, helper methods, or standard validation logic, you MUST verify how the project already handles this. Do not reinvent the wheel.
- Use
get_code_skeleton(for files/directories) orget_class_skeleton(for loaded workspaces) to understand architecture without loading full method bodies. - Use
find_usageswithsymbolName(afterload_workspace) for usages across the solution, orfind_symbol_referenceswithfilePath+symbolNamewhen you already know the declaring file — then mirror the team’s patterns. - Use
find_implementationswithsymbolNameto list classes that implement an interface or derive from a base class — do not use text search orfind_usagesfor this.
For C# edits, ALWAYS prefer get_class_skeleton, get_code_skeleton, get_method_body, explore_assembly, decompile_type, get_decompiled_class_skeleton, get_decompiled_method_body, run_dotnet_build, and get_diagnostics_for_file instead of inventing code from memory. When fixing compiler/analyzer errors, call get_code_fixes and apply_code_fix before guessing a manual patch—Roslyn already knows the correct fix for most standard diagnostics. Persisting edits to disk follows section 6 (IDE-native tools vs this MCP server's file tools).
4. Third-Party Code / NuGet Investigation
If you encounter a bug originating from a compiled .dll or NuGet package, DO NOT guess or hallucinate its implementation.
- Before adding or upgrading packages, use
search_nuget_registryto verify the package id and latest stable version — never invent library names or versions. - Use
list_nuget_packagesto inspect installed and transitive dependencies across projects (JSON) before changing.csprojfiles. - Use
explore_assemblywithassemblyName(afterload_workspace) orassemblyPath(absolute.dll, e.g. from NuGet cache) — provide one, not neither. - Use
decompile_type/get_decompiled_class_skeleton/get_decompiled_method_bodywith the sameassemblyNameorassemblyPathrules. - Use
decompile_typeto read the exact C# source code. For large types, useget_decompiled_class_skeleton; for a specific method overload, useget_decompiled_method_body. - Propose a fix only after reading the decompiled material.
5. Execution Loop
Think step-by-step. If a tool fails or returns an error, read the error message carefully, adjust your parameters, and try the appropriate MCP tool again. Do not fallback to raw shell commands. For MCP server diagnostics use tail_tool_log (or read_log_tail without filePath); optional filterKeyword such as Failure or ERR. Only after these steps are complete, respond to the user's actual prompt.
6. Environment-Specific File Editing Protocol
Before editing any files, identify your host environment:
- If you are running in a UI-based IDE (Cursor, OpenCode, Windsurf): You MUST use the built-in native file editing tools (such as
edit,write, or equivalent operations) provided by your environment so the user can review changes in the IDE diff viewer. Do NOT use this Roslyn MCP server'sapply_patchorupdate_file_contentwhen those native tools are available—they bypass the host review workflow.
- If you are running in a headless/CLI environment (e.g., Aider) or your client does not expose first-class edit tools: You MUST persist changes using this MCP server's
apply_patchand/orupdate_file_content(or the file-write mechanism your CLI integration documents). Do not use raw shell redirection to invent files. - For C# insertions (usings, methods, properties, fields): prefer
add_using,add_method_to_class,add_property_to_class,add_field_to_class,organize_usingsoverapply_patch. - For method body edits: read with
get_method_body, write withupdate_method_body— notapply_patch. - Bug investigation: use
get_call_graphto see callers/callees before loading many method bodies. - Packages: use
search_nuget_registry+add_package_reference— not hand-edited versions in csproj. - After server rebuild: call
get_mcp_server_info; runpublish-and-verify.ps1.
Logs
- Main log:
logs/mcp-*.log(relative toAppContext.BaseDirectory). - Global incoming JSON-RPC logging is enabled by default.
- Tool output: logged as a one-line summary plus separate warning/error lines (not a duplicated full MCP response). Set
ROSLYN_MCP_LOG_TOOL_OUTPUT=fullto log entire tool responses at Information level. - Environment Variables:
ROSLYN_MCP_WORKSPACE— repo root for MSBuild/SDK discovery at startup (see MCP config above).ROSLYN_MCP_LOG_TOOL_OUTPUT=full— verbose tool response logging.MCP_LOG_INCOMING_RPC=0(disable incoming RPC logging).MCP_LOG_INCOMING_RPC_MAX_CHARS=(limit payload log length,0= unlimited).
Reference: MCP Tools
Parameter Naming Rules:
filePath— a single file (read/edit/diagnostics/logs).directoryPath— root folder (list_directory_tree, optional root forsearch_code).includeExtensions— optional extension filter forsearch_code(.csby default;*= all files).workspacePath—.sln/.csproj(and sometimes a directory):load_workspace,run_dotnet_test,run_specific_test,run_format, optional reload forlist_projects/get_project_graph.run_dotnet_buildaccepts only a.csprojor.slnfile path, not a directory.symbolName— C# identifier forfind_symbol_definition,find_symbol_references,find_usages, andfind_implementations(exact name; matching is case-insensitive for definition/usages/implementations).diagnosticId— compiler/analyzer id fromget_diagnostics_for_file(e.g.CS0246) forget_code_fixes/apply_code_fix.fixIndex— 0-based index fromget_code_fixesforapply_code_fix.path—.csfile or directory forget_code_skeleton(absolute path; disk-based, no workspace required).
When a tool accepts filePath, relative values are resolved against the loaded workspace root after load_workspace; if no workspace is loaded, fallback is Environment.CurrentDirectory.
There are 55 registered tools (see list below) and 1 MCP prompt (RefactoringAssistantPrompt).
Workspace / Roslyn
load_workspace — Loads .sln/.csproj into MSBuildWorkspace.
Parameters:
workspacePath: string
resetworkspace — Clears the in-memory MSBuildWorkspace/solution cache. Call before loadworkspace again after building the loaded solution on disk.
Parameters: (none)
getfilecontent — Reads the entire file (safe preview for large files).
Parameters:
filePath: string
getclassskeleton — Returns the C# file structure without method bodies.
Parameters:
filePath: string
getcodeskeleton — Parses .cs from disk and returns full-file syntax with bodies stripped (signatures + empty blocks); optional directory scan (max 20 files, skips bin/obj/Test/Tests path segments).
Parameters:
path: string— absolute path to one.csfi
…
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: VuDZ
- Source: VuDZ/RoslynMcpServer
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.