Skip to main content
Glama

git_read_files

Retrieve and display the contents of specific files from a Git repository by providing a repository URL and file paths for efficient code browsing and analysis.

Instructions

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

Input Schema

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

Implementation Reference

  • Core handler function that implements git_read_files tool: clones Git repo and reads contents of specified files, returning JSON results or errors.
    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, }; } }
  • Defines the tool schema for git_read_files including name, description, and input schema with repo_url and file_paths parameters.
    { 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)
    Registers the handleGitReadFiles function to the 'git_read_files' tool name in the handlersMap for tool dispatch.
    git_read_files: handleGitReadFiles,
  • Re-exports handleGitReadFiles from directory-operations.js for centralized handler access.
    handleGitReadFiles,
  • Imports handleGitReadFiles from directory-operations.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