Skip to main content
Glama
0xjcf
by 0xjcf

cross-repo-analysis

Analyze dependencies, API usage, and architectural patterns across multiple repositories to identify relationships and integration points.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
primaryRepoUrlYes
relatedRepoUrlsYes
analysisTypeNodependencies
contextDepthNo

Implementation Reference

  • Registers the 'cross-repo-analysis' MCP tool with input schema and handler function.
    server.tool(
      "cross-repo-analysis",
      {
        primaryRepoUrl: z.string(),
        relatedRepoUrls: z.array(z.string()),
        analysisType: z.enum(["dependencies", "api-usage", "architectural-patterns"]).default("dependencies"),
        contextDepth: z.number().min(1).max(3).default(2)
      },
      async ({ primaryRepoUrl, relatedRepoUrls, analysisType, contextDepth }) => {
        try {
          const results = await analyzeMultipleRepositories(
            primaryRepoUrl, 
            relatedRepoUrls, 
            analysisType,
            contextDepth
          );
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(results, null, 2)
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error in cross-repository analysis: ${(error as Error).message}`
            }],
            isError: true
          };
        }
      }
    );
  • Input schema using Zod for primaryRepoUrl (string), relatedRepoUrls (array of strings), analysisType (enum with default), contextDepth (number 1-3 default 2).
    {
      primaryRepoUrl: z.string(),
      relatedRepoUrls: z.array(z.string()),
      analysisType: z.enum(["dependencies", "api-usage", "architectural-patterns"]).default("dependencies"),
      contextDepth: z.number().min(1).max(3).default(2)
    },
  • Tool execution handler: invokes analyzeMultipleRepositories with parameters and returns formatted JSON results or error response.
    async ({ primaryRepoUrl, relatedRepoUrls, analysisType, contextDepth }) => {
      try {
        const results = await analyzeMultipleRepositories(
          primaryRepoUrl, 
          relatedRepoUrls, 
          analysisType,
          contextDepth
        );
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(results, null, 2)
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error in cross-repository analysis: ${(error as Error).message}`
          }],
          isError: true
        };
      }
    }
  • Main analysis function: clones repositories, builds knowledge graphs, dispatches to type-specific analysis, and compiles summaries and relationships.
    export async function analyzeMultipleRepositories(
      primaryRepoUrl: string,
      relatedRepoUrls: string[],
      analysisType: "dependencies" | "api-usage" | "architectural-patterns",
      contextDepth: number = 2
    ): Promise<any> {
      // Step 1: Clone/update all repositories
      const primaryRepoPath = await getRepository(primaryRepoUrl);
      const relatedRepoPaths = await Promise.all(
        relatedRepoUrls.map(url => getRepository(url))
      );
      
      // Step 2: Build knowledge graphs for each repository
      console.log(`Building knowledge graph for primary repository: ${primaryRepoUrl}`);
      const primaryGraph = await buildKnowledgeGraph(primaryRepoUrl, contextDepth, false);
      
      console.log(`Building knowledge graphs for ${relatedRepoUrls.length} related repositories`);
      const relatedGraphsPromises = relatedRepoUrls.map(async (url, index) => {
        console.log(`Building graph for related repository ${index + 1}: ${url}`);
        return {
          url,
          graph: await buildKnowledgeGraph(url, contextDepth, false)
        };
      });
      
      const relatedGraphs = await Promise.all(relatedGraphsPromises);
      
      // Step 3: Analyze cross-repository relationships based on analysis type
      let crossRepoRelationships;
      
      switch (analysisType) {
        case "dependencies":
          crossRepoRelationships = await analyzeCrossDependencies(
            primaryRepoUrl,
            relatedRepoUrls
          );
          break;
        case "api-usage":
          crossRepoRelationships = await analyzeApiUsage(
            primaryRepoUrl,
            relatedRepoUrls
          );
          break;
        case "architectural-patterns":
          crossRepoRelationships = await analyzeArchitecturalPatterns(
            primaryRepoUrl,
            relatedRepoUrls
          );
          break;
        default:
          throw new Error(`Unknown analysis type: ${analysisType}`);
      }
      
      // Step 4: Prepare the result
      return {
        primaryRepository: {
          url: primaryRepoUrl,
          summary: await summarizeRepository(primaryRepoUrl)
        },
        relatedRepositories: await Promise.all(relatedRepoUrls.map(async (url) => ({
          url,
          summary: await summarizeRepository(url)
        }))),
        relationships: crossRepoRelationships,
        analysisType
      };
    }
  • Analyzes shared dependencies between primary and related repositories using knowledge graph queries.
    async function analyzeCrossDependencies(
      primaryRepoUrl: string,
      relatedRepoUrls: string[]
    ): Promise<any> {
      const results: any[] = [];
      
      // Step 1: Get dependency nodes from primary repo
      const primaryResult = await queryKnowledgeGraph({
        query: "dependencies",
        repositoryUrl: primaryRepoUrl,
        contextDepth: 2
      });
      
      const primaryDependencies = primaryResult.nodes.filter(
        node => node.type === "dependency"
      );
      
      // Step 2: For each related repo, find matching dependencies
      for (const relatedUrl of relatedRepoUrls) {
        const relatedResult = await queryKnowledgeGraph({
          query: "dependencies", 
          repositoryUrl: relatedUrl,
          contextDepth: 2
        });
        
        const relatedDependencies = relatedResult.nodes.filter(
          node => node.type === "dependency"
        );
        
        // Find shared dependencies
        const sharedDependencies = primaryDependencies.filter(primaryDep => 
          relatedDependencies.some(relatedDep => 
            primaryDep.name === relatedDep.name
          )
        );
        
        if (sharedDependencies.length > 0) {
          results.push({
            primaryRepository: primaryRepoUrl,
            relatedRepository: relatedUrl,
            type: "shared-dependencies",
            items: sharedDependencies.map(dep => ({
              name: dep.name,
              details: dep.attributes
            }))
          });
        }
      }
      
      return results;
    }
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