Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

git_read_files

Read specific files from a Git repository to access their contents directly without cloning the entire repository locally.

Instructions

Read the contents of specified files in a given git repository.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_urlYesThe URL of the Git repository
file_pathsYesList of file paths to read (relative to repository root)

Implementation Reference

  • Core handler function that implements the git_read_files tool logic: clones the repository, reads specified files, and returns their contents as JSON.
    export async function handleGitReadFiles({ repo_url, file_paths }) {
      try {
        const repoPath = await cloneRepo(repo_url);
        const results = {};
    
        for (const filePath of file_paths) {
          const fullPath = path.join(repoPath, filePath);
          try {
            if (await fs.pathExists(fullPath)) {
              results[filePath] = await fs.readFile(fullPath, "utf8");
            } else {
              results[filePath] = "Error: File not found";
            }
          } catch (error) {
            results[filePath] = `Error reading file: ${error.message}`;
          }
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(results, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { error: `Failed to process repository: ${error.message}` },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition for the git_read_files tool, specifying parameters repo_url and file_paths.
    {
      name: "git_read_files",
      description:
        "Read the contents of specified files in a given git repository.",
      inputSchema: {
        type: "object",
        properties: {
          repo_url: {
            type: "string",
            description: "The URL of the Git repository",
          },
          file_paths: {
            type: "array",
            items: { type: "string" },
            description:
              "List of file paths to read (relative to repository root)",
          },
        },
        required: ["repo_url", "file_paths"],
      },
    },
  • src/server.js:901-901 (registration)
    Maps the tool name 'git_read_files' to its handler function handleGitReadFiles in the central handlersMap.
    git_read_files: handleGitReadFiles,
  • Re-exports the handleGitReadFiles function from directory-operations.js for use in server.js.
    handleGitReadFiles,

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/bsreeram08/git-commands-mcp'

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