MCP Git 仓库导入工具 是一个模型上下文协议(MCP)服务器,旨在帮助读取 GitHub 仓库结构和重要文件,为开发者提供便利。它受 gitingest 启发而开发。
你可以按照以下方式对工具进行配置:
{
"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 仓库操作。clone_repo(repo_url: str) -> str:
get_directory_tree(path: str, prefix: str = "") -> str:
.git 目录。github_directory_structure(repo_url: str) -> str:
github_read_important_files(repo_url: str, file_paths: List[str]) -> dict[str, str]:
在克隆或读取过程中处理常见 Git 和 I/O 错误,提供有意义的错误消息以帮助调试。