Content
# .NET Profiler MCP Server
An MCP (Model Context Protocol) server that wraps .NET diagnostic tools (`dotnet-trace`, `dotnet-counters`, `dotnet-dump`) to help AI assistants analyze application performance, identify hotspots, and generate optimization recommendations.
## Prerequisites
Install the .NET diagnostic tools globally:
```bash
dotnet tool install -g dotnet-trace
dotnet tool install -g dotnet-counters
dotnet tool install -g dotnet-dump
```
## Available Tools
| Tool | Description |
|------|-------------|
| `ListDotNetProcesses` | Discover running .NET processes that can be profiled |
| `CollectTrace` | Capture CPU performance trace for a specified duration |
| `AnalyzeTrace` | Extract hot methods and performance bottlenecks from trace files |
| `CollectCounters` | Monitor System.Runtime counters (CPU, GC, memory, threadpool) |
| `CollectDump` | Capture memory dump (Windows/Linux only) |
| `AnalyzeDump` | Analyze dump for heap statistics, GC roots, threadpool info |
| `GeneratePerformanceReport` | Create styled HTML report from collected data |
| `CleanupTempFiles` | Remove all temporary profiling artifacts |
## Tool Details
### ListDotNetProcesses
Lists all running .NET processes that can be profiled using dotnet-trace.
### CollectTrace
Collects a performance trace from a running .NET process.
- **processId**: Target process ID
- **durationSeconds**: Collection duration (default: 30)
- **profile**: cpu-sampling, gc-verbose, or gc-collect
### AnalyzeTrace
Analyzes a .nettrace file to identify hot methods.
- **traceFilePath**: Path to the .nettrace file
### CollectCounters
Captures System.Runtime metrics including CPU usage, GC heap size, Gen 0/1/2 counts, threadpool stats.
- **processId**: Target process ID
- **durationSeconds**: Collection duration (default: 30)
- **refreshIntervalSeconds**: Sampling interval (default: 1)
### CollectDump
Captures a memory dump (Windows and Linux only).
- **processId**: Target process ID
- **dumpType**: Full, Heap, or Mini
### AnalyzeDump
Analyzes a dump file with various commands.
- **dumpFilePath**: Path to the .dmp file
- **command**: dumpheap -stat, gcroot, threadpool, or eeheap
### GeneratePerformanceReport
Generates a styled HTML report combining trace analysis, counter data, and dump analysis.
- **applicationName**: Name for the report header
- **traceAnalysis**: Hot methods data (optional)
- **counterData**: Counter metrics (optional)
- **dumpAnalysis**: Dump analysis results (optional)
### CleanupTempFiles
Removes all temporary files created during profiling sessions.
## Developing Locally
Configure your IDE to run the project:
```json
{
"servers": {
"dotnet-profiler-mcp": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "--project", "<PATH TO PROJECT DIRECTORY>"]
}
}
}
```
## Example Usage
Ask Copilot Chat:
- "List all .NET processes I can profile"
- "Collect a 30-second CPU trace from process 1234"
- "Analyze the trace file and show me the hot methods"
- "Collect performance counters from my app for 60 seconds"
- "Generate an HTML performance report for MyApp"
## Platform Support
- **Windows**: Full support for all tools
- **Linux**: Full support for all tools
- **macOS**: Trace and counter collection supported; dump collection not supported
## Publishing to NuGet.org
```bash
dotnet pack -c Release
dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json
```
## More Information
- [Model Context Protocol](https://modelcontextprotocol.io/)
- [MCP C# SDK](https://modelcontextprotocol.github.io/csharp-sdk)
- [.NET Diagnostics](https://learn.microsoft.com/dotnet/core/diagnostics/)