Skip to main content
Glama
giri-jeedigunta

Test Analyzer MCP Server

check_coverage

Analyze test coverage metrics for JavaScript/TypeScript repositories to identify gaps and improve testing quality by detecting frameworks like Jest, Vitest, and Cypress.

Instructions

Check test coverage for a repository and provide detailed metrics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoPathYesPath to the repository
runTestsNoWhether to run tests to generate fresh coverage data

Implementation Reference

  • Primary handler function that validates input, checks repository path, optionally runs tests or reads existing coverage, and returns CoverageResult metrics or error.
    private async checkCoverage(args: any) {
      if (!args.repoPath || typeof args.repoPath !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'repoPath is required');
      }
    
      try {
        const repoPath = path.resolve(args.repoPath);
        
        // Check if path exists
        try {
          await fs.access(repoPath);
        } catch {
          throw new McpError(ErrorCode.InvalidParams, `Repository path does not exist: ${repoPath}`);
        }
    
        let coverageData: CoverageResult | null = null;
    
        if (args.runTests) {
          // Try to run tests with coverage
          coverageData = await this.runTestsWithCoverage(repoPath);
        } else {
          // Try to read existing coverage data
          coverageData = await this.readExistingCoverage(repoPath);
        }
    
        if (!coverageData) {
          return {
            content: [
              {
                type: 'text',
                text: 'No coverage data found. Try running with runTests: true to generate fresh coverage data.',
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(coverageData, null, 2),
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) throw error;
        
        return {
          content: [
            {
              type: 'text',
              text: `Error checking coverage: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:119-137 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema.
    {
      name: 'check_coverage',
      description: 'Check test coverage for a repository and provide detailed metrics',
      inputSchema: {
        type: 'object',
        properties: {
          repoPath: {
            type: 'string',
            description: 'Path to the repository',
          },
          runTests: {
            type: 'boolean',
            description: 'Whether to run tests to generate fresh coverage data',
            default: false,
          },
        },
        required: ['repoPath'],
      },
    },
  • Type definition for the coverage result structure used by the tool.
    interface CoverageResult {
      lines: { percentage: number; covered: number; total: number };
      statements: { percentage: number; covered: number; total: number };
      functions: { percentage: number; covered: number; total: number };
      branches: { percentage: number; covered: number; total: number };
      summary: string;
    }
  • Dispatcher case in CallToolRequestHandler that routes to the checkCoverage method.
    case 'check_coverage':
      return await this.checkCoverage(request.params.arguments);
  • Helper function to read existing coverage data from common locations and parse into CoverageResult.
    private async readExistingCoverage(repoPath: string): Promise<CoverageResult | null> {
      // Common coverage output locations
      const coverageFiles = [
        'coverage/coverage-summary.json',
        'coverage/lcov-report/index.html',
        'coverage-final.json',
        '.nyc_output/processinfo/index.json',
      ];
      
      for (const file of coverageFiles) {
        try {
          const coveragePath = path.join(repoPath, file);
          const content = await fs.readFile(coveragePath, 'utf-8');
          
          if (file.endsWith('.json')) {
            const data = JSON.parse(content);
            
            // Parse coverage-summary.json format
            if (data.total) {
              return {
                lines: data.total.lines,
                statements: data.total.statements,
                functions: data.total.functions,
                branches: data.total.branches,
                summary: this.generateCoverageSummary(data.total),
              };
            }
          }
        } catch {
          // File doesn't exist or can't be parsed
        }
      }
      
      return null;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions checking coverage and providing metrics but does not disclose key behavioral traits such as whether this is a read-only operation, if it requires specific permissions, potential performance impacts, or how it handles errors. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 concise and front-loaded, consisting of a single sentence that directly states the tool's purpose. It avoids unnecessary words and gets straight to the point, making it efficient. However, it could be slightly improved by structuring it to include usage context or behavioral hints without sacrificing brevity.

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

Completeness2/5

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

Given the complexity of checking test coverage (which may involve running tests and generating metrics), the lack of annotations, and no output schema, the description is incomplete. It does not explain what 'detailed metrics' include, how results are returned, or any limitations. For a tool with no structured behavioral data, the description should provide more context to be fully helpful.

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?

The input schema has 100% description coverage, with clear documentation for both parameters ('repoPath' and 'runTests'). The description does not add any semantic details beyond what the schema provides, such as explaining the implications of 'runTests' or format expectations for 'repoPath'. Given the high schema coverage, the baseline score of 3 is appropriate, as the schema handles the parameter documentation adequately.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Check test coverage for a repository and provide detailed metrics.' It specifies the verb ('check'), resource ('test coverage for a repository'), and outcome ('detailed metrics'), making it easy to understand what the tool does. However, it does not explicitly differentiate from sibling tools like 'analyze_test_setup' or 'get_test_summary', which might also relate to testing, so it lacks sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools, prerequisites, or specific contexts for usage. Without any usage guidelines, the agent must infer when to select this tool based on the purpose alone, which is insufficient for optimal tool selection.

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/giri-jeedigunta/hello-mcp'

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