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
| Name | Required | Description | Default |
|---|---|---|---|
| file_paths | Yes | List of file paths to read (relative to repository root) | |
| repo_url | Yes | The 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, }; } }
- src/server.js:109-129 (schema)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,
- src/handlers/index.js:44-44 (registration)Re-exports handleGitReadFiles from directory-operations.js for centralized handler access.handleGitReadFiles,
- src/handlers/index.js:4-4 (registration)Imports handleGitReadFiles from directory-operations.js.handleGitReadFiles,