This document describes how the .NET MCP Server integrates directly with the .NET SDK through official NuGet packages.
The .NET MCP Server uses a hybrid architecture that combines:
- SDK Integration - Direct access to .NET SDK internals via NuGet packages
- CLI Execution - Proven, reliable command execution
This approach provides rich metadata access, type-safe operations, and validation capabilities while maintaining the reliability of the official CLI.
- Microsoft.TemplateEngine.Abstractions (v10.0.101)
- Microsoft.TemplateEngine.Edge (v10.0.101)
Provides programmatic access to the .NET template system:
- List all installed templates with metadata
- Access template parameters and options
- Search and filter templates
- Validate template existence
- Microsoft.Build.Utilities.Core (v18.0.2)
- Microsoft.Build (v18.0.2)
Provides framework validation, metadata, and project analysis:
- Parse and validate Target Framework Monikers (TFMs)
- Access framework version information
- Framework classification (modern .NET, .NET Core, .NET Framework, .NET Standard)
- Parse and analyze .csproj files without building
- Extract package references, project references, and build properties
- Validate project configuration and detect common issues
Located in DotNetMcp/CachedResourceManager.cs
Generic cache manager for readonly resources with configurable TTL and metrics tracking:
Features:
- Configurable TTL (default: 300 seconds)
- Thread-safe async operations using
SemaphoreSlim - Cache hit/miss metrics tracking
- Force reload capability
- Automatic cache expiration
- JSON response generation with cache metadata
Usage Example:
var cache = new CachedResourceManager<string>("MyResource", defaultTtlSeconds: 300);
// Load or get from cache
var entry = await cache.GetOrLoadAsync(async () => {
return await LoadDataFromSource();
});
// Force reload
var freshEntry = await cache.GetOrLoadAsync(LoadDataFromSource, forceReload: true);
// Check metrics
Console.WriteLine($"Cache metrics: {cache.Metrics}");
// Clear cache
await cache.ClearAsync();Located in DotNetMcp/CacheMetrics.cs
Thread-safe metrics tracker for monitoring cache performance:
Properties:
Hits- Number of cache hitsMisses- Number of cache missesHitRatio- Cache hit ratio (0.0 to 1.0)
Methods:
RecordHit()- Increment hit counterRecordMiss()- Increment miss counterReset()- Reset all metrics to zero
Located in DotNetMcp/DotNetSdkConstants.cs
Provides strongly-typed constants for common SDK values:
Target Frameworks
DotNetSdkConstants.TargetFrameworks.Net110 // "net11.0"
DotNetSdkConstants.TargetFrameworks.Net100 // "net10.0"
DotNetSdkConstants.TargetFrameworks.Net90 // "net9.0"
DotNetSdkConstants.TargetFrameworks.Net80 // "net8.0"
DotNetSdkConstants.TargetFrameworks.Net60 // "net6.0"Build Configurations
DotNetSdkConstants.Configurations.Debug
DotNetSdkConstants.Configurations.ReleaseRuntime Identifiers
DotNetSdkConstants.RuntimeIdentifiers.WinX64
DotNetSdkConstants.RuntimeIdentifiers.LinuxX64
DotNetSdkConstants.RuntimeIdentifiers.OsxArm64Common Templates
DotNetSdkConstants.Templates.Console
DotNetSdkConstants.Templates.WebApi
DotNetSdkConstants.Templates.BlazorCommon NuGet Packages
DotNetSdkConstants.CommonPackages.NewtonsoftJson
DotNetSdkConstants.CommonPackages.EFCore
DotNetSdkConstants.CommonPackages.XUnitLocated in DotNetMcp/TemplateEngineHelper.cs
Integrates with the .NET Template Engine for template operations with built-in caching:
Methods:
GetInstalledTemplatesAsync(forceReload)- Get all installed templates with metadataGetTemplateDetailsAsync(shortName, forceReload)- Get detailed template informationSearchTemplatesAsync(searchTerm, forceReload)- Search templates by name/descriptionValidateTemplateExistsAsync(shortName, forceReload)- Check if a template existsClearCacheAsync()- Clear template cache and reset metricsMetrics- Property to access cache hit/miss statistics
Caching:
- Templates are cached for 5 minutes (300 seconds) by default
- Cache can be bypassed with
forceReload: trueparameter - Cache is automatically invalidated after expiry or when cleared
- Thread-safe implementation using
CachedResourceManager<T>
Usage Example:
// Normal usage (uses cache)
var templates = await TemplateEngineHelper.GetInstalledTemplatesAsync();
// Force reload from disk
var freshTemplates = await TemplateEngineHelper.GetInstalledTemplatesAsync(forceReload: true);
// Check cache metrics
var metrics = TemplateEngineHelper.Metrics;
Console.WriteLine($"Cache hits: {metrics.Hits}, Misses: {metrics.Misses}");
// Clear cache after installing new templates
await TemplateEngineHelper.ClearCacheAsync();Located in DotNetMcp/FrameworkHelper.cs
Provides framework validation and information:
Methods:
IsValidFramework(framework)- Validate a TFMGetFrameworkDescription(framework)- Get friendly name (e.g., ".NET 8.0 (LTS)")IsLtsFramework(framework)- Check if framework is Long-Term SupportIsModernNet(framework)- Check if .NET 5.0+IsNetCore(framework)- Check if .NET CoreIsNetFramework(framework)- Check if .NET FrameworkIsNetStandard(framework)- Check if .NET StandardGetLatestRecommendedFramework()- Get latest recommended versionGetLatestLtsFramework()- Get latest LTS versionGetSupportedModernFrameworks()- List modern .NET versionsGetSupportedNetCoreFrameworks()- List .NET Core versionsGetSupportedNetStandardFrameworks()- List .NET Standard versions
Usage Example:
if (FrameworkHelper.IsValidFramework("net8.0"))
{
var description = FrameworkHelper.GetFrameworkDescription("net8.0");
var isLts = FrameworkHelper.IsLtsFramework("net8.0");
}Located in DotNetMcp/ProjectAnalysisHelper.cs
Provides comprehensive .csproj file analysis using MSBuild APIs without requiring a build:
Methods:
AnalyzeProjectAsync(projectPath, logger)- Comprehensive project analysis- Returns JSON with target frameworks, package references, project references, build properties
AnalyzeDependenciesAsync(projectPath, logger)- Dependency graph analysis- Returns JSON with direct package and project dependencies
ValidateProjectAsync(projectPath, logger)- Project health check- Returns JSON with errors, warnings, and recommendations
Usage Example:
// Analyze a project file
var analysisJson = await ProjectAnalysisHelper.AnalyzeProjectAsync("MyApp.csproj", logger);
// Returns: target frameworks, packages, project refs, build properties, analyzers, etc.
// Analyze dependencies
var depsJson = await ProjectAnalysisHelper.AnalyzeDependenciesAsync("MyApp.csproj", logger);
// Returns: direct package dependencies, project dependencies, framework info
// Validate project health
var validationJson = await ProjectAnalysisHelper.ValidateProjectAsync("MyApp.csproj", logger);
// Returns: errors, warnings, recommendations (e.g., use LTS framework, enable nullable)Features:
- Parses .csproj files using MSBuild's Project class
- No build required - reads project structure directly
- Extracts package references with versions and metadata
- Extracts project references with paths
- Reads build properties (PublishAot, InvariantGlobalization, etc.)
- Validates framework versions and suggests LTS alternatives
- Detects missing configuration (OutputType, Nullable, etc.)
- Thread-safe and async-first design
Template, SDK, runtime, and framework metadata is surfaced via the consolidated dotnet_sdk tool:
dotnet_sdk(action:ListTemplates) - Lists installed templates (Template Engine API; CLI fallback when needed)dotnet_sdk(action:SearchTemplates) - Searches templates by name/descriptiondotnet_sdk(action:TemplateInfo) - Detailed template info, including parameters/optionsdotnet_sdk(action:ListTemplatePacks) - Lists installed template packs (viadotnet new uninstalllisting behavior)dotnet_sdk(action:InstallTemplatePack) - Installs a template pack (wrapsdotnet new install)dotnet_sdk(action:UninstallTemplatePack) - Uninstalls a template pack (wrapsdotnet new uninstall)dotnet_sdk(action:ClearTemplateCache) - Clears template cache (use after installing/uninstalling templates)dotnet_sdk(action:CacheMetrics) - Cache hit/miss stats for SDK/runtime/templates caching
Framework metadata is also provided via dotnet_sdk:
dotnet_sdk(action:FrameworkInfo) - Framework validation and LTS classification (modern .NET / .NET Core / .NET Framework / .NET Standard)
dotnet://sdk-info
- Returns JSON with installed .NET SDK versions and paths
- Cached for 5 minutes (300 seconds)
- Includes cache metadata: timestamp, age, duration, metrics
dotnet://runtime-info
- Returns JSON with installed .NET runtime information
- Cached for 5 minutes (300 seconds)
- Includes cache metadata: timestamp, age, duration, metrics
dotnet://templates
- Returns JSON catalog of installed templates with full metadata
- Cached for 5 minutes (300 seconds)
- Uses TemplateEngineHelper cache
dotnet://frameworks
- Returns JSON with framework information (not cached)
- Provides static metadata about .NET TFMs
All cached resources include metadata:
{
"data": {
// Actual resource data
},
"cache": {
"timestamp": "2025-10-31T05:50:00.000Z",
"cacheAgeSeconds": 15,
"cacheDurationSeconds": 300,
"metrics": {
"hits": 5,
"misses": 1,
"hitRatio": 0.8333
}
}
}???????????????????????????????????????
? AI Assistant / User ?
???????????????????????????????????????
? MCP Protocol
?
???????????????????????????????????????
? .NET MCP Server ?
? ???????????????????????????????? ?
? ? DotNetCliTools ? ?
? ? (MCP Tool Methods) ? ?
? ???????????????????????????????? ?
? ? ?
? ???????????????????????????????? ?
? ? TemplateEngineHelper ? ?
? ? FrameworkHelper ? ?
? ? DotNetSdkConstants ? ?
? ???????????????????????????????? ?
? ? ?
? ???????????????????????????????? ?
? ? ExecuteDotNetCommand ? ?
? ? (CLI Execution) ? ?
? ???????????????????????????????? ?
???????????????????????????????????????
?
???????????????????????????????????????
? .NET SDK ?
? - Template Engine (NuGet) ?
? - MSBuild (NuGet) ?
? - dotnet CLI ?
???????????????????????????????????????
- Metadata and discovery (templates, frameworks)
- Input validation before execution
- Structured data access
- Type-safe operations
- Actual command operations (build, run, test)
- Features not exposed by SDK packages
- Proven, tested functionality
[McpServerTool, Description("Create project with validation")]
public async Task<string> DotnetProjectNew(string template)
{
// 1. SDK: Validate template exists
if (!await TemplateEngineHelper.ValidateTemplateExistsAsync(template))
{
return $"Template '{template}' not found.";
}
// 2. CLI: Execute the command
return await ExecuteDotNetCommand($"new {template}");
}Type Safety
- Strongly-typed constants prevent typos
- IntelliSense support for SDK values
- Compile-time validation
Rich Metadata
- Direct access to template information
- Framework classification and LTS status
- Template parameter discovery
Better Validation
- Validate inputs before execution
- Provide helpful error messages
- Guide users to correct values
Future Extensibility
- Foundation for MSBuild project analysis ✅ (Implemented)
- Ready for NuGet API integration
- Prepared for Roslyn integration
MSBuild-based analysis is surfaced via the consolidated dotnet_project tool:
dotnet_project(action:Analyze) - Extract target frameworks, package refs, project refs, and key properties from a project filedotnet_project(action:Dependencies) - Direct package + project dependency graphdotnet_project(action:Validate) - Health checks (framework support, common project config issues)
Test template, framework, and project analysis tools:
# Template discovery
"What .NET templates are available?"
→ Uses dotnet_sdk (action: "ListTemplates")
# Template search
"Show me web-related templates"
→ Uses dotnet_sdk (action: "SearchTemplates")
# Template details
"What options does the console template have?"
→ Uses dotnet_sdk (action: "TemplateInfo")
# Framework information
"Which .NET versions are LTS?"
→ Uses dotnet_sdk (action: "FrameworkInfo")
# Project analysis
"Analyze the MyApp.csproj file and show me what packages it uses"
→ Uses dotnet_project (action: "Analyze")
# Dependency analysis
"What dependencies does this project have?"
→ Uses dotnet_project (action: "Dependencies")
# Project validation
"Check if MyApp.csproj has any configuration issues"
→ Uses dotnet_project (action: "Validate")
The SDK integration foundation enables:
- NuGet API Integration - Package querying and dependency analysis
- MSBuild Project Analysis ✅ (Implemented) - Parse and analyze project files
- Roslyn Integration - Code analysis and generation
- Workload Management - .NET workload installation and management
- Template Creation - Assist in creating custom templates