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;
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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