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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_url | Yes | The URL of the Git repository | |
| file_paths | Yes | List 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, }; } }
- src/server.js:109-129 (schema)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,
- src/handlers/index.js:44-44 (registration)Re-exports the handleGitReadFiles function from directory-operations.js for use in server.js.handleGitReadFiles,