analyze_coverage
Identify untested code, analyze test coverage, and generate actionable insights for lines, functions, branches, and statements. Excludes non-production files automatically and provides recommendations to improve coverage. Requires project root setup and supports summary or detailed output formats.
Instructions
Perform comprehensive test coverage analysis with line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements. Automatically excludes common non-production files (stories, mocks, e2e tests) and provides recommendations for improving coverage. Detects and prevents analysis on test files themselves. Requires set_project_root to be called first. Coverage thresholds are configured via vitest.config.ts.
USE WHEN: User wants to check test coverage, identify untested code, improve test coverage, asks "what's not tested", "coverage report", "how well tested", or mentions coverage/testing quality. Essential when "vitest-mcp:" prefix is used with coverage-related requests. Prefer this over raw vitest coverage commands for actionable insights.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exclude | No | Glob patterns to exclude from coverage analysis. Examples: ["***.test.*", "**/e2emocks/**"]. Useful for excluding test files, stories, mocks, or other non-production code from coverage calculations. | |
| format | No | Output format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details) | summary |
| target | Yes | Source file path or directory to analyze coverage for. Should target the actual source code files, NOT test files. Can be a specific source file (e.g., "./src/utils/helper.ts") or directory (e.g., "./src/components"). Relative paths resolved from project root. Required to prevent accidental full project analysis which can be slow and resource-intensive. |
Input Schema (JSON Schema)
Implementation Reference
- src/tools/analyze-coverage.ts:547-552 (handler)Entry point handler function for the analyze_coverage tool. Instantiates CoverageAnalyzer and calls its execute method to perform the analysis.export async function handleAnalyzeCoverage( args: AnalyzeCoverageArgs ): Promise<ProcessedCoverageResult> { const analyzer = new CoverageAnalyzer(); return await analyzer.execute(args); }
- src/tools/analyze-coverage.ts:245-256 (handler)Core execution method in CoverageAnalyzer class that orchestrates coverage execution, processing, and error handling.async execute(args: AnalyzeCoverageArgs): Promise<ProcessedCoverageResult> { let builtCommand = ""; try { builtCommand = this.buildDisplayCommand(args); const coverageResult = await this.executeCoverage(args); return await this.processCoverageResults(args, coverageResult); } catch (error) { return this.createErrorResult(error, builtCommand); } }
- src/tools/analyze-coverage.ts:27-58 (schema)Tool object definition including name, description, and input schema for MCP protocol compliance.export const analyzeCoverageTool: Tool = { name: "analyze_coverage", description: 'Perform comprehensive test coverage analysis with line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements. Automatically excludes common non-production files (stories, mocks, e2e tests) and provides recommendations for improving coverage. Detects and prevents analysis on test files themselves. Requires set_project_root to be called first.\n\nUSE WHEN: User wants to check test coverage, identify untested code, improve test coverage, asks "what\'s not tested", "coverage report", "how well tested", or mentions coverage/testing quality. Essential when "vitest-mcp:" prefix is used with coverage-related requests. Prefer this over raw vitest coverage commands for actionable insights.', inputSchema: { type: "object", properties: { target: { type: "string", description: 'Source file path or directory to analyze coverage for. Should target the actual source code files, NOT test files. Can be a specific source file (e.g., "./src/utils/helper.ts") or directory (e.g., "./src/components"). Relative paths resolved from project root. Required to prevent accidental full project analysis which can be slow and resource-intensive.', }, format: { type: "string", enum: ["summary", "detailed"], description: 'Output format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details)', default: "summary", }, exclude: { type: "array", description: 'Glob patterns to exclude from coverage analysis. Examples: ["***.test.*", "**/e2emocks/**"]. Useful for excluding test files, stories, mocks, or other non-production code from coverage calculations.', items: { type: "string", }, default: [], }, }, required: ["target"], }, };
- src/plugins/tool-plugins.ts:74-78 (registration)Plugin creation that wraps the analyze_coverage tool definition and handler using the plugin factory.export const analyzeCoveragePlugin: ToolPlugin<AnalyzeCoverageArgs, ProcessedCoverageResult> = createToolPlugin( analyzeCoverageTool, handleAnalyzeCoverage );
- src/plugins/index.ts:126-126 (registration)Registration of the analyzeCoveragePlugin in the standard tool registry used by the MCP server.registry.register(analyzeCoveragePlugin);
- src/types/coverage-types.ts:114-118 (schema)TypeScript interface defining the input arguments for the analyze_coverage tool.export interface AnalyzeCoverageArgs { target: string; format?: 'summary' | 'detailed'; exclude?: string[]; }