Back to MCP directory
publicPublicdnsLocal runtime

mcp-git-ingest

一个用于读取GitHub仓库结构和重要文件的MCP服务器

article

README

🚀 MCP Git 仓库导入工具

MCP Git 仓库导入工具 是一个模型上下文协议(MCP)服务器,旨在帮助读取 GitHub 仓库结构和重要文件,为开发者提供便利。它受 gitingest 启发而开发。

smithery badge

🚀 快速开始

配置

你可以按照以下方式对工具进行配置:

{
    "mcpServers": {
        "mcp-git-ingest": {
            "command": "uvx",
            "args": ["--from", "git+https://github.com/adhikasp/mcp-git-ingest", "mcp-git-ingest"]
        }
    }
}

使用方法

你可以使用 mcp-client-cli 来使用本工具,以下是使用示例:

$ llm read https://github.com/adhikasp/mcp-git-ingest 并确定代码如何工作

我将帮助你了解mcp-git-ingest仓库的技术细节。首先获取目录结构,然后读取重要文件以分析代码实现。

工具调用:
  github_directory_structure
  参数:
    repo_url: https://github.com/adhikasp/mcp-git-ingest

现在,我将读取重要文件以理解技术实现:

工具调用:
  github_read_important_files
  参数:
    repo_url: https://github.com/adhikarp/mcp-git-ingest
    file_paths: ['README.md', 'src/mcp_git_ingest/main.py', 'pyproject.toml']

✨ 主要特性

  • 提供两个主要工具:
    • github_directory_structure:返回仓库目录结构的树状表示。
    • github_read_important_files:读取并返回指定文件的内容。
  • 支持并行处理多个仓库,提高处理效率。
  • 提供详细日志记录,增强调试能力。

📦 安装指南

# 项目依赖管理
pip install gitpython fastmcp

# 克隆仓库并运行
git clone https://github.com/adhikarp/mcp-git-ingest.git
cd mcp-git-ingest
python3 src/main.py

💻 使用示例

基础用法

# 示例代码结构
class GitRepository:
    def __init__(self, url):
        self.url = url
        self.repository_path = None
        
    def clone(self):
        # 克隆仓库的逻辑
        pass
    
    def get_file(self, path):
        # 获取指定路径文件内容
        pass

def main():
    repo = GitRepository("https://github.com/adhikarp/mcp-git-ingest")
    repo.clone()
    tree = get_directory_tree(repo.repository_path)
    files = [repo.get_file(f) for f in ["README.md", "pyproject.toml"]]
    
if __name__ == "__main__":
    main()

🔧 技术细节

目的

mcp-git-ingest 是一个模型上下文协议(MCP)服务器,设计用于帮助读取 GitHub 仓库结构和重要文件。

技术实现

依赖项

  • 使用 fastmcp 创建 MCP 服务器。
  • 使用 gitpython 进行 Git 仓库操作。
  • 需要 Python 3.8+。

关键函数

  • clone_repo(repo_url: str) -> str
    • 基于仓库 URL 的哈希值创建一个确定性的临时目录。
    • 检查是否已经克隆了该仓库。
    • 如果尚未克隆,则克隆仓库。
    • 处理错误情况并清理。
    • 返回克隆仓库的路径。
  • get_directory_tree(path: str, prefix: str = "") -> str
    • 递归生成目录结构的树状表示。
    • 忽略 .git 目录。
    • 使用 Unicode 盒图字符创建视觉上的树结构表示。
    • 处理条目排序。
  • github_directory_structure(repo_url: str) -> str
    • 克隆仓库。
    • 生成目录树。
    • 在处理完成后清理临时仓库。
    • 返回树结构或错误消息。
  • github_read_important_files(repo_url: str, file_paths: List[str]) -> dict[str, str]
    • 克隆仓库。
    • 读取指定文件。
    • 返回文件路径到内容的字典映射。
    • 处理文件读取错误。
    • 清理临时仓库。

错误处理

在克隆或读取过程中处理常见 Git 和 I/O 错误,提供有意义的错误消息以帮助调试。

性能优化

  • 使用轻量级承诺(lightweight commits)以减少磁盘空间使用。
  • 实施垃圾收集机制以清理临时仓库。

📚 详细文档

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client