Skip to main content
Glama

analyze_repository

Analyze GitHub repositories to identify code examples demonstrating specific code smells for structured learning sessions.

Instructions

Analyze a GitHub repository to find real code examples for Learning Hours

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repositoryUrlYesGitHub repository URL to analyze
codeSmellYesType of code smell to find (e.g., 'Feature Envy', 'Long Method')

Implementation Reference

  • The primary handler for the 'analyze_repository' tool. Validates input using Zod schema, delegates analysis to RepositoryAnalyzer, handles errors, and returns formatted results.
    private async analyzeRepository(args: any) {
      const input = AnalyzeRepositoryInputSchema.parse(args);
    
      try {
        const analysisResult = await this.repositoryAnalyzer.analyzeRepository(input.repositoryUrl, input.codeSmell);
    
        return {
          content: [
            {
              type: "text",
              text: `✅ Repository analysis completed for: ${input.codeSmell}`,
            },
            {
              type: "text",
              text: `Found ${analysisResult.examples.length} examples in ${input.repositoryUrl}`,
            },
            {
              type: "text",
              text: JSON.stringify(analysisResult, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
    
        if (errorMessage.includes('GitHub integration not configured')) {
          return {
            content: [
              {
                type: "text",
                text: `❌ GitHub integration not configured`,
              },
              {
                type: "text",
                text: `To use repository analysis, please set GITHUB_TOKEN in your environment.`,
              },
              {
                type: "text",
                text: `Visit https://github.com/settings/tokens to create a personal access token with 'repo' scope.`,
              },
            ],
          };
        }
    
        if (errorMessage.includes('No examples')) {
          return {
            content: [
              {
                type: "text",
                text: `⚠️ No examples found`,
              },
              {
                type: "text",
                text: errorMessage,
              },
            ],
          };
        }
    
        throw new Error(`Failed to analyze repository: ${errorMessage}`);
      }
    }
  • Core implementation of repository analysis: parses GitHub URL, generates search queries for code smells, searches files using GitHub client, analyzes content for examples, and returns AnalysisResult.
    async analyzeRepository(repositoryUrl: string, codeSmell: string): Promise<AnalysisResult> {
      const { owner, repo } = this.parseGitHubUrl(repositoryUrl);
      
      try {
        const searchQueries = this.getSearchQueriesForCodeSmell(codeSmell);
        const examples: CodeExample[] = [];
    
        for (const query of searchQueries) {
          try {
            const searchResult = await this.githubClient.searchRepositoryFiles(owner, repo, query);
            const items = (searchResult as any)?.content?.[0]?.text ?
              JSON.parse((searchResult as any).content[0].text).items : [];
    
            for (const item of items.slice(0, 3)) {
              const fileContent = await this.githubClient.getFileContent(owner, repo, item.path);
              const content = this.extractFileContent(fileContent);
    
              const example = this.analyzeFileForCodeSmell(
                item.path,
                content,
                codeSmell
              );
    
              if (example) {
                examples.push(example);
              }
            }
          } catch (error) {
            if (error instanceof Error && error.message.includes('GitHub MCP client not connected')) {
              throw error;
            }
            logger.error(`Search query failed: ${query}`, error);
          }
        }
    
        if (examples.length === 0) {
          throw new Error(`No examples of '${codeSmell}' found in repository ${repositoryUrl}. Try searching for a different code smell or repository.`);
        }
    
        return {
          examples: examples.slice(0, 5),
          codeSmell,
          repositoryUrl
        };
      } catch (error) {
        if (error instanceof Error && error.message.includes('GitHub MCP client not connected')) {
          throw new Error('GitHub integration not configured. Please ensure GITHUB_TOKEN is set in your environment.');
        }
        throw error;
      }
    }
  • Zod schema used for input validation in the analyze_repository handler.
    const AnalyzeRepositoryInputSchema = z.object({
      repositoryUrl: z.string().min(1, "Repository URL is required"),
      codeSmell: z.string().min(1, "Code smell type is required"),
    });
  • src/index.ts:153-170 (registration)
    Tool registration in the ListTools response, defining name, description, and JSON input schema.
    {
      name: "analyze_repository",
      description: "Analyze a GitHub repository to find real code examples for Learning Hours",
      inputSchema: {
        type: "object",
        properties: {
          repositoryUrl: {
            type: "string",
            description: "GitHub repository URL to analyze",
          },
          codeSmell: {
            type: "string",
            description: "Type of code smell to find (e.g., 'Feature Envy', 'Long Method')",
          },
        },
        required: ["repositoryUrl", "codeSmell"],
      },
    },
  • src/index.ts:246-247 (registration)
    Dispatcher in CallToolRequestHandler that routes 'analyze_repository' calls to the handler method.
    case "analyze_repository":
      return await this.analyzeRepository(request.params.arguments);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't reveal important traits like whether it's read-only or mutative, what permissions are needed, how it handles errors, or the format of results. For a tool analyzing repositories, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It directly communicates the tool's function and goal, making it easy to understand at a glance.

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

Completeness2/5

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

Given the complexity of analyzing repositories and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the analysis entails, what kind of output to expect, or any limitations. For a tool with two required parameters and no structured output information, more context is needed to guide effective use.

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

Parameters3/5

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

The schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond what's in the schema, such as explaining what constitutes a valid repository URL or providing more context about code smells. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('analyze') and resource ('GitHub repository') with a specific purpose ('to find real code examples for Learning Hours'). It distinguishes from most siblings like 'analyze_tech_stack' by focusing on code examples rather than technology analysis, though it doesn't explicitly contrast with 'generate_code_example' which might be related.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. While the purpose is clear, there's no mention of prerequisites, when not to use it, or how it differs from 'generate_code_example' which might create rather than find examples. The description implies usage for Learning Hours but lacks explicit context.

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/SDiamante13/learning-hour-mcp'

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