Skip to main content
Glama
razorback16

MCP Git Repo Browser

git_directory_structure

Clone a Git repository and display its directory structure in a tree format to visualize project organization and file hierarchy.

Instructions

Clone a Git repository and return its directory structure in a tree format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_urlYesThe URL of the Git repository

Implementation Reference

  • The main handler function for the 'git_directory_structure' tool. It clones the specified Git repository using cloneRepo helper, generates the directory tree using getDirectoryTree helper, and returns the tree as text content.
    async handleGitDirectoryStructure({ repo_url }) {
      try {
        const repoPath = await cloneRepo(repo_url);
        const tree = await getDirectoryTree(repoPath);
        return {
          content: [
            {
              type: 'text',
              text: tree,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.js:104-117 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      name: 'git_directory_structure',
      description: 'Clone a Git repository and return its directory structure in a tree format.',
      inputSchema: {
        type: 'object',
        properties: {
          repo_url: {
            type: 'string',
            description: 'The URL of the Git repository',
          },
        },
        required: ['repo_url'],
      },
    },
  • Input schema definition for the git_directory_structure tool, specifying the required repo_url parameter.
    inputSchema: {
      type: 'object',
      properties: {
        repo_url: {
          type: 'string',
          description: 'The URL of the Git repository',
        },
      },
      required: ['repo_url'],
    },
  • Helper function to clone the Git repository to a temporary directory, reusing if already cloned.
    async function cloneRepo(repoUrl) {
      // Create deterministic directory name based on repo URL
      const repoHash = crypto.createHash('sha256')
        .update(repoUrl)
        .digest('hex')
        .slice(0, 12);
      const tempDir = path.join(os.tmpdir(), `github_tools_${repoHash}`);
    
      // Check if directory exists and is a valid git repo
      if (await fs.pathExists(tempDir)) {
        try {
          const git = simpleGit(tempDir);
          const remotes = await git.getRemotes(true);
          if (remotes.length > 0 && remotes[0].refs.fetch === repoUrl) {
            return tempDir;
          }
        } catch (error) {
          // If there's any error with existing repo, clean it up
          await fs.remove(tempDir);
        }
      }
    
      // Create directory and clone repository
      await fs.ensureDir(tempDir);
      try {
        await simpleGit().clone(repoUrl, tempDir);
        return tempDir;
      } catch (error) {
        // Clean up on error
        await fs.remove(tempDir);
        throw new Error(`Failed to clone repository: ${error.message}`);
      }
    }
  • Helper function to recursively generate a tree-formatted string of the directory structure, excluding .git.
    async function getDirectoryTree(dirPath, prefix = '') {
      let output = '';
      const entries = await fs.readdir(dirPath);
      entries.sort();
    
      for (let i = 0; i < entries.length; i++) {
        const entry = entries[i];
        if (entry.startsWith('.git')) continue;
    
        const isLast = i === entries.length - 1;
        const currentPrefix = isLast ? '└── ' : '├── ';
        const nextPrefix = isLast ? '    ' : '│   ';
        const entryPath = path.join(dirPath, entry);
        
        output += prefix + currentPrefix + entry + '\n';
        
        const stats = await fs.stat(entryPath);
        if (stats.isDirectory()) {
          output += await getDirectoryTree(entryPath, prefix + nextPrefix);
        }
      }
      
      return output;
    }
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 mentions cloning and returning a tree structure but fails to detail critical aspects like whether it performs a full clone (which could be resource-intensive), how it handles errors (e.g., invalid URLs), authentication needs, rate limits, or the format of the returned tree. This leaves significant gaps in understanding the tool's 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, well-structured sentence that efficiently conveys the core functionality without unnecessary words. It is front-loaded with the main action and outcome, making it easy to grasp quickly, and there is no wasted information.

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?

For a tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the returned tree format looks like, potential side effects of cloning, error handling, or performance considerations. Given the complexity of Git operations and the lack of structured data, more detail is needed to adequately inform an agent.

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, with 'repo_url' clearly documented. The description adds minimal value beyond the schema by implying the URL is used for cloning, but it doesn't provide additional context such as supported URL formats (e.g., HTTPS vs. SSH) or examples. Given the high schema coverage, a 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 ('Clone a Git repository') and the outcome ('return its directory structure in a tree format'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from the sibling tool 'git_read_important_files', which might have overlapping functionality, so it doesn't reach the highest score.

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 'git_read_important_files' or other Git-related operations. It lacks context on prerequisites, such as needing network access or Git installed, and doesn't specify any exclusions or when not to use it.

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/razorback16/mcp-git-repo-browser'

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