Git Ingest

mcp-git-ingest

Analyzes GitHub repository structure and important files.

MCP Git Ingest

A Model Context Protocol (MCP) server that helps read GitHub repository structure and important files.

Features

  • Purpose: The mcp-git-ingest is designed to assist in reading GitHub repository structures and important files. It provides two main tools:
    • github_directory_structure: Returns a tree-like representation of a repository's directory structure.
    • github_read_important_files: Reads and returns the contents of specified files in a repository.

Technical Implementation

  • Dependencies:

    • Uses fastmcp for creating an MCP server.
    • Uses gitpython for Git repository operations.
    • Requires Python 3.8+.
  • Key Functions:

    • clone_repo(repo_url: str) -> str: Creates a deterministic temporary directory based on the repository URL's hash, checks if the repository is already cloned, and handles error cases.
    • get_directory_tree(path: str, prefix: str = "") -> str: Recursively generates a tree-like directory structure while skipping .git directories.
    • github_directory_structure(repo_url: str) -> str: Clones the repository, generates a directory tree, and cleans up the temporary repository after processing.
    • github_read_important_files(repo_url: str, file_paths: List[str]) -> dict[str, str]: Clones the repository, reads specified files, and returns a dictionary mapping file paths to their contents.

Error Handling

  • Uses try-except blocks to manage repository cloning and file reading errors, ensuring that temporary directories are cleaned up with descriptive error messages.

Performance Optimizations

  • Utilizes a hash-based naming convention for temporary directories to potentially reuse cloned repositories and prevent accumulation of temporary files.

Unique Features

  • Deterministic temporary directory creation.
  • Unicode tree representation.
  • Flexible file reading with error handling.

Execution

  • Can be run as a CLI tool via mcp-git-ingest.
  • Configured through pyproject.toml.
  • Depends on fastmcp for MCP server functionality.

The code is a robust, flexible tool for programmatically exploring and reading GitHub repositories, focusing on error handling and clean implementation.

Installation

Server Statistics

LicenseMIT
LocalNo
Published12/20/2024