dotnet-coverage-mcp
Provides tools for .NET test-coverage workflows, including running dotnet test with coverage, parsing Cobertura XML reports, analyzing method- and branch-level coverage, diffing coverage between runs, and appending test code to test files.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@dotnet-coverage-mcp@dotnet-coverage-mcp Run tests and show coverage summary"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
dotnet-coverage-mcp
An MCP (Model Context Protocol) server that gives AI assistants — Claude Code, Gemini CLI, and others — direct access to .NET test-coverage tooling. Run dotnet test, parse Cobertura XML, identify uncovered branches, diff coverage between runs, and append test code — all over stdio.
Purpose
This server lets an AI assistant run unit tests, collect coverage data, and analyse results — all without leaving the chat. Instead of manually running dotnet test and parsing reports, the AI can call the server's tools directly to:
Discover source files and build smart batches by line budget
Run a filtered set of tests and collect coverage
Read compact, AI-optimised coverage summaries (method-level line/branch rates)
Check per-file coverage against a configurable target rate (default 80%)
Identify uncovered branches as structured JSON
Diff coverage between runs to see only what changed
Append new test code to an existing test file with atomic writes
Related MCP server: codecov-mcp-server
How It Works
The server starts as a console process and communicates over stdio using the MCP protocol. An MCP-compatible client (Claude Code, Gemini CLI, etc.) launches the process and calls its tools as if they were functions.
AI Client <--stdio/MCP--> dotnet-coverage-mcp <--shell--> dotnet test + reportgeneratorAvailable Tools
Tool | Description |
| Discover |
| Run |
| Parse |
| Get coverage for a single source file from Cobertura XML. Returns |
| Find uncovered branch conditions for methods matching a given name. Returns all matching methods with partial name support. Supports |
| Compare current Cobertura XML against baseline. Shows method-level changes including new and removed methods. Supports |
| Insert or append C# test code into a test file. Supports anchor-based insertion with whitespace-tolerant fallback matching. Uses atomic writes to prevent file corruption. |
| Remove session state files and |
Batch Workflow
For projects with many source files, the recommended workflow is:
Discover — Call
GetSourceFileson a folder or.csprojto get all files and smart batchesRun once — Call
RunTestsWithCoveragewith a broad filter (e.g.,*) to collect coverage across all filesCheck per-file — Call
GetFileCoveragefor each file in the current batch (instant XML parsing, no test re-run)Focus — Pick the 3 lowest branch-coverage methods and call
GetUncoveredBranchesfor eachWrite tests — Use
AppendTestCodeto add test methodsRe-run and diff — Run tests once, call
GetCoverageDiffto verify improvementRepeat — Continue until batch files meet the target rate (default 80%) or 3 cycles with no improvement, then move to next batch
This minimises dotnet test invocations (the main bottleneck) while still tracking per-file progress.
Concurrency
Multiple AI agents can run in parallel by passing a sessionId to each tool call, which isolates their coverage artifacts:
Isolated output directories —
RunTestsWithCoveragecreatesTestResults-{hash}/andcoveragereport-{hash}/per session, preventing one agent from deleting another's XML mid-parseScoped state files — Coverage state is written to
.mcp-coverage/.coverage-state-{hash}, soResolveCoberturaPathresolves to the correct XML for each sessionScoped baselines —
GetCoverageDiffstores baselines as.coverage-prev-{hash}.xmlper sessionAtomic writes — All file writes (state files and test code) use write-to-temp-then-rename to prevent corruption from race conditions or process crashes
Limitation — build outputs are not session-scoped.
sessionIdisolates coverage artifacts, not the .NET build.dotnet testcompiles the target project into its sharedobj/andbin/, which are not per-session, so two agents runningRunTestsWithCoverageagainst the same test project at the same time collide on those outputs and fail withbuildError(e.g.CS2012: the file is being used by another process). Run parallel agents against different test projects, or on separate working copies of the repo. Multiple agents on one project are fine as long as theirdotnet testbuilds don't overlap.
Without sessionId, tools use shared defaults — safe for single-agent use.
Requirements
.NET 9.0 SDK (or later) — https://dotnet.microsoft.com/download
reportgenerator global tool — the server shells out to it to render coverage reports (installed in the Install step below)
An MCP-compatible client (Claude Code, Gemini CLI, etc.)
COVERAGE_MCP_ALLOWED_ROOT— recommended. Set to your repository root to restrict every tool's filesystem access to that subtree. Any path passed by the client outside this root is rejected withpathNotAllowed. When unset, the server logs a warning once and accepts any path (backward-compatible, but not recommended for shared environments).export COVERAGE_MCP_ALLOWED_ROOT=/path/to/your/repo
Install
Install the server as a global .NET tool from NuGet:
dotnet tool install --global dotnet-coverage-mcpThe server depends on the reportgenerator global tool to render coverage reports — install it too:
dotnet tool install --global dotnet-reportgenerator-globaltoolAfter install, the dotnet-coverage-mcp command is on your PATH.
Build & Run (from source)
cd <path-to-dotnet-coverage-mcp>
# Restore dependencies
dotnet restore
# Build
dotnet build
# Run
dotnet runThe server will start and wait for MCP messages over stdin/stdout.
MCP Client Configuration
After installing the global tool (dotnet tool install --global dotnet-coverage-mcp),
register the server with your MCP client. Set COVERAGE_MCP_ALLOWED_ROOT to the
repository you want the server to operate on.
Claude Code
claude mcp add coverage --env COVERAGE_MCP_ALLOWED_ROOT=/path/to/your/repo -- dotnet-coverage-mcpClaude Desktop
Add to claude_desktop_config.json (Settings → Developer → Edit Config):
{
"mcpServers": {
"coverage": {
"command": "dotnet-coverage-mcp",
"env": {
"COVERAGE_MCP_ALLOWED_ROOT": "/path/to/your/repo"
}
}
}
}Cursor
Add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (per-project):
{
"mcpServers": {
"coverage": {
"command": "dotnet-coverage-mcp",
"env": {
"COVERAGE_MCP_ALLOWED_ROOT": "/path/to/your/repo"
}
}
}
}VS Code (GitHub Copilot)
Add to .vscode/mcp.json:
{
"servers": {
"coverage": {
"type": "stdio",
"command": "dotnet-coverage-mcp",
"env": {
"COVERAGE_MCP_ALLOWED_ROOT": "/path/to/your/repo"
}
}
}
}Run from source
To run from source instead of the global tool, use dotnet run:
{
"mcpServers": {
"coverage": {
"command": "dotnet",
"args": ["run", "--project", "<path-to-dotnet-coverage-mcp>"],
"transport": "stdio"
}
}
}Or point directly at the compiled executable:
{
"mcpServers": {
"coverage": {
"command": "<path-to-dotnet-coverage-mcp>\\bin\\Debug\\net9.0\\DotNetCoverageMcp.exe",
"transport": "stdio"
}
}
}Tool Parameters
GetSourceFiles
Parameter | Type | Required | Description |
| string | Yes | Path to a |
| int | No | Max total lines per batch (default: 300). Small files are grouped together; large files get their own batch. |
RunTestsWithCoverage
Parameter | Type | Required | Description |
| string | Yes | Full path to the |
| string | Yes | Test filter string (matched against |
| string | No | Working directory; defaults to the project directory |
| bool | No | When |
| string | No | Isolates output directories ( |
| string | No | Restrict coverage collection to types matching this name (coverlet |
| bool | No | When |
GetCoverageSummary
Parameter | Type | Required | Description |
| string | Yes | Full path to the generated |
| double | No | When set (a fraction in |
| int | No | Return only the N lowest-branch-coverage classes (results are sorted worst-first). Omit for all classes. |
| int | No | Keep at most this many lowest-branch-coverage methods per class, trimming the rest. Omit to keep all methods. |
GetFileCoverage
Parameter | Type | Required | Description |
| string | Yes | Path to |
| string | Yes | Source file name to look up (e.g., |
| string | No | Resolves session-scoped state file for concurrent isolation. |
| double | No | Coverage threshold (0.0–1.0) used to compute |
GetUncoveredBranches
Parameter | Type | Required | Description |
| string | Yes | Path to |
| string | Yes | Method name to inspect (partial match supported; returns all matching methods) |
| string | No | Resolves session-scoped state file for concurrent isolation. |
GetCoverageDiff
Parameter | Type | Required | Description |
| string | Yes | Path to the current |
| string | No | Directory for storing baseline; defaults to the XML's parent directory |
| string | No | Isolates baseline as |
AppendTestCode
Parameter | Type | Required | Description |
| string | Yes | Full path to the target |
| string | Yes | C# code to insert |
| string | No | If provided, inserts code after the last occurrence of this string (with whitespace-tolerant fallback). If omitted, appends before the last |
CleanupSession
Parameter | Type | Required | Description |
| string | Yes | Project working directory containing |
| string | No | When set, removes only state files and directories scoped to this session. |
| int | No | When |
State Files
All state files are written to a .mcp-coverage/ subdirectory inside the working directory, keeping the project root clean. Add .mcp-coverage/ to the target repository's .gitignore.
File | Purpose |
| Default Cobertura XML path for single-agent use |
| Session-scoped Cobertura XML path |
| Default coverage baseline for diff |
| Session-scoped coverage baseline |
Plugin (Skills & Agent)
This repo includes a plugin/ directory with Claude Code skills and an agent definition for guided test coverage workflows:
plugin/
├── plugin.json
├── agents/
│ └── test-coverage.agent.md
└── skills/
├── scaffold-test-files/ — Create test directories and files mirroring source structure
├── run-coverage/ — Run tests and view coverage reports
├── analyze-coverage-gaps/ — Find uncovered branches and compare diffs
└── improve-test-coverage/ — Iterative loop to reach 80% coverageThe skills support NUnit, xUnit, and MSTest with framework-agnostic reference docs in references/unit.md and references/integration.md.
Dependencies
Package | Version | Purpose |
| 10.0.7 | DI and hosting |
| 1.2.0 | MCP server framework |
| 5.3.0 | Roslyn AST for safe code insertion and accurate method counting (~15MB) |
Security
dotnet-coverage-mcp runs as a local stdio process and validates every tool argument against COVERAGE_MCP_ALLOWED_ROOT to confine filesystem access. See SECURITY.md for the threat model, hardening recommendations, and how to report a vulnerability.
Contributing
Contributions are welcome. See CONTRIBUTING.md for development setup, pull request guidelines, and code conventions. Notable changes are tracked in CHANGELOG.md.
Releasing
Maintainer-only — release process, NuGet publishing, and MCP registry submission are documented in RELEASING.md.
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for building and testing AI agents with multi-model experimentation and insights.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
- ZapierOAuthcom.zapier
Hosted MCP server connecting AI assistants to 9,000+ apps and 40,000+ actions via Zapier.
Related MCP Servers
- AlicenseBqualityDmaintenanceAn MCP server that enables AI agents to debug .NET applications using netcoredbg. It supports core debugging tasks like setting breakpoints, stepping through code, and inspecting variables or stack traces.1MIT
- AlicenseAqualityFmaintenanceMCP server for Codecov that provides tools to get commit coverage totals and prompts to suggest tests to write.138 npm6ISC
- AlicenseAqualityCmaintenanceAn MCP server that exposes 41 Azure DevOps tools to AI assistants, enabling management of pipelines, repositories, pull requests, releases, work items, test management, and wikis through natural language.4146 PyPIMIT
- AlicenseAqualityAmaintenanceAn MCP server that brings senior-QA discipline to AI coding assistants, enabling test planning, TDD, mutation testing, and code review.486Apache 2.0