MsBuildGraphMcp
MCP server for MSBuild project graph analysis β exposes dependency graphs, shared imports, TFM compatibility, configuration diffs, and build issue detection to LLM-powered coding assistants.
Ask AI about MsBuildGraphMcp
Powered by Claude Β· Grounded in docs
I know everything about MsBuildGraphMcp. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MSBuild Project Graph MCP Server
Pre-build static analysis of MSBuild solutions for LLM-powered coding assistants. Analyze project dependencies, detect build issues, inspect shared imports, and compare configurations β all through natural language, before building.
No existing MCP server provides pre-build project graph analysis. This fills that gap.
What It Does
Ask your AI assistant natural questions about your .NET/C++ solution:
- "Show me the dependency graph for this solution" β Full DAG with topological sort
- "Are there any TFM mismatches?" β Finds net6.0 projects referencing net8.0 libraries
- "What does Directory.Build.props affect?" β Shows all projects importing each shared file
- "Compare Debug vs Release" β Property and package reference differences
- "Where does LangVersion come from?" β Traces to Directory.Build.props line 3
Tools
| Tool | Description |
|---|---|
analyze_solution | Parse .sln/.slnx/.slnf β projects, TFMs, output types, configurations |
get_project_graph | Build the full dependency DAG with topological sort and graph metrics |
find_shared_imports | Discover Directory.Build.props/.targets and other shared imports |
detect_build_issues | Find circular deps, TFM mismatches, orphan projects, platform mismatches |
analyze_project_properties | Inspect evaluated properties with source tracking (which file, which line) |
compare_configurations | Diff Debug vs Release (or any two configs) β properties, packages, references |
analyze_impact | "What breaks if I remove project X?" β direct + transitive dependents |
check_package_versions | NuGet package version consistency, CPM detection, VersionOverride tracking |
get_build_order | Lightweight build order (topological sort) with critical path length |
list_projects | Fast project listing without MSBuild evaluation β instant response |
Supported Clients
β Works with
| Client | Config file | Details |
|---|---|---|
| VS Code + GitHub Copilot | .vscode/mcp.json | Copilot agent mode calls MCP tools directly |
| VS Code + Continue.dev | .vscode/mcp.json | Works with Claude, GPT, or any LLM backend |
| Cursor | .cursor/mcp.json | Built-in AI calls MCP tools natively |
| Windsurf | Settings UI | Native MCP support via stdio transport |
| Claude Desktop | claude_desktop_config.json | Full tool + prompt support |
| Claude Code (terminal) | CLI: claude mcp add | Inline with terminal workflow |
| Visual Studio 2026 + Copilot | .mcp.json in solution dir | Native MCP support in VS 2026 Preview |
β Not supported
| Client | Reason |
|---|---|
| Visual Studio 2022 | Copilot in VS 2022 does not support MCP protocol |
| ChatGPT | OpenAI uses a different protocol (function calling, not MCP) |
| Gemini | Google uses a different protocol (not MCP) |
Quick Start
Install
dotnet tool install -g MsBuildGraphMcp
Configure
Claude Desktop β add to %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"msbuild-graph": {
"command": "msbuild-graph-mcp"
}
}
}
Claude Code:
claude mcp add msbuild-graph -- msbuild-graph-mcp
VS Code β add to .vscode/mcp.json:
{
"servers": {
"msbuild-graph": {
"type": "stdio",
"command": "msbuild-graph-mcp"
}
}
}
Cursor β add to .cursor/mcp.json:
{
"mcpServers": {
"msbuild-graph": {
"command": "msbuild-graph-mcp"
}
}
}
Requirements
- .NET SDK 8.0+ (or Visual Studio 2022+)
- Windows (MSBuildLocator discovers VS/.NET SDK installations)
Example Output
get_project_graph
{
"metrics": {
"nodeCount": 4,
"edgeCount": 3,
"uniqueProjectCount": 4,
"maxDepth": 2,
"constructionTimeMs": 297
},
"projects": [
{
"name": "WebApp",
"targetFrameworks": ["net8.0"],
"outputType": "Exe",
"isRoot": true,
"references": ["DataLib\\DataLib.csproj", "CoreLib\\CoreLib.csproj"]
}
],
"topologicalOrder": [
"CoreLib\\CoreLib.csproj",
"DataLib\\DataLib.csproj",
"WebApp\\WebApp.csproj"
]
}
detect_build_issues
{
"totalIssues": 2,
"frameworkMismatches": [{
"project": "OldApp.csproj",
"projectTfm": "net6.0",
"dependency": "NewLib.csproj",
"dependencyTfm": "net8.0",
"reason": "net6.0 cannot consume net8.0"
}],
"orphanProjects": [{
"name": "UnusedLib",
"reason": "Library with no referencing projects"
}]
}
Features
- Pre-build analysis β no build required, evaluates MSBuild project files directly
- .sln / .slnx / .slnf β supports all solution formats including the new .slnx (VS 17.10+)
- Multi-targeting aware β correctly handles TargetFrameworks (plural) with outer/inner build deduplication
- TFM compatibility β NuGet.Frameworks-based checking (net8.0-windows vs net8.0, netstandard2.0 vs net48, etc.)
- Property source tracking β shows which file and line number defined each MSBuild property
- Configuration diffing β compares any two configurations (Debug/Release, custom configs)
- Circular dependency detection β catches both MSB4251 and CircularDependencyException
- Shared import discovery β identifies Directory.Build.props, Directory.Build.targets, Directory.Packages.props
- CPM detection β recognizes Central Package Management (ManagePackageVersionsCentrally)
Security
All tools are read-only β no builds are triggered, no files are modified.
| Measure | Description |
|---|---|
IsBuildEnabled = false | Prevents MSBuild target execution during evaluation |
MSBUILDENABLEALLPROPERTYFUNCTIONS guard | Server refuses to start if this dangerous env var is set |
| Path validation | UNC paths rejected, extension whitelist, existence check |
| Fresh ProjectCollection per call | No state leakage between tool invocations |
| try/finally cleanup | Projects always unloaded, even on exception |
Important: MSBuild property functions execute during evaluation (by design). Functions like
$([System.IO.File]::ReadAllText(...))run when a project is loaded. Only analyze projects you trust.
Architecture
ββββββββββββββββββββ stdio (JSON-RPC) βββββββββββββββββββββββ
β Claude / Copilot βββββββββββββββββββββββββΊβ msbuild-graph-mcp β
β VS Code / Cursor β β β
ββββββββββββββββββββ β MSBuildLocator β
β βΊ ProjectGraph β
β βΊ ProjectCollection β
β βΊ SolutionPersist β
βββββββββββββββββββββββ
Key architectural decisions:
- MSBuildLocator JIT trap pattern β RegisterInstance() in Main(), MSBuild types only in [NoInlining] method
- EvaluationContext.Shared via ProjectInstanceFactoryFunc β 2-5x speedup for large solutions
- Parallelism capped at 8 β prevents memory exhaustion on high-core machines
- Microsoft.Build 17.13.9 with ExcludeAssets="runtime" β avoids 17.14.8 dependency publishing bug
Testing
333 tests across 35 test files, sourced from 5 rounds of internet research covering 20+ sources:
dotnet test tests/MsBuildGraphMcp.Tests/
# Passed! - Failed: 0, Passed: 333, Skipped: 0, Total: 333, Duration: 12s
Test categories: validation, core tools, TFM compatibility, security (OWASP/CVE), solution formats, production resilience, concurrency, path edge cases, JSON serialization, real-world scenarios.
8 production bugs found and fixed during testing.
Complementary Tools
This server provides pre-build analysis. For post-build analysis (requires a completed build), see:
- BinlogInsights.Mcp β 26 MCP tools + 13 CLI commands for MSBuild binary log analysis (build times, errors, performance, analyzers)
- baronfel/mcp-binlog-tool β MSBuild binary log analysis (build times, errors, targets)
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT - FlorinVica
