Skip to main content
Glama
0xjcf
by 0xjcf

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");
        }
      });
    }
Behavior1/5

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

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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

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