mcp-git-ingest
by: adhikasp
A Model Context Protocol (MCP) server that helps read GitHub repository structure and important files.
📌Overview
Purpose: The mcp-git-ingest
is designed to help users read the structure and important files of GitHub repositories through the Model Context Protocol (MCP).
Overview: This framework acts as a server for extracting and analyzing GitHub repository information, providing functionalities to visualize directory structures and access specified files within repositories. It enhances interaction with GitHub repositories by integrating essential tools for repository exploration.
Key Features:
-
github_directory_structure: This function generates a tree-like representation of a GitHub repository's directory structure while skipping
.git
directories. It facilitates users in understanding the layout of repositories at a glance. -
github_read_important_files: This feature reads and returns the contents of important files specified by users. It carefully handles potential errors during file access and ensures clean-up of temporary directories to maintain system performance.
MCP Git Ingest
Overview
MCP Git Ingest is a Model Context Protocol (MCP) server designed to read GitHub repository structures and important files. It is inspired by gitingest.
Configuration
To configure the MCP Git Ingest server, use the following JSON structure:
{
"mcpServers": {
"mcp-git-ingest": {
"command": "uvx",
"args": ["--from", "git+https://github.com/adhikasp/mcp-git-ingest", "mcp-git-ingest"]
}
}
}
Usage
Using mcp-client-cli, you can read the structure and important files of a GitHub repository:
$ llm read https://github.com/adhikasp/mcp-git-ingest
Technical Details
Purpose
The mcp-git-ingest
server helps users understand GitHub repository structures and crucial files through two main tools:
github_directory_structure
: Returns a tree-like representation of the repository's directory structure.github_read_important_files
: Reads specified files within a repository.
Technical Implementation
-
Dependencies:
fastmcp
for MCP server functionality.gitpython
for Git operations.- Python 3.8+ required.
-
Key Functions:
clone_repo(repo_url: str) -> str
: Clones the repository into a deterministic temporary directory based on its URL hash.get_directory_tree(path: str, prefix: str = "") -> str
: Recursively generates a directory structure while skipping.git
directories.github_directory_structure(repo_url: str) -> str
: Clones the repo, generates the directory tree, and cleans up afterwards.github_read_important_files(repo_url: str, file_paths: List[str]) -> dict[str, str]
: Clones the repo, reads specified files, and returns their contents.
Error Handling
The implementation includes robust error handling through try-except blocks, ensuring that temporary directories are cleaned up using finally
blocks and descriptive error messages are returned.
Performance Optimizations
- Hash-based naming for temporary directories to facilitate reusing cloned repositories.
- Checking for existing repos before cloning to enhance performance.
- Implementing cleanup to prevent the accumulation of temporary files.
Unique Features
- Deterministic directory creation.
- Unicode-based tree representation.
- Flexible file reading capabilities with error handling.
Conclusion
The MCP Git Ingest is a powerful tool for programmatically exploring and reading GitHub repositories while focusing on clean implementation and error management.