使用说明
🐙 GitHub MCP服务器
一个强大的 模型上下文协议(MCP) 服务器,使AI助手能够轻松分析和读取GitHub存储库。非常适合代码分析、存储库探索和理解项目结构。
✨ 特性
🔍 存储库结构分析
- 完成目录遍历 具有可配置的深度
- 文件类型分布 分析与统计
- 项目架构见解 具有框架检测功能
- 重要文件检测 (README、package.json、Dockerfile等)
- 可视化树形结构 代表
- 大小分析 以及文件计数
📖 文件内容读取
- 多格式支持 (UTF-8、Base64、Raw)
- 语法突出显示 适用于30多种编程语言
- 代码分析 具有函数/类计数功能
- 模式检测 (TODO注释、async/await等)
- 智能内容截断 对于大文件
- 二进制文件处理 使用适当的编码
🚀 高性能
- 速率限制优化 支持GitHub代币
- 分行具体分析 (主要、发展、特色分支)
- 错误处理 有详细的故障排除
- 会话管理 用于高效使用API
- 流式HTTP 现代人工智能客户端的运输
🛠️ 安装
快速开始
npm install -g @xingyuchen/github-mcp-server
来源
git clone https://github.com/guangxiangdebizi/github-mcp-server.git
cd github-mcp-server
npm install
npm run build
⚙️ 配置
环境设置
-
复制环境模板:
cp .env.example .env -
配置您的设置:
# GitHub Personal Access Token (recommended for higher rate limits) GITHUB_TOKEN=your_github_token_here # Server Configuration PORT=3000 # Optional: Default repository DEFAULT_REPO=owner/repository
GitHub令牌设置
为了获得最佳性能和访问私有存储库:
- 首选 GitHub设置>开发者设置>个人访问令牌
- 使用生成新令牌
repo范围 - 将其添加到您的
.env文件
🚀 用法
启动服务器
# Production mode
npm start
# Development mode
npm run dev
# HTTP mode (recommended)
npm run start:http
服务器将在以下时间启动 http://localhost:3000 MCP端点位于 /mcp.
客户端配置
添加到AI客户端的MCP配置中:
{
"mcpServers": {
"github-analyzer": {
"type": "streamableHttp",
"url": "http://localhost:3000/mcp",
"timeout": 600
}
}
}
🔧 可用工具
1. analyze_repository_structure
分析GitHub存储库的完整结构和架构。
参数:
owner(必填):存储库所有者/组织repo(必填):存储库名称path(可选):要分析的特定目录branch(可选):分支名称(默认:main)max_depth(可选):最大遍历深度(1-5,默认值:3)
例子:
{
"owner": "microsoft",
"repo": "vscode",
"branch": "main",
"max_depth": 3
}
2. read_repository_file
从GitHub存储库中读取并分析特定文件的内容。
参数:
owner(必填):存储库所有者/组织repo(必填):存储库名称path(必需):存储库中的文件路径branch(可选):分支名称(默认:main)encoding(可选):文件编码(utf8/base64/raw,默认:utf8)max_size(可选):最大文件大小(以字节为单位)(默认值:1MB,最大值:5MB)
例子:
{
"owner": "microsoft",
"repo": "vscode",
"path": "src/vs/code/electron-main/main.ts",
"branch": "main"
}
📊 输出示例
存储库结构分析
# 📊 Repository Structure Analysis
## 📋 Repository Information
- **Repository:** microsoft/vscode
- **Description:** Visual Studio Code
- **Language:** TypeScript
- **Stars:** 150,000 ⭐
- **Forks:** 25,000 🍴
## 📁 Directory Structure
📁 src/
📁 vs/
📄 main.ts (15.2 KB)
📁 workbench/
📄 workbench.main.ts (8.5 KB)
## 📈 Statistics
- **Total Files:** 12,450
- **Total Directories:** 1,200
- **Total Size:** 145.2 MB
## 🏗️ Project Architecture Insights
🟨 **TypeScript Project** - Modern web development stack detected
📦 **Node.js Ecosystem** - Uses npm package management
🐳 **Containerized** - Docker deployment ready
文件内容分析
# 📄 File Content Analysis
## 📋 File Information
- **Repository:** microsoft/vscode
- **File Path:** `src/main.ts`
- **Branch:** main
## 📊 Content Analysis
**File Type:** TypeScript
**Size:** 15.2 KB
**Lines:** 450
**Functions:** 12
**Classes:** 3
**Imports:** 25
## 📝 File Content
```typescript
import { app, BrowserWindow } from 'electron';
// ... (file content with syntax highlighting)
🔍 健康检查
监控服务器状态:
curl http://localhost:3000/health
答复:
{
"status": "healthy",
"transport": "streamable-http",
"activeSessions": 2,
"serverInfo": {
"name": "GitHub-MCP",
"version": "1.0.0"
}
}
🤝 贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
📝 许可证
此项目根据Apache许可证2.0获得许可-请参阅 许可证 文件以获取详细信息。
👨💻 作者
陈兴宇
🙏 致谢
- 与 模型上下文协议SDK
- 由...驱动 GitHub REST API
- 受更好的AI存储库集成需求的启发
⭐ Star this repository if you find it helpful! ⭐
