一款模型上下文协议(MCP)服务器,提供使用 Microsoft Roslyn 的 C# 代码分析能力
概览
一台 C# MCP(模型上下文协议)服务器,集成于 Microsoft 的 Roslyn 编译器平台,为 Claude Desktop 提供 C# 代码库的代码分析和导航功能。 - - 通过模式匹配(*Service、Get*User 等)查找类、方法和属性 - - 定位整个解决方案中符号的所有使用情况 - 获取关于类型、方法、属性等的详细信息 - 分析项目依赖关系和命名空间使用模式 - 使用 cyclomatic 复杂度指标识别高复杂度方法 - 为大型代码库进行多级缓存和增量分析 - 输入验证与路径净化 - .NET 8.0 SDK 或更高版本 - Visual Studio 2022 或 VS Code(推荐开发)- Claude 桌面应用程序 要将此 MCP 服务器连接到 Claude Desktop,您需要修改 Claude Desktop 配置文件: - : %APPDATA%\Claude\claude_desktop_config.json - : ~/Library/Application Support/Claude/claude_desktop_config。
概述(AI 翻译)
一台 C# MCP(模型上下文协议)服务器,集成于 Microsoft 的 Roslyn 编译器平台,为 Claude Desktop 提供 C# 代码库的代码分析和导航功能。
特色
- 万用符号搜索 - 通过模式匹配(
*Service、Get*User等)查找类、方法和属性。 - 引用追踪 - 定位整个解决方案中所有符号的使用情况
- 符号信息 - 获取关于类型、方法、属性等的详细信息
- 依赖分析 - 分析项目依赖关系和命名空间使用模式
- 代码复杂度分析 - 利用循环复杂度指标识别高复杂度方法
- 性能优化 - 针对大型代码库的多级缓存和增量分析
- 安全性 - 输入验证和路径净化
先修条件
- .NET 8.0 SDK 或更高版本
- Visual Studio 2022 或 VS Code(推荐开发)
- Claude桌面应用程序
安装
-
克隆或下载该项目
-
恢复NuGet包
-
构建项目
-
测试服务器(可选)
快速布置
Windows
运行PowerShell设置脚本:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Roslyn MCP Server
A C# MCP (Model Context Protocol) server that integrates with Microsoft’s Roslyn compiler platform to provide Claude Desktop with code analysis and navigation capabilities for C# codebases.
Features
- Wildcard Symbol Search - Find classes, methods, and properties using pattern matching (
*Service,Get*User, etc.) - Reference Tracking - Locate all usages of symbols across entire solutions
- Symbol Information - Get detailed information about types, methods, properties, and more
- Dependency Analysis - Analyze project dependencies and namespace usage patterns
- Code Complexity Analysis - Identify high-complexity methods using cyclomatic complexity metrics
- Performance Optimized - Multi-level caching and incremental analysis for large codebases
- Security - Input validation and path sanitization
Prerequisites
- .NET 8.0 SDK or later
- Visual Studio 2022 or VS Code (recommended for development)
- Claude Desktop application
Installation
-
Clone or download the project
git clone https://github.com/carquiza/RoslynMCP.git cd RoslynMCP/RoslynMcpServer -
Restore NuGet packages
dotnet restore -
Build the project
dotnet build -
Test the server (optional)
dotnet run
Quick Setup
Windows
Run the PowerShell setup script:
.\setup.ps1
Linux/macOS
Run the installation test:
./test-installation.sh
Claude Desktop Configuration
To connect this MCP server to Claude Desktop, you need to modify the Claude Desktop configuration file:
Configuration File Location
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Configuration Content
Add the following to your claude_desktop_config.json file:
{
"mcpServers": {
"roslyn-code-navigator": {
"command": "dotnet",
"args": [
"run",
"--project",
"/path/to/RoslynMCP/RoslynMcpServer"
],
"env": {
"DOTNET_ENVIRONMENT": "Production",
"LOG_LEVEL": "Information"
}
}
}
}
Important: Replace /path/to/RoslynMCP/RoslynMcpServer with the actual absolute path to your project directory.
Usage
Once configured, restart Claude Desktop. You should see the Roslyn MCP Server appear in the available tools. Here are some example queries:
Search for Symbols
Search for all classes ending with 'Service' in my solution at C:\MyProject\MyProject.sln
Find References
Find all references to the UserRepository class in C:\MyProject\MyProject.sln
Get Symbol Information
Get information about the CalculateTotal method in C:\MyProject\MyProject.sln
Analyze Dependencies
Analyze dependencies for the solution at C:\MyProject\MyProject.sln
Code Complexity Analysis
安装
npx @modelcontextprotocol/inspector dotnet run --project ./RoslynMcpServer配置
{
"mcpServers": {
"roslyn-code-navigator": {
"command": "dotnet",
"args": [
"run",
"--project",
"/path/to/RoslynMCP/RoslynMcpServer"
],
"env": {
"DOTNET_ENVIRONMENT": "Production",
"LOG_LEVEL": "Information"
}
}
}
}