Skip to main content
Glama

analyze_coverage

Analyze test coverage for a target file or directory to find untested lines, functions, branches, and statements. Delivers actionable insights and metrics to improve test quality.

Instructions

Perform comprehensive test coverage analysis with line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements. Runs the tests that import the target (wherever they live, e.g. ./test or tests) and reports coverage for the target only, including files no test touches. Automatically excludes common non-production files (stories, mocks, e2e tests). Detects and prevents analysis on test files themselves. Requires set_project_root to be called first. Coverage thresholds are read from the Vitest config.

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

NameRequiredDescriptionDefault
formatNoOutput format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details)summary
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.
excludeNoGlob patterns to exclude from coverage analysis. Examples: ["**/*.stories.*", "**/e2e/**"]. Useful for excluding stories, mocks, or other non-production code from coverage calculations.
projectNoOptional name of a Vitest project (from the `projects` array in vitest.config) whose tests should be used to measure coverage, e.g. "unit". Defaults to all projects.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.6.0
    • changedInput schema / properties / exclude / description
      Previous value: -"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."New value: +"Glob patterns to exclude from coverage analysis. Examples: [\"**/*.stories.*\", \"**/e2e/**\"]. Useful for excluding stories, mocks, or other non-production code from coverage calculations."
    • addedInput schema / properties / project
      Added value: +{
      +  "description": "Optional name of a Vitest project (from the `projects` array in vitest.config) whose tests should be used to measure coverage, e.g. \"unit\". Defaults to all projects.",
      +  "type": "string"
      +}
  2. First observed

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does well: it discloses that it runs importing tests wherever they live, auto-excludes non-production files (stories/mocks/e2e), refuses to analyze test files themselves, reads thresholds from the Vitest config, and requires prior set_project_root. It does not mention runtime cost or failure modes, keeping it out of the top tier.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core purpose, then a scannable "USE WHEN" block. Every sentence carries information; the description is long but for a complex tool with setup prerequisites and exclusion rules the length is largely justified.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, so return-value explanation falls on the description; it covers what is reported (gap listings plus line/function/branch/statement metrics) and that a summary vs detailed format is selectable. What remains thin is the concrete shape/magnitude of the report, but the essentials for correct invocation are present.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% so the baseline is 3, but the description adds real meaning beyond it: it clarifies that target must be source code, that paths resolve from the project root, and that automatic exclusions happen beyond the user-supplied exclude globs. format and project parameters get no extra prose, so it is not a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ("Perform comprehensive test coverage analysis") and enumerates the exact outputs (line-by-line gaps, metrics for lines/functions/branches/statements). Scope is pinned down: it reports coverage for the target only, including untouched files, which the agent can distinguish from the sibling run_tests/list_tests tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The USE WHEN block gives explicit triggers ("what's not tested", "coverage report") and names an alternative ("prefer this over raw vitest coverage commands for actionable insights"), plus a prerequisite (set_project_root first). It stops short of an explicit when-not-this-vs-run_tests statement, so it falls just below a full 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.