
Dotnet Coverage Mcp
io.github.Hyeonu-Cha由 GitHub 帳號 Hyeonu-Cha 發布v2.1.0更新於 Nov 20, 2026
MCP server for .NET coverage: run tests, parse Cobertura, find uncovered branches, append tests.
概覽
本機 MCP 伺服器,讓助理執行 .NET 測試、讀取 Cobertura 覆蓋率、找出未覆蓋分支與缺口、比較兩次執行並附加測試程式碼。
- 可以做什麼
- 探索原始碼檔案並依行數預算分批,並分析測試目標的相依性、方法與難以控制的呼叫
- 執行含覆蓋率的 dotnet test,回傳通過/失敗/略過數量、失敗詳情與 Cobertura 報告路徑
- 彙總類別與方法覆蓋率、依目標覆蓋率檢查單一檔案、列出未覆蓋分支
- 報告各檔案的覆蓋率缺口及可補足缺口的方法,並與基準比較覆蓋率變化
- 偵測測試專案的框架、執行器、覆蓋率收集器與模擬套件
- 將 C# 測試程式碼附加或插入測試檔案,並清理工作階段產物
- 適用情境
- 適合在 AI 用戶端內提升或檢查 .NET 儲存庫的測試覆蓋率,尤其是反覆迭代:先跑一次測試、找出缺口、撰寫測試、再跑並比較。也適合在撰寫測試前了解測試專案的技術堆疊。
- 執行需求
- 以本機 stdio 程序執行;需安裝 .NET 10 或更新版本,測試專案需有覆蓋率收集器(VSTest 上為 coverlet.collector,Microsoft.Testing.Platform 上為 Microsoft.Testing.Extensions.CodeCoverage)。可安裝為全域 .NET 工具或從原始碼執行。建議將 COVERAGE_MCP_ALLOWED_ROOT 設為儲存庫根目錄;可選 COVERAGE_MCP_DOTNET_TEST_TIMEOUT_MS 與 COVERAGE_MCP_HANG_TIMEOUT_SECONDS 調整逾時。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Dotnet Coverage Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
dotnet-coverage-mcp
[build] [tests] [NuGet] [License: MIT]
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
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.
Available Tools
Tools are named here as MCP clients list and call them.
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 batches - Run once — Call
run_tests_with_coveragewithout a filter (runs every test) to collect coverage across all files - Find 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 methods - Re-run and diff — Run tests once, call
get_coverage_diffto verify improvement - Repeat — 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-parse - Scoped state files — Coverage state is written to
.mcp-coverage/.coverage-state-{hash}, soResolveCoberturaPathresolves to the correct XML for each session - Scoped baselines —
get_coverage_diffstores baselines as.coverage-prev-{hash}.xmlper session - Atomic 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).
Optional settings, also environment variables:
Install
Install the server as a global .NET tool from NuGet:
After install, the dotnet-coverage-mcp command is on your PATH.
Build & Run (from source)
The 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 Desktop
Add to claude_desktop_config.json (Settings → Developer → Edit Config):
Cursor
Add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (per-project):
VS Code (GitHub Copilot)
Add to .vscode/mcp.json:
Run from source
To run from source instead of the global tool, use dotnet run:
Or point directly at the compiled executable:
Tool Parameters
get_source_files
run_tests_with_coverage
get_coverage_summary
get_file_coverage
describe_test_target
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
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
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
get_coverage_diff
append_test_code
cleanup_session
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.
Plugin (Skills & Agent)
This repo includes a plugin/ directory with Claude Code skills and an agent definition for guided test coverage workflows:
The skills support NUnit, xUnit, and MSTest with framework-agnostic reference docs in references/unit.md and references/integration.md.
Dependencies
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.
來源:README.md,提交 642be01
工具
0版本歷史
4- v2.1.0最新Nov 20, 2026
- v2.0.7Nov 20, 2026
- v2.0.6Nov 19, 2026
- v0.1.1Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分