# dotnet-coverage-mcp [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/Hyeonu-Cha/dotnet-coverage-mcp  
**GitHub Stars:** 3  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/dotnet-coverage-mcp

## Description
MCP server for .NET coverage: run tests, parse Cobertura, find uncovered branches, append tests.

## Tools
Capabilities this server exposes over MCP:

- **get_test_environment** — Detect the test framework, runner, coverage collector, and mocking and assertion libraries.
- **describe_test_target** — Learn how to construct a class in a test, and whether a unit or integration test fits.
- **get_source_files** — List the `.cs` files to cover in a file, folder or project, grouped into batches.
- **run_tests_with_coverage** — Run `dotnet test` with coverage and get the Cobertura report path.
- **get_coverage_gaps** — Get, per file below target, the methods and branches to test next.
- **get_coverage_summary** — See the classes with the worst coverage.
- **get_file_coverage** — Check one file against the target rate.
- **get_uncovered_branches** — See the uncovered branch conditions of a method.
- **get_coverage_diff** — Compare coverage with the previous run.
- **append_test_code** — Insert test methods into a test file.
- **cleanup_session** — Remove the test results and state files the server created.

## Claude Desktop Quick Installation
No confirmed install details yet, so no config is published. Follow the setup steps in the repository above.

## Documentation

## What dotnet-coverage-mcp does

dotnet-coverage-mcp exposes .NET testing and coverage operations as MCP tools for clients such as Claude Code and Gemini CLI. It works with source files, folders, and `.csproj` scopes, while filtering out common non-test targets such as generated code, entry points, data-only models, dependency-injection registration, and test projects.

The server supports a coverage-driven test workflow: discover source files, run the test suite, inspect coverage gaps, add test members, run again, and compare the result with a previous run. Coverage analysis uses Cobertura XML, which is also the report path returned by the test tool.

## How it works

The server runs as a console process and communicates with an MCP client over standard input and output. The client launches it and invokes tools, while the server calls `dotnet test` through the shell when a test run is requested.

`run_tests_with_coverage` uses coverlet with VSTest. When `global.json` selects Microsoft.Testing.Platform, it uses Microsoft's CodeCoverage extension instead. Results include test counts and coverage output. Failed tests retain coverage data, while an aborted test host does not produce coverage for that run.

For larger projects, `get_source_files` can create smart batches based on a line budget. Coverage gaps can then be examined per batch without rerunning tests for every file. Session IDs provide isolation for concurrent workflows, and cleanup removes artifacts created for a session.

## Setup and configuration

Configure an MCP-compatible client to launch the dotnet-coverage-mcp console process over stdio. The server operates against the .NET projects and test files available to that process.

Coverage checks use a default target rate of 0.8 for both line and branch coverage. Tools that evaluate coverage accept a target rate or filtering options where supported. A `sessionId` can be passed to test, query, diff, and cleanup operations when separate workflows need isolated state.

The test-environment inspection tool reads `obj/project.assets.json` when the project has been restored. It identifies the test framework, runner, coverage collector, mocking and assertion libraries, and integration-test packages.

## Tools and capabilities

- `get_source_files` discovers C# files, reports exclusions and reasons, returns file metadata, and provides paginated batches.
- `run_tests_with_coverage` runs tests, collects coverage, reports pass/fail/skip counts, and distinguishes failures, build errors, unmatched tests, busy projects, and aborted test hosts.
- `get_coverage_summary` ranks classes and methods by branch coverage and can limit results to items below a target.
- `get_file_coverage` evaluates one source file and reports whether its classes meet both line and branch targets.
- `get_coverage_gaps` identifies deficient files, uncovered line ranges, uncovered branches, relevant source, and a small set of methods to test.
- `get_uncovered_branches` finds uncovered conditions for methods by exact or partial name matching.
- `get_coverage_diff` compares method-level coverage with a baseline, including added and removed methods.
- `describe_test_target` summarizes constructor dependencies, methods, decision points, uncontrollable calls, suggested test types, and existing test files using syntax-only analysis.
- `append_test_code` inserts or appends C# members with duplicate detection, syntax checks, anchor matching, formatting preservation, and atomic writes.
- `cleanup_session` removes generated session state and tool-created `TestResults-*` directories without deleting the bare `TestResults` directory used by `dotnet test` and Visual Studio.

## Limitations and notes

Coverage artifacts and session state remain until `cleanup_session` is called. A run covering multiple target frameworks produces reports that are merged so coverage from any framework counts as covered.

`append_test_code` accepts member syntax rather than arbitrary C# source. Invalid members, duplicate signatures, and unsafe fallback insertions are rejected without changing the file. `describe_test_target` provides syntax-based guidance rather than executing code.

Only the test-running operation can reach NuGet during a restore. Tool results report failures as structured MCP errors with stable error types, and read-only query operations are annotated as read-only and idempotent.

_Full upstream README: https://allmcps.com/mcp/dotnet-coverage-mcp/readme_

