RepoInsight MCP
用于GitHub存储库分析的本地第一台MCP服务器
RepoInsight MCP是一个基于Python的模型上下文协议(MCP)服务器,使AI代理能够深入了解公共GitHub存储库。它提供了用于搜索文档、探索项目结构和读取源代码文件的结构化工具。
______________________________________________________________________
🚀 快速入门(3个步骤)
步骤1:安装依赖项
# Navigate to project folder
cd C:\DEKSTOP\MCP\repo_insight
# Install required packages
pip install -r requirements.txt步骤2:配置Claude桌面
先找到你的Python路径:
# Windows
where python
# macOS/Linux
which python3编辑配置文件:
- 视窗:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
粘贴此配置 (更新路径以匹配您的系统):
Windows示例:
{
"mcpServers": {
"repoinsight": {
"command": "C:\\laragon\\bin\\python\\python-3.13\\python.exe",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "C:\\DEKSTOP\\MCP\\repo_insight",
"env": {
"PYTHONPATH": "C:\\DEKSTOP\\MCP\\repo_insight\\src"
}
}
}
}macOS/Linux示例:
{
"mcpServers": {
"repoinsight": {
"command": "/usr/local/bin/python3",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "/path/to/repo_insight",
"env": {
"PYTHONPATH": "/path/to/repo_insight/src"
}
}
}
}重要提示:
- 使用 完整Python路径 (从
where python或which python3) cwd必须指向项目根(其中src/文件夹存在)PYTHONPATH必须指向src项目中的文件夹- 在Windows上,使用双反斜杠
\\在路径
步骤3:重新启动克劳德桌面
- 完全退出克劳德桌面 (文件→ 退出,而不仅仅是关闭窗口)
- 等待5秒
- 重新启动克劳德桌面
- 测试:“显示fastapi/fastapi存储库的结构”
✅ 完成! 您的AI代理现在可以分析任何GitHub存储库!
______________________________________________________________________
✅ 验证它是否正常工作
在Claude Desktop中,您应该看到:
- 显示MCP服务器已加载的小图标或指示器
- 当你要求分析一个仓库时,Claude会自动使用这些工具
测试命令:
"Analyze the structure of django/django and show me the main components"如果它有效,你会看到克劳德使用 get_repo_structure 工具并显示结果!
______________________________________________________________________
🎯 你能做什么
配置后,询问您的AI代理以下问题:
"Analyze the FastAPI repository structure"
→ Uses: get_repo_structure
"Search the Django repo for authentication documentation"
→ Uses: search_doc
"Read the main.py file from fastapi/fastapi"
→ Uses: read_file
"Debug the login issue in owner/repo by checking auth files"
→ Uses: All 3 tools together______________________________________________________________________
🔑 GitHub令牌(可选)
无令牌:60个请求/小时(适合测试)\ 带令牌:5000次请求/小时(增加83倍-更适合频繁使用)
如何创建令牌:
- 首选https://github.com/settings/tokens
- 点击 “生成新令牌(经典)”
- 给它起个名字:
RepoInsight MCP - 选择NO范围 (取消选中所有复选框)
- ✅ 我们只需要公共存储库访问权限 - ✅ 公共存储库不需要权限 - ✅ 使用最少的权限更安全
- 点击 “生成令牌”
- 复制令牌(以开头
ghp_...)
将令牌添加到配置:
更新您的Claude Desktop配置以包含令牌:
{
"mcpServers": {
"repoinsight": {
"command": "C:\\laragon\\bin\\python\\python-3.13\\python.exe",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "C:\\DEKSTOP\\MCP\\repo_insight",
"env": {
"PYTHONPATH": "C:\\DEKSTOP\\MCP\\repo_insight\\src",
"GITHUB_TOKEN": "ghp_your_token_here"
}
}
}
}添加令牌后,记得重新启动Claude Desktop!
______________________________________________________________________
特性
- 本地优先:本地缓存的所有数据,最少API调用
- 安全:只读访问、路径验证、不执行代码
- 快速:SQLite FTS5搜索,主动缓存
- 符合MCP标准:与Claude Desktop、Cline和其他MCP客户端配合使用
- 确定性的:稳定的输出,用于可靠的AI推理
建筑
RepoInsight MCP
├── MCP Protocol Layer (stdio/HTTP)
├── Tool Handlers (search_doc, get_repo_structure, read_file)
├── GitHub API Client
├── Repository Cache
├── Search Index (SQLite FTS5)
└── File Reader (with security validation)需求
- Python 3.10或更高版本
- Git已安装并在PATH中可用
- (可选)用于更高API速率限制的GitHub个人访问令牌
安装
来源
# Clone or navigate to repository
cd repo_insight
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .使用pip
pip install -e .用法
运行服务器
标准模式(建议MCP客户端使用)
# Using installed command
repoinsight-mcp
# Or with Python module
python -m repoinsight_mcp.main
# With GitHub token for higher rate limits
export GITHUB_TOKEN=your_token_here
repoinsight-mcpMCP客户端配置
克劳德桌面(推荐)
视窗: %APPDATA%\Claude\claude_desktop_config.json\ macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
完整的工作配置:
{
"mcpServers": {
"repoinsight": {
"command": "C:\\path\\to\\python.exe",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "C:\\path\\to\\repo_insight",
"env": {
"PYTHONPATH": "C:\\path\\to\\repo_insight\\src"
}
}
}
}使用GitHub代币(5000需求/小时):
{
"mcpServers": {
"repoinsight": {
"command": "C:\\path\\to\\python.exe",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "C:\\path\\to\\repo_insight",
"env": {
"PYTHONPATH": "C:\\path\\to\\repo_insight\\src",
"GITHUB_TOKEN": "ghp_your_token_here"
}
}
}
}寻找你的路径:
# Python path
where python # Windows
which python3 # macOS/Linux
# Project path - use absolute path where you cloned the projectCline(VS代码扩展)
添加到临床MCP设置:
{
"repoinsight": {
"command": "repoinsight-mcp",
"args": [],
"env": {
"GITHUB_TOKEN": "your_token_here"
}
}
}MCP工具
RepoInsight提供 4个强大的工具 使AI代理能够分析、检查、调试和执行GitHub存储库上的任何任务:
1.get_repo_summary
获取GitHub存储库的全面摘要,包括元数据、统计数据、最近的活动、主要贡献者和主要文档。
🎯 AI代理用例:
- 在深入分析之前快速浏览存储库
- 了解存储库流行度和活动级别
- 获取README摘要,无需阅读完整文件
- 查看最新问题和PR概览
- 确定使用的主要编程语言
输入:
{
"repository": "owner/repo"
}输出:
{
"repository": {
"name": "owner/repo",
"description": "...",
"stars": 1234,
"forks": 567,
"language": "Python",
"default_branch": "main",
"updated_at": "2024-01-15T10:30:00Z"
},
"readme_summary": "First 500 characters of README...",
"recent_issues": [...],
"recent_pull_requests": [...],
"top_contributors": [...],
"languages": {
"Python": 45,
"JavaScript": 30
},
"total_files": 123
}2.search_doc
搜索与GitHub存储库对应的知识文档,快速了解存储库知识、新闻、最新问题、PR和贡献者。
🎯 AI代理用例:
- 快速了解存储库的功能
- 查找功能的相关文档
- 回顾最近的问题和讨论
- 确定积极的贡献者和维护者
- 搜索特定主题或实现
输入:
{
"repository": "owner/repo",
"query": "authentication flow",
"limit": 10
}输出:
{
"repository": {
"name": "owner/repo",
"description": "...",
"stars": 1234,
"language": "Python"
},
"documents": [...],
"issues": [...],
"pull_requests": [...],
"contributors": [...]
}3.get_repo_structure
获取GitHub仓库的目录结构和文件列表,了解项目模块拆分和目录组织。
🎯 AI代理用例:
- 了解整体架构
- 定位特定模块或组件
- 分析项目组织模式
- 查找配置文件
- 映射模块之间的依赖关系
- 高效地浏览大型代码库
输入:
{
"repository": "owner/repo",
"path": "",
"depth": 4
}输出:
{
"root": "/",
"structure": [...],
"stats": {
"total_files": 123,
"languages": {
"Python": 45,
"JavaScript": 30
}
}
}4.read_file
阅读GitHub存储库中指定文件的完整代码内容,深入分析文件代码的实现细节。
🎯 AI代理用例:
- 调试代码问题
- 分析实施细节
- 审查代码质量
- 理解算法和逻辑
- 检查安全漏洞
- 提取API签名
- 学习编码模式
输入:
{
"repository": "owner/repo",
"path": "src/main.py"
}输出:
{
"path": "src/main.py",
"language": "Python",
"size": 1234,
"encoding": "utf-8",
"content": "..."
}______________________________________________________________________
🤖 AI代理工作流示例
- 概述 -使用
get_repo_summary快速获取摘要 - 发现 -使用
search_doc了解存储库 - 导航 -使用
get_repo_structure查找相关文件 - 分析 -使用
read_file检查实施细节 - 调试 -读取多个文件以跟踪错误
- 审查 -检查代码质量和模式
配置
环境变量
GITHUB_TOKEN:GitHub个人访问令牌(可选,增加速率限制)
缓存位置
存储库缓存在:
- Linux/macOS:
~/.repoinsight/repos/ - 视窗:
%USERPROFILE%\.repoinsight\repos\
缓存TTL:24小时(可在中配置 config.py)
文件大小限制
- 最大文件大小:1MB
- 最大树深:10层
安全
RepoInsight MCP的设计优先考虑安全性:
- 只读:无文件修改或代码执行
- 路径验证:阻止路径遍历尝试
- 大小限制:防止内存耗尽
- 二进制检测:拒绝二进制文件
- 本地优先:没有数据发送到外部服务(除了GitHub API)
演出
- 存储库索引:\<60秒(中等存储库)
- 缓存搜索:\<500ms
- 文件读取时间:\<200ms
项目结构
repo_insight/
├── src/
│ └── repoinsight_mcp/
│ ├── __init__.py
│ ├── main.py # Entry point
│ ├── server.py # MCP server
│ ├── handlers.py # Tool handlers
│ ├── github_client.py # GitHub API
│ ├── cache.py # Repository caching
│ ├── search.py # Search & indexing
│ ├── file_reader.py # File reading
│ ├── models.py # Data models
│ ├── config.py # Configuration
│ └── exceptions.py # Custom exceptions
├── AGENTS.md # Agent guidelines
├── repo_insight_mcp_prd.md # Product requirements
├── pyproject.toml
├── requirements.txt
└── README.md发展
运行测试
# Install dev dependencies
pip install -e ".[dev]"
# Run tests (when implemented)
pytest代码格式化
black src/类型检查
mypy src/故障排除
常见问题
1.MCP错误-32000:连接关闭
原因:服务器启动失败
解决:
A.使用完整的Python路径
{
"mcpServers": {
"repoinsight": {
"command": "C:\\Users\\YourName\\AppData\\Local\\Programs\\Python\\Python313\\python.exe",
"args": ["-m", "repoinsight_mcp.main"],
"cwd": "C:\\DEKSTOP\\MCP\\repo_insight",
"env": {
"PYTHONPATH": "C:\\DEKSTOP\\MCP\\repo_insight\\src"
}
}
}
}找到你的Python路径:
where python # Windows
which python3 # macOS/LinuxB.验证依赖关系
cd C:\DEKSTOP\MCP\repo_insight
pip install -r requirements.txtC.手动测试服务器
cd C:\DEKSTOP\MCP\repo_insight
set PYTHONPATH=C:\DEKSTOP\MCP\repo_insight\src
python -m repoinsight_mcp.main如果这有效,那么你的路径是正确的。
______________________________________________________________________
2.协议版本错误
如果您看到“不支持服务器的协议版本”,则代码已更新为使用协议版本 2024-11-05。只需重新启动Claude Desktop。
______________________________________________________________________
3.工具不出现
检查:
- 配置文件位于正确的位置
- JSON语法有效(没有缺少逗号/大括号)
- 路径使用双反斜杠
\\在Windows上 - Claude Desktop已完全退出并重新启动(不仅仅是关闭窗口)
验证配置位置:
# Windows - should open the folder
explorer %APPDATA%\Claude
# macOS
open ~/Library/Application\ Support/Claude/---速率限制
如果您遇到GitHub API速率限制:
- 创建个人访问令牌:https://github.com/settings/tokens
- 选择NO范围 (公共仓库不需要权限)
- 添加到配置中(请参阅上面的GitHub Token部分)
- 重新启动克劳德桌面
缓存问题
清除缓存:
# Windows
rmdir /s /q %USERPROFILE%\.repoinsight
# macOS/Linux
rm -rf ~/.repoinsight/repos/导入错误
确保安装了依赖项:
cd C:\DEKSTOP\MCP\repo_insight
pip install -r requirements.txt未来的增强功能
- 基于AST的符号导航
- 语义嵌入搜索
- 私有存储库支持
- 语言服务器协议集成
- HTTP/SSE传输模式
许可证
\[在此处添加您的许可证\]
贡献
欢迎投稿!请确保:
- 代码遵循AGENTS.md指南
- 遵守所有安全规则
- 包括类型提示
- 测试通过(实施时)
作者
项目作者
______________________________________________________________________
内置于❤️ 对于AI代理
