Skip to main content
Glama
shanksxz

GitHub Repository MCP Server

get-repo-structure

Retrieve the file and folder structure of a GitHub repository to understand its organization and contents for analysis or integration.

Instructions

Get the structure of a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesGitHub repository owner/organization name
repoYesGitHub repository name

Implementation Reference

  • The handler function for the 'get-repo-structure' tool. It retrieves all file paths from the repository using the getAllFiles helper, sorts them, and returns a formatted text response with the structure or an error message.
    async ({ owner, repo }) => {
      try {
        const allFiles = await getAllFiles(owner, repo);
    
        const fileStructure = allFiles
          .map(file => file.path)
          .sort()
          .join('\n');
    
        return {
          content: [
            {
              type: "text",
              text: `Repository Structure for ${owner}/${repo}:\n\n${fileStructure}`,
            },
          ],
        };
      } catch (error) {
        console.error("Error fetching repository structure:", error);
        return {
          content: [
            {
              type: "text",
              text: `Error fetching repository structure: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    },
  • Input schema for the 'get-repo-structure' tool, defining 'owner' and 'repo' parameters using Zod.
    {
      owner: z.string().describe("GitHub repository owner/organization name"),
      repo: z.string().describe("GitHub repository name"),
    },
  • src/index.ts:200-236 (registration)
    Registration of the 'get-repo-structure' tool using server.tool(), including description, schema, and inline handler.
    server.tool(
      "get-repo-structure",
      "Get the structure of a GitHub repository",
      {
        owner: z.string().describe("GitHub repository owner/organization name"),
        repo: z.string().describe("GitHub repository name"),
      },
      async ({ owner, repo }) => {
        try {
          const allFiles = await getAllFiles(owner, repo);
    
          const fileStructure = allFiles
            .map(file => file.path)
            .sort()
            .join('\n');
    
          return {
            content: [
              {
                type: "text",
                text: `Repository Structure for ${owner}/${repo}:\n\n${fileStructure}`,
              },
            ],
          };
        } catch (error) {
          console.error("Error fetching repository structure:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error fetching repository structure: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      },
    );
  • Helper function getAllFiles that recursively traverses the repository directory structure to collect all file paths, used by the get-repo-structure handler.
    async function getAllFiles(owner: string, repo: string, path: string = ""): Promise<{ path: string, type: string }[]> {
      const contents = await getRepoContents(owner, repo, path);
      let allFiles: { path: string, type: string }[] = [];
    
      for (const item of contents) {
        if (item.type === 'file') {
          allFiles.push({
            path: item.path,
            type: 'file'
          });
        } else if (item.type === 'dir') {
          const subFiles = await getAllFiles(owner, repo, item.path);
          allFiles = [...allFiles, ...subFiles];
        }
      }
    
      return allFiles;
    }
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 the tool retrieves repository structure but doesn't explain what that entails (e.g., returns a tree, includes file types, requires authentication, has rate limits, or is read-only). This leaves significant gaps in understanding how the tool behaves.

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 with no wasted words. It's front-loaded with the core purpose, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete. It doesn't clarify what 'structure' means, how results are formatted, or any behavioral traits like authentication needs. For a tool with two parameters and no structured context, more detail is needed to be fully helpful.

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 input schema has 100% description coverage, clearly documenting both parameters ('owner' and 'repo'). The description adds no additional meaning beyond the schema, such as examples or constraints. Since schema coverage is high, the baseline score of 3 is appropriate.

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 ('Get') and resource ('structure of a GitHub repository'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get-file-content' or 'get-repo-context', which likely retrieve different aspects of repository data.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get-file-content' or 'get-repo-context'. It lacks context about what 'structure' means (e.g., directory tree, file metadata) or any prerequisites for usage.

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/shanksxz/gh-mcp-server'

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