Skip to main content
Glama
TheAlchemist6

CodeCompass MCP

analyze_codebase

Analyze GitHub repositories to understand code structure, architecture patterns, complexity metrics, and quality indicators through comprehensive automated analysis.

Instructions

🔬 Comprehensive codebase analysis combining structure, architecture, and metrics. Provides unified view of code organization, design patterns, complexity, and quality indicators.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesGitHub repository URL
file_pathsNoSpecific files to analyze (optional - analyzes all code files if not specified)
analysis_typesNoTypes of analysis to perform
optionsNo

Implementation Reference

  • Tool schema definition including input validation, description, and parameters for analyze_codebase
    {
      name: 'analyze_codebase',
      description: '🔬 Comprehensive codebase analysis combining structure, architecture, and metrics. Provides unified view of code organization, design patterns, complexity, and quality indicators.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'GitHub repository URL',
          },
          file_paths: {
            type: 'array',
            items: { type: 'string' },
            description: 'Specific files to analyze (optional - analyzes all code files if not specified)',
          },
          analysis_types: {
            type: 'array',
            items: {
              type: 'string',
              enum: ['structure', 'architecture', 'metrics', 'patterns', 'complexity'],
            },
            description: 'Types of analysis to perform',
            default: ['structure', 'architecture', 'metrics'],
          },
          options: {
            type: 'object',
            properties: {
              include_functions: {
                type: 'boolean',
                description: 'Include function analysis',
                default: true,
              },
              include_classes: {
                type: 'boolean',
                description: 'Include class analysis',
                default: true,
              },
              include_imports: {
                type: 'boolean',
                description: 'Include import/dependency analysis',
                default: true,
              },
              include_complexity: {
                type: 'boolean',
                description: 'Include complexity metrics',
                default: true,
              },
              include_patterns: {
                type: 'boolean',
                description: 'Include design pattern detection',
                default: true,
              },
              include_components: {
                type: 'boolean',
                description: 'Include reusable component identification',
                default: false,
              },
              languages: {
                type: 'array',
                items: { type: 'string' },
                description: 'Programming languages to analyze',
              },
              confidence_threshold: {
                type: 'number',
                description: 'Minimum confidence score for pattern detection',
                default: 0.7,
              },
            },
          },
        },
        required: ['url'],
      },
    },
  • src/index.ts:236-240 (registration)
    Registers the consolidatedTools array (including analyze_codebase) for the MCP listTools endpoint
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: consolidatedTools,
      };
    });
  • src/index.ts:269-271 (registration)
    Dispatch registration in the main tool switch statement mapping 'analyze_codebase' to its handler
    case 'analyze_codebase':
      result = await handleAnalyzeCodebase(args);
      break;
  • MCP tool handler function for analyze_codebase that extracts arguments and delegates to GitHubService
    async function handleAnalyzeCodebase(args: any) {
      try {
        const { url, file_paths, options = {} } = args;
        
        const analysis = await githubService.analyzeCodeStructure(url, file_paths, options);
        
        const response = createResponse(analysis);
        return formatToolResponse(response);
      } catch (error) {
        const response = createResponse(null, error);
        return formatToolResponse(response);
      }
    }
  • Core implementation performing code structure analysis: extracts functions/imports, calculates complexity metrics across key repository files
    async analyzeCodeStructure(url: string, file_paths?: string[], options: any = {}): Promise<any> {
      const keyFiles = await this.getKeyFiles(url);
      const codeStructure: any = {
        functions: [],
        classes: [],
        imports: [],
        exports: [],
        complexity: {
          cyclomatic: 0,
          cognitive: 0,
          maintainability: 0,
        },
      };
      
      for (const [filePath, content] of Object.entries(keyFiles)) {
        if (file_paths && !file_paths.includes(filePath)) continue;
        
        // Extract functions
        const functions = this.extractFunctions(content);
        codeStructure.functions.push(...functions.map(func => ({
          name: func,
          signature: `function ${func}()`,
          startLine: 0,
          endLine: 0,
          complexity: 1,
          parameters: [],
          documentation: '',
        })));
        
        // Extract imports
        const imports = this.extractDependencies(content);
        codeStructure.imports.push(...imports.map(imp => ({
          source: imp,
          imports: [],
          type: 'import',
          isExternal: !imp.startsWith('.'),
        })));
        
        // Calculate complexity
        codeStructure.complexity.cyclomatic += this.calculateFileComplexity(content);
      }
      
      codeStructure.complexity.maintainability = this.calculateMaintainability(keyFiles);
      
      return codeStructure;
    }

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/TheAlchemist6/codecompass-mcp'

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