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.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
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 testAvailable Tools
Tools are named here as MCP clients list and call them.
Tool | Description |
| Discover |
| Run |
| Summarise class/method coverage from the Cobertura XML, sorted worst-first by branch coverage: |
| Get coverage for a single source file from Cobertura XML. Returns |
| For a source file, per class: constructor dependencies with how to provide each in a test (mock, |
| Detect a test project's stack: framework (xUnit v2/v3, NUnit, MSTest) with the attributes to use, runner (VSTest or Microsoft.Testing.Platform), coverage collector, mocking and assertion libraries, integration-test packages, plus warnings such as a missing coverage collector. Reads |
| For a scope (file, folder, |
| 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. Rejects code that is not valid C# member syntax with |
| Remove session state files and the |
Protocol details
Tool annotations. The six query tools are marked
readOnlyHint+idempotentHint, so clients that auto-approve read-only tools won't prompt for them.run_tests_with_coverage,append_test_codeandget_coverage_diffwrite files but are not destructive. Onlycleanup_sessionisdestructiveHint: true. Onlyrun_tests_with_coverageisopenWorldHint: true, since a restore can reach NuGet.Errors. A tool error comes back as
{"error": "...", "errorType": "..."}text in a result flaggedisError: true, so clients show it as a failed call.errorTypeis a stable name to branch on (fileNotFound,pathNotAllowed,testsFailed,buildError,duplicateMember, ...).Server instructions. The
initializeresult carries a short workflow (environment → run → gaps → append → repeat) that clients put in the model's context.Progress. When the client sends a progress token,
run_tests_with_coveragereports milestones whiledotnet testruns: restore, each project built, tests started, the result line.
Batch Workflow
For projects with many source files, the recommended workflow is:
Discover — Call
get_source_fileson a folder or.csprojto get all files and smart batchesRun once — Call
run_tests_with_coveragewithout a filter (runs every test) to collect coverage across all filesFind the gaps — Call
get_coverage_gapsfor the batch: per file below target, the methods to test, with the uncovered branches and source around them (no test re-run)Write tests — Use
append_test_codeto add test methodsRe-run and diff — Run tests once, call
get_coverage_diffto verify improvementRepeat — Continue until batch files meet the target rate (default 80%) or 3 cycles with no improvement, then move to next batch
Clean up — Once the goal is reached, call
cleanup_session(with the samesessionId, if you used one) to removeTestResults-mcp/orTestResults-{hash}/and the session state files. These are not deleted automatically — they persist untilcleanup_sessionis called.
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 —
run_tests_with_coveragecreatesTestResults-{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 —
get_coverage_diffstores 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 runningrun_tests_with_coverageagainst the same test project at the same time collide on those outputs. The run that loses returnsprojectBusy(its build hitCS2012/MSB3027, "being used by another process"), notbuildError, and succeeds when run again after the other build finishes. 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 10 (or later) to run the tool — https://dotnet.microsoft.com/download. The projects it tests do not have to be .NET 10:
net8.0andnet9.0test projects work, including in a repository whoseglobal.jsonpins an older SDK, and so do test projects with several target frameworks (the end-to-end tests run one targetingnet8.0;net10.0). As with anydotnet test, the runtime the tests target must be installed.A coverage collector in the test project. On VSTest (the default),
coverlet.collector. On Microsoft.Testing.Platform,Microsoft.Testing.Extensions.CodeCoverage, plusMicrosoft.Testing.Extensions.TrxReportfor per-failure details. MTP is used when the repository'sglobal.jsonsets"test": { "runner": "Microsoft.Testing.Platform" }, which the .NET 10 SDK requires for MTP projects anyway.get_test_environmentreports what a project has and what is missing.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
Optional settings, also environment variables:
Variable | Default | Effect |
|
| Longest a whole |
|
| Longest a single test may run before it counts as hung and the run is stopped (VSTest; reported as |
Install
Install the server as a global .NET tool from NuGet:
dotnet tool install --global dotnet-coverage-mcpAfter 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\\net10.0\\DotNetCoverageMcp.exe",
"transport": "stdio"
}
}
}Tool Parameters
get_source_files
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. |
| int | No | Batches to skip (default 0). At most 10 batches come back per call; when |
run_tests_with_coverage
Parameter | Type | Required | Description |
| string | Yes | Path to the |
| string | No | Passed to |
| string | No | Working directory; defaults to the project directory |
| bool | No | When |
| string | No | Isolates the output directory ( |
| string | No | Restrict coverage collection to types matching this name (coverlet |
get_coverage_summary
Parameter | Type | Required | Description |
| string | Yes | Path to |
| double | No | When set (a fraction in |
| int | No | Return only the N lowest-branch-coverage classes (results are sorted worst-first). Default |
| int | No | Keep at most this many lowest-branch-coverage methods per class, trimming the rest. Omit to keep all methods. |
| string | No | Resolves the session-scoped state file for concurrent isolation. |
get_file_coverage
Parameter | Type | Required | Description |
| string | Yes | Path to |
| string | Yes | File to look up: an absolute path (as |
| string | No | Resolves session-scoped state file for concurrent isolation. |
| double | No | Coverage threshold (0.0–1.0) used to compute |
describe_test_target
Parameter | Type | Required | Description |
| string | Yes | Full path to the |
Dependencies are classified from where their types are declared in the file's project (interface, abstract, sealed, DbContext subclass...), falling back to well-known framework types and the I-prefix convention for external types. Classes without public/internal methods (records, DTOs, exceptions) are not listed.
get_test_environment
Parameter | Type | Required | Description |
| string | Yes | Full path to the test project's |
Returns a one-line summary (e.g. xunit 2.9.3 on VSTest, coverlet.collector, Moq + FluentAssertions), the detected packages, conventions (test, data-driven, setup and teardown attributes for the framework) and warnings.
get_coverage_gaps
Parameter | Type | Required | Description |
| string | Yes | Path to |
| string | Yes | Scope: a |
| double | No | Per-file target (0.0–1.0) for both line and branch coverage. Default |
| int | No | Below-target files returned in detail, smallest gap first; the rest are listed with rates only. Default |
| int | No | Maximum methods returned per file. Default |
| bool | No | Include the source lines around each gap (2 lines of context, at most 30 per method). Default |
| string | No | Resolves the session-scoped state file for concurrent isolation. |
Methods are ranked by how many uncovered lines and branch outcomes they hold, counting only the metric that is still below target, and picked until the file's gap is closed (closesGap). Files are named by their full paths, as the scope gives them. Files in the scope with no coverage data are listed under notInReport. A file edited after the coverage run is marked sourceChangedSinceRun: true and its source left out, since the report's line numbers may no longer match it; run the tests again first.
get_uncovered_branches
Parameter | Type | Required | Description |
| string | Yes | Path to |
| string | Yes | Method name as written in source (partial match supported; returns all matching methods). Async methods, lambdas and local functions are reported under the method they belong to; overloads are labelled |
| string | No | Resolves session-scoped state file for concurrent isolation. |
get_coverage_diff
Parameter | Type | Required | Description |
| string | Yes | Path to the current |
| string | No | Directory for storing the baseline; defaults to the project folder the report belongs to (it walks up past |
| string | No | Isolates baseline as |
append_test_code
Parameter | Type | Required | Description |
| string | Yes | Full path to the target |
| string | Yes | C# code to insert. A member the target class already declares with the same name and parameter types is refused with |
| string | No | If provided, inserts code after the last member containing this string (whitespace-tolerant), in whichever class holds it. If omitted, appends at the end of the target class. |
| string | No | Simple name of the class to insert into, nested classes included. If omitted, the file's test class is used: the last top-level class with test attributes ( |
cleanup_session
Parameter | Type | Required | Description |
| string | Yes | Project working directory containing |
| string | No | When set, removes only state files and directories scoped to this session. When omitted, removes the single-agent artifacts whatever their age. |
| 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.15 | DI and hosting |
| 2.4.0 | MCP server framework |
| 5.12.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.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server that lets your AI assistant build and deploy apps, hosting each one at a live URL.
MCP server for building and testing AI agents with multi-model experimentation and insights.
One MCP server for the services your AI needs: memory, files, Microsoft 365, kanban and more.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
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.16ISC
- AlicenseAqualityDmaintenanceAn 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.4139 PyPIMIT
- AlicenseAqualityBmaintenanceAn MCP server that brings senior-QA discipline to AI coding assistants, enabling test planning, TDD, mutation testing, and code review.50410 PyPI7Apache 2.0