Skip to main content
Glama

analyze_coverage

Analyze test coverage to identify untested code gaps, generate actionable improvement insights, and provide detailed metrics for lines, functions, branches, and statements in your source files.

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

TableJSON Schema
NameRequiredDescriptionDefault
targetYesSource 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.
formatNoOutput format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details)summary
excludeNoGlob patterns to exclude from coverage analysis. Examples: ["***.test.*", "**/e2emocks/**"]. Useful for excluding test files, stories, mocks, or other non-production code from coverage calculations.

Implementation Reference

  • The main exported handler function for the 'analyze_coverage' tool. This is the function passed to createToolPlugin as the execution handler. It instantiates the CoverageAnalyzer class and calls its execute method to perform the coverage analysis.
    export async function handleAnalyzeCoverage( args: AnalyzeCoverageArgs ): Promise<ProcessedCoverageResult> { const analyzer = new CoverageAnalyzer(); return await analyzer.execute(args); }
  • The tool metadata definition including name, description, and inputSchema used by MCP for validation and tool listing.
    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"], }, };
  • Plugin registration that combines the tool definition and handler using createToolPlugin, making it available for the ToolRegistry.
    export const analyzeCoveragePlugin: ToolPlugin<AnalyzeCoverageArgs, ProcessedCoverageResult> = createToolPlugin( analyzeCoverageTool, handleAnalyzeCoverage );
  • Registers the analyzeCoveragePlugin in the standard tool registry returned by createStandardToolRegistry, which is used by the MCP server.
    registry.register(analyzeCoveragePlugin);
  • TypeScript interface definition for AnalyzeCoverageArgs, providing compile-time validation matching the inputSchema.
    export interface AnalyzeCoverageArgs { target: string; format?: 'summary' | 'detailed'; exclude?: string[]; } interface StatementMapping {

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/djankies/vitest-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server