Skip to main content
Glama

analyze-repository

Analyze code repositories to assess structure, dependencies, and complexity metrics for better understanding and optimization.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repositoryUrlYesURL of the repository to analyze (e.g., 'https://github.com/username/repo')
depthNoAnalysis depth - higher values analyze more deeply but take longer (1-5)
includeDependenciesNoInclude dependency analysis in the results
includeComplexityNoInclude complexity metrics in the results
specificFilesNoSpecific files to analyze, can include glob patterns (e.g., ['src/*.ts', 'lib/utils.js'])

Implementation Reference

  • The main handler for the analyze-repository tool. It logs the call, calls the analyzeRepository helper with the repository URL, incorporates additional parameters like depth and flags into the response, handles errors using createErrorResponse, and returns an MCP-formatted text response with JSON data.
    async (args) => { try { console.log("analyze-repository called with:", args); // Perform the actual analysis const startTime = Date.now(); const analysis = await analyzeRepository(args.repositoryUrl); // Create a standardized response with the results const responseData = { repository: args.repositoryUrl, result: { ...analysis.data, includedDependencies: args.includeDependencies, includedComplexity: args.includeComplexity, depth: args.depth, specificFiles: args.specificFiles || "all" } }; // Return MCP-formatted response return { content: [{ type: "text", text: JSON.stringify(responseData, null, 2) }] }; } catch (error) { // Create a standardized error response const errorResponse = createErrorResponse( error instanceof Error ? error.message : String(error), "analyze-repository" ); // Return MCP-formatted error response return { content: [{ type: "text", text: JSON.stringify(errorResponse, null, 2) }], isError: true }; } } );
  • Zod input schema defining parameters for the analyze-repository tool, including required repositoryUrl and optional depth, flags, and specificFiles.
    { repositoryUrl: z.string().describe("URL of the repository to analyze (e.g., 'https://github.com/username/repo')"), depth: z.number().default(2).describe("Analysis depth - higher values analyze more deeply but take longer (1-5)"), includeDependencies: z.boolean().default(true).describe("Include dependency analysis in the results"), includeComplexity: z.boolean().default(true).describe("Include complexity metrics in the results"), specificFiles: z.array(z.string()).optional().describe("Specific files to analyze, can include glob patterns (e.g., ['src/*.ts', 'lib/utils.js'])") },
  • Registration of the analyze-repository tool on the MCP server using server.tool(), including the name, input schema, and handler function. This is called within registerAnalysisTools.
    server.tool( "analyze-repository", { repositoryUrl: z.string().describe("URL of the repository to analyze (e.g., 'https://github.com/username/repo')"), depth: z.number().default(2).describe("Analysis depth - higher values analyze more deeply but take longer (1-5)"), includeDependencies: z.boolean().default(true).describe("Include dependency analysis in the results"), includeComplexity: z.boolean().default(true).describe("Include complexity metrics in the results"), specificFiles: z.array(z.string()).optional().describe("Specific files to analyze, can include glob patterns (e.g., ['src/*.ts', 'lib/utils.js'])") }, async (args) => { try { console.log("analyze-repository called with:", args); // Perform the actual analysis const startTime = Date.now(); const analysis = await analyzeRepository(args.repositoryUrl); // Create a standardized response with the results const responseData = { repository: args.repositoryUrl, result: { ...analysis.data, includedDependencies: args.includeDependencies, includedComplexity: args.includeComplexity, depth: args.depth, specificFiles: args.specificFiles || "all" } }; // Return MCP-formatted response return { content: [{ type: "text", text: JSON.stringify(responseData, null, 2) }] }; } catch (error) { // Create a standardized error response const errorResponse = createErrorResponse( error instanceof Error ? error.message : String(error), "analyze-repository" ); // Return MCP-formatted error response return { content: [{ type: "text", text: JSON.stringify(errorResponse, null, 2) }], isError: true }; } } );
  • Key helper function analyzeRepository that clones the repository, lists files, extracts dependencies using extractDependencies, generates analysis ID, caches results, and supports single file analysis. Called by the main handler.
    export async function analyzeRepository( repositoryUrl?: string, fileContent?: string, language?: string ): Promise<any> { return executeWithTiming('analyze-repository', async () => { if (repositoryUrl) { const repoPath = await getRepository(repositoryUrl); const files = listFiles(repoPath); const analysisId = uuidv4(); // Perform dependency analysis const dependencies = extractDependencies(repoPath, files, language); // Store results in cache const results = { repositoryUrl, analysisId, dependencies, fileCount: files.length, timestamp: new Date().toISOString() }; analysisCache.set(analysisId, results); return results; } else if (fileContent) { // Analyze single file content const dependencies = analyzeCode(fileContent, language); return { analysisId: uuidv4(), dependencies, timestamp: new Date().toISOString() }; } else { throw new Error("Either repositoryUrl or fileContent must be provided"); } }); }

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/0xjcf/MCP_CodeAnalysis'

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