A Model Context Protocol (MCP) server that provides code analysis capabilities for .NET C# projects and monorepos using Roslyn. This service enables AI agents to detect unreferenced code, analyze solution structures, and perform other code quality checks.
- Unreferenced Code Detection: Find classes, methods, properties, and fields that are never referenced in your codebase
- Configurable Scope: Analyze entire solutions, specific projects, or filter by file paths
- Entry Point Awareness: Optionally exclude entry points (Main methods, test methods, controllers) from analysis
- Public Member Filtering: Choose whether to include or exclude public members from analysis
- Detailed Results: Get comprehensive reports with file paths, line numbers, member types, and accessibility levels
Analyzes a .NET solution file (.sln) for unreferenced code members.
Parameters:
solutionPath(string, required): Full path to the .sln fileincludePublicMembers(bool, optional, default: true): Include public members in resultsincludeEntryPoints(bool, optional, default: false): Include entry points in resultsprojectFilter(string, optional): Comma-separated list of project name filtersfileFilter(string, optional): Comma-separated list of file path filters
Analyzes a single .NET project file (.csproj) for unreferenced code members.
Parameters:
projectPath(string, required): Full path to the .csproj fileincludePublicMembers(bool, optional, default: true): Include public members in resultsincludeEntryPoints(bool, optional, default: false): Include entry points in resultsfileFilter(string, optional): Comma-separated list of file path filters
Gets summary information about projects in a .NET solution.
Parameters:
solutionPath(string, required): Full path to the .sln file
- .NET 9.0 or later
- MSBuild (included with Visual Studio or .NET SDK)
dotnet buildThe server communicates via stdio and is designed to be used with MCP-compatible AI clients.
dotnet runAdd to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"code-analysis": {
"command": "dotnet",
"args": [
"run",
"--project",
"C:\\path\\to\\CodeAnalysisMCP\\CodeAnalysisMCP.csproj"
]
}
}
}Once configured, you can ask Claude to analyze your code:
- "Analyze the solution at C:\MyProject\MyProject.sln and find all unreferenced code"
- "Check the project C:\MyProject\MyLib\MyLib.csproj for unused private methods"
- "Find unreferenced code in MyProject.sln but exclude test projects"
- "What projects are in the solution at C:\MyProject\MyProject.sln?"
- Workspace Loading: Uses Roslyn's
MSBuildWorkspaceto load solutions and projects - Symbol Analysis: Traverses the syntax tree to find all declared symbols
- Reference Finding: Uses
SymbolFinder.FindReferencesAsyncto find all references to each symbol - Filtering: Applies configurable filters for public members, entry points, projects, and files
- Results: Returns detailed JSON with member information and statistics
- Models: Data transfer objects for analysis options and results
- Services:
WorkspaceLoader: Handles loading of solutions and projects via RoslynUnreferencedCodeAnalyzer: Performs the actual code analysis
- Tools: MCP tool definitions that expose analysis capabilities to AI agents
- Only analyzes C# code (via Roslyn)
- Requires projects to be buildable (MSBuild must be able to restore and process them)
- Analysis can be slow for very large solutions (consider using project or file filters)
- Does not detect unreachable code (code after return statements, etc.) - only unreferenced symbols
Potential features for future releases:
- Dead code detection (unreachable code)
- Cyclomatic complexity analysis
- Code duplication detection
- Dependency graph analysis
- Cross-reference reports
See LICENSE.md for details.