Skip to main content
Glama
0xjcf
by 0xjcf

evolution-pathway

Analyze code repositories to generate actionable evolution pathways for modernizing architecture, improving performance, enhancing security, or reducing technical debt within specified timeframes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repositoryUrlYes
targetGoalYes
timeframeYes
includeImplementationDetailsNo

Implementation Reference

  • Handler function for the 'evolution-pathway' tool that calls generateEvolutionPlan and formats the response as MCP content.
    async ({ repositoryUrl, targetGoal, timeframe, includeImplementationDetails }) => {
      try {
        const plan = await generateEvolutionPlan(
          repositoryUrl, 
          targetGoal, 
          timeframe,
          includeImplementationDetails
        );
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(plan, null, 2)
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error generating evolution pathway: ${(error as Error).message}`
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining parameters for the evolution-pathway tool.
    {
      repositoryUrl: z.string(),
      targetGoal: z.enum([
        "modernize-architecture", 
        "improve-performance", 
        "enhance-security",
        "reduce-technical-debt"
      ]),
      timeframe: z.enum(["immediate", "sprint", "quarter", "year"]),
      includeImplementationDetails: z.boolean().default(true)
    },
  • Registers the 'evolution-pathway' MCP tool with server.tool(), providing schema and handler.
    server.tool(
      "evolution-pathway",
      {
        repositoryUrl: z.string(),
        targetGoal: z.enum([
          "modernize-architecture", 
          "improve-performance", 
          "enhance-security",
          "reduce-technical-debt"
        ]),
        timeframe: z.enum(["immediate", "sprint", "quarter", "year"]),
        includeImplementationDetails: z.boolean().default(true)
      },
      async ({ repositoryUrl, targetGoal, timeframe, includeImplementationDetails }) => {
        try {
          const plan = await generateEvolutionPlan(
            repositoryUrl, 
            targetGoal, 
            timeframe,
            includeImplementationDetails
          );
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(plan, null, 2)
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error generating evolution pathway: ${(error as Error).message}`
            }],
            isError: true
          };
        }
      }
    );
  • Main helper function implementing the evolution pathway logic: clones repo, analyzes code, detects frameworks, builds knowledge graph, generates goal-specific plans with recommendations filtered by timeframe.
    export async function generateEvolutionPlan(
      repositoryUrl: string,
      targetGoal:
        | "modernize-architecture"
        | "improve-performance"
        | "enhance-security"
        | "reduce-technical-debt",
      timeframe: "immediate" | "sprint" | "quarter" | "year",
      includeImplementationDetails: boolean = true
    ): Promise<any> {
      console.log(
        `Generating ${targetGoal} evolution plan for ${repositoryUrl} (${timeframe} timeframe)`
      );
    
      // Step 1: Clone/update the repository
      const repoPath = await getRepository(repositoryUrl);
    
      // Step 2: Analyze the codebase
      const files = listFiles(repoPath);
      const fileAnalyses: Record<string, any> = {};
    
      // Analyze a subset of files to avoid performance issues with large repositories
      const filesToAnalyze = selectRepresentativeFiles(files, 50);
    
      console.log(`Analyzing ${filesToAnalyze.length} representative files...`);
      for (const file of filesToAnalyze) {
        try {
          const fullPath = path.join(repoPath, file);
          const code = fs.readFileSync(fullPath, "utf8");
          const fileLanguage = path.extname(file).slice(1);
          const analysis = analyzeCode(code, fileLanguage);
          fileAnalyses[file] = analysis;
        } catch (error) {
          console.warn(`Error analyzing file ${file}: ${(error as Error).message}`);
        }
      }
    
      // Step 3: Build knowledge graph
      console.log(`Building knowledge graph...`);
      const { nodes, relationships } = await buildKnowledgeGraph(
        repositoryUrl,
        2,
        false
      );
    
      // Step 4: Retrieve insights from memory
      console.log(`Retrieving memories about this repository...`);
      const memories = await retrieveMemories({
        repositoryUrl,
        limit: 10,
      });
    
      // Step 5: Generate the evolution plan based on target goal and timeframe
      console.log(`Generating ${targetGoal} plan...`);
    
      // Analyze major frameworks and libraries used
      const frameworks = detectFrameworks(files, fileAnalyses);
    
      // Analyze project structure
      const projectStructure = analyzeProjectStructure(files);
    
      // Generate plan based on target goal
      let plan;
      switch (targetGoal) {
        case "modernize-architecture":
          plan = generateModernizeArchitecturePlan(
            repositoryUrl,
            frameworks,
            projectStructure,
            fileAnalyses,
            timeframe,
            includeImplementationDetails
          );
          break;
        case "improve-performance":
          plan = generatePerformancePlan(
            repositoryUrl,
            frameworks,
            fileAnalyses,
            timeframe,
            includeImplementationDetails
          );
          break;
        case "enhance-security":
          plan = generateSecurityPlan(
            repositoryUrl,
            frameworks,
            fileAnalyses,
            timeframe,
            includeImplementationDetails
          );
          break;
        case "reduce-technical-debt":
          plan = generateTechnicalDebtPlan(
            repositoryUrl,
            frameworks,
            projectStructure,
            fileAnalyses,
            timeframe,
            includeImplementationDetails
          );
          break;
        default:
          throw new Error(`Unknown target goal: ${targetGoal}`);
      }
    
      // Return the evolution plan
      return {
        repository: {
          url: repositoryUrl,
          summary: summarizeRepository(
            files,
            fileAnalyses,
            frameworks,
            projectStructure
          ),
        },
        targetGoal,
        timeframe,
        plan,
      };
    }

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