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 {
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it 'Automatically excludes common non-production files (stories, mocks, e2e tests),' 'Detects and prevents analysis on test files themselves,' mentions performance considerations ('prevent accidental full project analysis which can be slow and resource-intensive'), and notes configuration dependencies ('Coverage thresholds are configured via vitest.config.ts'). It lacks details on rate limits or error handling, but covers most operational aspects.

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?

The description is appropriately sized and front-loaded with the core purpose in the first sentence. The 'USE WHEN' section is well-structured but slightly verbose; every sentence earns its place by providing specific guidance, though it could be more streamlined without losing clarity.

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?

Given the tool's complexity (coverage analysis with multiple parameters) and no output schema, the description is mostly complete: it explains what the tool does, when to use it, behavioral traits, and prerequisites. It lacks details on return values or error cases, but compensates with rich usage guidelines and transparency. With no annotations, it does a good job covering essential context.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal parameter semantics beyond the schema, such as implying the 'target' should be 'actual source code files, NOT test files' and mentioning exclusions in the context of the tool's behavior. This meets the baseline of 3 when the schema does the heavy lifting.

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?

The description clearly states the tool performs 'comprehensive test coverage analysis' with specific capabilities like 'line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements.' It distinguishes itself from sibling tools like 'list_tests' and 'run_tests' by focusing on coverage analysis rather than test execution or listing.

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

Usage Guidelines5/5

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

The description includes explicit 'USE WHEN' guidance with specific user scenarios (e.g., 'User wants to check test coverage, identify untested code'), mentions prerequisites ('Requires set_project_root to be called first'), and provides alternatives ('Prefer this over raw vitest coverage commands for actionable insights'). It also specifies when to use based on context ('Essential when "vitest-mcp:" prefix is used with coverage-related requests').

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

Install Server

Other Tools

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