@npm_xiyuan/mcp-github-trending 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +527 -0
- package/README_CN.md +527 -0
- package/dist/github-api.js +83 -0
- package/dist/index.js +370 -0
- package/package.json +46 -0
package/README_CN.md
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
[English](./README.md) | 简体中文
|
|
2
|
+
|
|
3
|
+
# GitHub Trending MCP Server
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@npm_xiyuan/mcp-github-trending)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
[](https://modelcontextprotocol.io)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
|
|
10
|
+
一个基于 Model Context Protocol (MCP) 的服务器,为 AI 应用(如 Claude Code)提供实时访问 GitHub 热门仓库和开发者数据的能力。
|
|
11
|
+
|
|
12
|
+
## ✨ 核心特性
|
|
13
|
+
|
|
14
|
+
- 🚀 **实时数据** - 直接从 GitHub 获取最新的热门趋势
|
|
15
|
+
- 🔍 **智能搜索** - 支持关键词模糊匹配和语言过滤
|
|
16
|
+
- 📊 **详细统计** - 获取仓库的 stars、forks、topics 等完整信息
|
|
17
|
+
- 👥 **开发者追踪** - 追踪热门开发者及其代表作品
|
|
18
|
+
- ⚡ **轻量高效** - 基于 cheerio 的快速数据抓取
|
|
19
|
+
- 🔧 **零配置** - 安装即用,无需额外设置
|
|
20
|
+
- 🤖 **AI 原生** - 专为 Claude Code 等 AI 工具设计
|
|
21
|
+
|
|
22
|
+
## 🚀 快速开始
|
|
23
|
+
|
|
24
|
+
### 系统要求
|
|
25
|
+
|
|
26
|
+
- Node.js 18.0.0 或更高版本
|
|
27
|
+
- 可访问 github.com 的网络连接
|
|
28
|
+
|
|
29
|
+
### 安装
|
|
30
|
+
|
|
31
|
+
使用 npm 全局安装:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install -g @npm_xiyuan/mcp-github-trending
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
或使用 npx 直接运行(推荐):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx @npm_xiyuan/mcp-github-trending
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ⚙️ Claude Code 配置
|
|
44
|
+
|
|
45
|
+
### 配置位置
|
|
46
|
+
|
|
47
|
+
根据你使用的 Claude 客户端,配置文件位置不同:
|
|
48
|
+
|
|
49
|
+
| 客户端 | 配置文件路径 |
|
|
50
|
+
|--------|-------------|
|
|
51
|
+
| **Claude Desktop (macOS)** | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
52
|
+
| **Claude Desktop (Windows)** | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
53
|
+
| **Claude Code CLI** | `~/.claude/settings.json` |
|
|
54
|
+
|
|
55
|
+
### 基础配置
|
|
56
|
+
|
|
57
|
+
编辑配置文件,添加 MCP 服务器配置:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"github-trending": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": ["-y", "@npm_xiyuan/mcp-github-trending"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 配置说明
|
|
71
|
+
|
|
72
|
+
- **服务器名称**: `github-trending` 可自定义,用于在 Claude 中识别此服务
|
|
73
|
+
- **command**: 使用 `npx` 确保始终运行最新版本
|
|
74
|
+
- **args**:
|
|
75
|
+
- `-y`: 自动确认安装,避免交互式提示
|
|
76
|
+
- 包名: `@npm_xiyuan/mcp-github-trending`
|
|
77
|
+
|
|
78
|
+
### 验证配置
|
|
79
|
+
|
|
80
|
+
重启 Claude 客户端后,你可以通过以下方式验证配置是否成功:
|
|
81
|
+
|
|
82
|
+
1. 在 Claude 中询问:`"帮我查看 GitHub 今日热门项目"`
|
|
83
|
+
2. 如果配置成功,Claude 会自动调用 MCP 工具获取数据
|
|
84
|
+
|
|
85
|
+
## 📦 MCP 工具能力说明
|
|
86
|
+
|
|
87
|
+
本服务提供 9 个 MCP 工具,可在 Claude Code 中直接调用:
|
|
88
|
+
|
|
89
|
+
### 1. get_trending_repos - 获取热门仓库
|
|
90
|
+
|
|
91
|
+
**功能描述**: 获取 GitHub 上的热门仓库列表,支持按时间范围和编程语言筛选。
|
|
92
|
+
|
|
93
|
+
**参数说明**:
|
|
94
|
+
|
|
95
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
96
|
+
|------|------|------|--------|------|
|
|
97
|
+
| `since` | string | 否 | `"weekly"` | 时间范围:`"daily"` (今日)、`"weekly"` (本周)、`"monthly"` (本月) |
|
|
98
|
+
| `language` | string | 否 | - | 编程语言过滤,如 `"python"`, `"javascript"`, `"rust"` |
|
|
99
|
+
| `limit` | number | 否 | `10` | 返回结果数量,建议 1-25 |
|
|
100
|
+
|
|
101
|
+
**返回数据**:
|
|
102
|
+
```json
|
|
103
|
+
[
|
|
104
|
+
{
|
|
105
|
+
"name": "owner/repo-name",
|
|
106
|
+
"url": "https://github.com/owner/repo-name",
|
|
107
|
+
"description": "项目描述",
|
|
108
|
+
"stars": "1,234 stars today"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**使用场景**:
|
|
114
|
+
- 发现最新的热门开源项目
|
|
115
|
+
- 了解特定编程语言的流行趋势
|
|
116
|
+
- 学习和研究优秀代码库
|
|
117
|
+
|
|
118
|
+
### 2. get_trending_developers - 获取热门开发者
|
|
119
|
+
|
|
120
|
+
**功能描述**: 获取 GitHub 上的热门开发者列表及其代表作品。
|
|
121
|
+
|
|
122
|
+
**参数说明**:
|
|
123
|
+
|
|
124
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
125
|
+
|------|------|------|--------|------|
|
|
126
|
+
| `since` | string | 否 | `"weekly"` | 时间范围:`"daily"`, `"weekly"`, `"monthly"` |
|
|
127
|
+
| `language` | string | 否 | - | 编程语言过滤 |
|
|
128
|
+
| `limit` | number | 否 | `10` | 返回结果数量 |
|
|
129
|
+
|
|
130
|
+
**返回数据**:
|
|
131
|
+
```json
|
|
132
|
+
[
|
|
133
|
+
{
|
|
134
|
+
"name": "开发者名称",
|
|
135
|
+
"username": "github-username",
|
|
136
|
+
"url": "https://github.com/username",
|
|
137
|
+
"avatar": "头像URL",
|
|
138
|
+
"popularRepo": {
|
|
139
|
+
"name": "代表性仓库",
|
|
140
|
+
"description": "仓库描述",
|
|
141
|
+
"url": "仓库链接"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**使用场景**:
|
|
148
|
+
- 关注活跃的优秀开发者
|
|
149
|
+
- 发现某个领域的技术专家
|
|
150
|
+
- 寻找学习榜样和合作对象
|
|
151
|
+
|
|
152
|
+
### 3. search_trending - 搜索热门仓库
|
|
153
|
+
|
|
154
|
+
**功能描述**: 在热门仓库列表中按关键词搜索,支持名称和描述的模糊匹配。
|
|
155
|
+
|
|
156
|
+
**参数说明**:
|
|
157
|
+
|
|
158
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
159
|
+
|------|------|------|--------|------|
|
|
160
|
+
| `keyword` | string | **是** | - | 搜索关键词(不区分大小写) |
|
|
161
|
+
| `since` | string | 否 | `"weekly"` | 时间范围 |
|
|
162
|
+
| `language` | string | 否 | - | 编程语言过滤 |
|
|
163
|
+
|
|
164
|
+
**返回数据**: 与 `get_trending_repos` 相同的格式
|
|
165
|
+
|
|
166
|
+
**使用场景**:
|
|
167
|
+
- 快速找到特定技术栈的热门项目
|
|
168
|
+
- 搜索特定功能或领域的开源解决方案
|
|
169
|
+
- 精准定位感兴趣的项目类型
|
|
170
|
+
|
|
171
|
+
### 4. get_repo_details - 获取仓库详情
|
|
172
|
+
|
|
173
|
+
**功能描述**: 获取指定 GitHub 仓库的详细统计信息和元数据。
|
|
174
|
+
|
|
175
|
+
**参数说明**:
|
|
176
|
+
|
|
177
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
178
|
+
|------|------|------|--------|------|
|
|
179
|
+
| `owner` | string | **是** | - | 仓库所有者(用户名或组织名) |
|
|
180
|
+
| `repo` | string | **是** | - | 仓库名称 |
|
|
181
|
+
|
|
182
|
+
**返回数据**:
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"name": "仓库名称",
|
|
186
|
+
"fullName": "owner/repo",
|
|
187
|
+
"description": "仓库描述",
|
|
188
|
+
"url": "https://github.com/owner/repo",
|
|
189
|
+
"stars": 12345,
|
|
190
|
+
"forks": 678,
|
|
191
|
+
"watchers": 890,
|
|
192
|
+
"language": "JavaScript",
|
|
193
|
+
"topics": ["react", "typescript", "ui"],
|
|
194
|
+
"createdAt": "2023-01-01",
|
|
195
|
+
"updatedAt": "2024-06-05",
|
|
196
|
+
"license": "MIT"
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**使用场景**:
|
|
201
|
+
- 深入了解特定项目的详细信息
|
|
202
|
+
- 评估项目的活跃度和受欢迎程度
|
|
203
|
+
- 获取项目的技术栈和主题标签
|
|
204
|
+
|
|
205
|
+
### 5. analyze_repo - 项目综合分析
|
|
206
|
+
|
|
207
|
+
**功能描述**: 一次性获取 GitHub 项目的完整分析报告,包括 README、依赖、目录结构和最近提交。这是最强大的分析工具,适合快速了解陌生项目。
|
|
208
|
+
|
|
209
|
+
**参数说明**:
|
|
210
|
+
|
|
211
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
212
|
+
|------|------|------|------|
|
|
213
|
+
| `owner` | string | **是** | 仓库所有者 |
|
|
214
|
+
| `repo` | string | **是** | 仓库名称 |
|
|
215
|
+
|
|
216
|
+
**返回数据**:
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"basic": {
|
|
220
|
+
"fullName": "owner/repo",
|
|
221
|
+
"stars": 12345,
|
|
222
|
+
"language": "TypeScript",
|
|
223
|
+
"topics": ["react", "typescript"]
|
|
224
|
+
},
|
|
225
|
+
"readme": {
|
|
226
|
+
"content": "# Project Title\n...",
|
|
227
|
+
"size": 5432
|
|
228
|
+
},
|
|
229
|
+
"structure": {
|
|
230
|
+
"rootFiles": ["package.json", "README.md"],
|
|
231
|
+
"directories": ["src", "test", "docs"]
|
|
232
|
+
},
|
|
233
|
+
"dependencies": {
|
|
234
|
+
"detected": true,
|
|
235
|
+
"packageManager": "npm/yarn/pnpm",
|
|
236
|
+
"file": "package.json",
|
|
237
|
+
"content": "{...}"
|
|
238
|
+
},
|
|
239
|
+
"recentActivity": {
|
|
240
|
+
"commits": [...],
|
|
241
|
+
"lastCommitDate": "2024-06-05"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**使用场景**:
|
|
247
|
+
- 快速了解一个陌生项目的用途和技术栈
|
|
248
|
+
- 评估项目的活跃度和维护状态
|
|
249
|
+
- 获取项目完整的技术背景信息
|
|
250
|
+
|
|
251
|
+
### 6. get_repo_readme - 获取 README
|
|
252
|
+
|
|
253
|
+
**功能描述**: 获取 GitHub 仓库的 README.md 原始 Markdown 内容。
|
|
254
|
+
|
|
255
|
+
**参数说明**:
|
|
256
|
+
|
|
257
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
258
|
+
|------|------|------|------|
|
|
259
|
+
| `owner` | string | **是** | 仓库所有者 |
|
|
260
|
+
| `repo` | string | **是** | 仓库名称 |
|
|
261
|
+
|
|
262
|
+
**使用场景**:
|
|
263
|
+
- 阅读项目文档了解使用方法
|
|
264
|
+
- 提取项目介绍和功能说明
|
|
265
|
+
|
|
266
|
+
### 7. get_repo_file - 获取文件内容
|
|
267
|
+
|
|
268
|
+
**功能描述**: 获取 GitHub 仓库中指定文件的原始内容。
|
|
269
|
+
|
|
270
|
+
**参数说明**:
|
|
271
|
+
|
|
272
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
273
|
+
|------|------|------|------|
|
|
274
|
+
| `owner` | string | **是** | 仓库所有者 |
|
|
275
|
+
| `repo` | string | **是** | 仓库名称 |
|
|
276
|
+
| `path` | string | **是** | 文件路径,如 "package.json" |
|
|
277
|
+
|
|
278
|
+
**使用场景**:
|
|
279
|
+
- 查看配置文件(package.json, requirements.txt)
|
|
280
|
+
- 读取代码文件了解实现细节
|
|
281
|
+
|
|
282
|
+
### 8. get_repo_structure - 获取目录结构
|
|
283
|
+
|
|
284
|
+
**功能描述**: 获取 GitHub 仓库的目录和文件列表。
|
|
285
|
+
|
|
286
|
+
**参数说明**:
|
|
287
|
+
|
|
288
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
289
|
+
|------|------|------|--------|------|
|
|
290
|
+
| `owner` | string | **是** | - | 仓库所有者 |
|
|
291
|
+
| `repo` | string | **是** | - | 仓库名称 |
|
|
292
|
+
| `path` | string | 否 | `""` | 目录路径(空为根目录) |
|
|
293
|
+
|
|
294
|
+
**使用场景**:
|
|
295
|
+
- 了解项目的文件组织结构
|
|
296
|
+
- 浏览特定目录下的文件
|
|
297
|
+
|
|
298
|
+
### 9. get_repo_commits - 获取提交历史
|
|
299
|
+
|
|
300
|
+
**功能描述**: 获取 GitHub 仓库的最近提交记录。
|
|
301
|
+
|
|
302
|
+
**参数说明**:
|
|
303
|
+
|
|
304
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
305
|
+
|------|------|------|--------|------|
|
|
306
|
+
| `owner` | string | **是** | - | 仓库所有者 |
|
|
307
|
+
| `repo` | string | **是** | - | 仓库名称 |
|
|
308
|
+
| `limit` | number | 否 | `10` | 返回数量 |
|
|
309
|
+
|
|
310
|
+
**使用场景**:
|
|
311
|
+
- 了解项目的最近开发动态
|
|
312
|
+
- 查看项目的提交频率和活跃度
|
|
313
|
+
|
|
314
|
+
## 💡 使用示例
|
|
315
|
+
|
|
316
|
+
### 示例 1:查看今日热门项目
|
|
317
|
+
|
|
318
|
+
在 Claude Code 中询问:
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
帮我查看 GitHub 今日热门项目 top 10
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Claude 会自动调用 `get_trending_repos` 工具,返回今日最热门的 10 个项目。
|
|
325
|
+
|
|
326
|
+
### 示例 2:搜索特定技术栈
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
帮我找找最近有哪些热门的 Rust 项目
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Claude 会使用 `language: "rust"` 参数筛选 Rust 相关的热门项目。
|
|
333
|
+
|
|
334
|
+
### 示例 3:关键词搜索
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
搜索 GitHub 热门项目中关于 AI agent 的项目
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Claude 会调用 `search_trending` 工具,在热门列表中搜索包含 "AI agent" 关键词的项目。
|
|
341
|
+
|
|
342
|
+
### 示例 4:获取仓库详情
|
|
343
|
+
|
|
344
|
+
```
|
|
345
|
+
帮我查看 microsoft/vscode 这个仓库的详细信息
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Claude 会调用 `get_repo_details` 获取该仓库的 stars、forks、技术栈等完整信息。
|
|
349
|
+
|
|
350
|
+
### 示例 5:分析 GitHub 项目
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
帮我分析一下 https://github.com/microsoft/vscode 这个项目
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Claude 会调用 `analyze_repo` 工具,一次性返回项目的完整分析报告,包括:
|
|
357
|
+
- 项目基本信息(stars、语言、主题标签)
|
|
358
|
+
- README 内容
|
|
359
|
+
- 项目结构(根目录文件和主要目录)
|
|
360
|
+
- 依赖管理(package.json 等配置文件)
|
|
361
|
+
- 最近的提交记录
|
|
362
|
+
|
|
363
|
+
这是最强大和便捷的项目分析方式,适合快速了解陌生项目。
|
|
364
|
+
|
|
365
|
+
### 示例 6:查看热门开发者
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
帮我看看本周 GitHub 上的热门 Python 开发者
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Claude 会调用 `get_trending_developers` 工具,返回本周最活跃的 Python 开发者列表及其代表作品。
|
|
372
|
+
|
|
373
|
+
### 示例 7:读取项目 README
|
|
374
|
+
|
|
375
|
+
```
|
|
376
|
+
帮我读取 facebook/react 的 README 文档
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Claude 会调用 `get_repo_readme` 工具,获取 React 项目的完整 README.md 内容,方便了解项目的使用说明和功能介绍。
|
|
380
|
+
|
|
381
|
+
### 示例 8:查看配置文件
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
帮我查看 vercel/next.js 项目的 package.json 文件
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Claude 会调用 `get_repo_file` 工具,获取 Next.js 项目的 package.json 文件内容,可以了解项目的依赖和脚本配置。
|
|
388
|
+
|
|
389
|
+
### 示例 9:查看项目结构
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
帮我看看 nodejs/node 项目的根目录结构
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Claude 会调用 `get_repo_structure` 工具,返回 Node.js 项目的根目录文件和文件夹列表,帮助理解项目的组织架构。
|
|
396
|
+
|
|
397
|
+
### 示例 10:查看提交历史
|
|
398
|
+
|
|
399
|
+
```
|
|
400
|
+
帮我查看 denoland/deno 项目最近5次提交记录
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
Claude 会调用 `get_repo_commits` 工具,返回 Deno 项目最近5次提交的详细信息,包括提交者、提交时间和提交说明。
|
|
404
|
+
|
|
405
|
+
## 🎯 最佳实践
|
|
406
|
+
|
|
407
|
+
### 性能优化建议
|
|
408
|
+
|
|
409
|
+
1. **合理使用时间范围**:
|
|
410
|
+
- 日常浏览使用 `weekly` (本周)
|
|
411
|
+
- 快速了解最新动态使用 `daily` (今日)
|
|
412
|
+
- 长期趋势分析使用 `monthly` (本月)
|
|
413
|
+
|
|
414
|
+
2. **精准语言过滤**:
|
|
415
|
+
- 指定编程语言可大幅减少无关结果
|
|
416
|
+
- 支持的语言示例: `python`, `javascript`, `typescript`, `rust`, `go`, `java`
|
|
417
|
+
|
|
418
|
+
3. **控制返回数量**:
|
|
419
|
+
- 默认返回 10 条结果,可根据需求调整
|
|
420
|
+
- 建议不超过 25 条,避免过多数据影响响应速度
|
|
421
|
+
|
|
422
|
+
### 在 Claude Code 中的应用场景
|
|
423
|
+
|
|
424
|
+
- **技术选型**: 快速了解某个领域当前最流行的技术方案
|
|
425
|
+
- **学习资源**: 发现高质量的开源项目用于学习
|
|
426
|
+
- **竞品分析**: 追踪同类产品的开源实现
|
|
427
|
+
- **技术趋势**: 观察新兴技术和编程语言的热度变化
|
|
428
|
+
- **开发者关系**: 寻找优秀的开发者和潜在的合作伙伴
|
|
429
|
+
|
|
430
|
+
## 🔧 故障排除
|
|
431
|
+
|
|
432
|
+
### 常见问题
|
|
433
|
+
|
|
434
|
+
**Q: Claude 无法识别 MCP 工具?**
|
|
435
|
+
|
|
436
|
+
A: 请检查:
|
|
437
|
+
1. 配置文件路径是否正确
|
|
438
|
+
2. JSON 格式是否有效(使用 JSON 验证器检查)
|
|
439
|
+
3. 是否已重启 Claude 客户端
|
|
440
|
+
4. 使用 `npx -y @npm_xiyuan/mcp-github-trending` 确保包可正常运行
|
|
441
|
+
|
|
442
|
+
**Q: 返回数据为空或不完整?**
|
|
443
|
+
|
|
444
|
+
A: 可能原因:
|
|
445
|
+
1. GitHub trending 页面结构变化(等待包更新)
|
|
446
|
+
2. 网络连接问题(检查是否能访问 github.com)
|
|
447
|
+
3. 选择的语言或时间范围没有热门项目
|
|
448
|
+
|
|
449
|
+
**Q: 如何更新到最新版本?**
|
|
450
|
+
|
|
451
|
+
A: 使用 npx 会自动使用最新版本。如果全局安装,运行:
|
|
452
|
+
```bash
|
|
453
|
+
npm update -g @npm_xiyuan/mcp-github-trending
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
## 🛠️ 开发指南
|
|
457
|
+
|
|
458
|
+
### 本地开发
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
# 克隆项目
|
|
462
|
+
git clone https://github.com/jiyi1990118/mcp-github-trending.git
|
|
463
|
+
cd mcp-github-trending
|
|
464
|
+
|
|
465
|
+
# 安装依赖
|
|
466
|
+
npm install
|
|
467
|
+
|
|
468
|
+
# 构建项目
|
|
469
|
+
npm run build
|
|
470
|
+
|
|
471
|
+
# 本地测试
|
|
472
|
+
npm start
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### 目录结构
|
|
476
|
+
|
|
477
|
+
```
|
|
478
|
+
nodejs/
|
|
479
|
+
├── src/
|
|
480
|
+
│ ├── index.ts # MCP 服务器入口
|
|
481
|
+
│ ├── tools.ts # 工具定义
|
|
482
|
+
│ └── scraper.ts # GitHub 数据抓取逻辑
|
|
483
|
+
├── package.json
|
|
484
|
+
└── tsconfig.json
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### 技术栈
|
|
488
|
+
|
|
489
|
+
- **MCP SDK**: `@modelcontextprotocol/sdk` - Model Context Protocol 实现
|
|
490
|
+
- **HTTP 客户端**: `node-fetch` - 发起 HTTP 请求
|
|
491
|
+
- **HTML 解析**: `cheerio` - 轻量级的服务器端 jQuery 实现
|
|
492
|
+
- **TypeScript**: 类型安全的 JavaScript 超集
|
|
493
|
+
|
|
494
|
+
### 贡献指南
|
|
495
|
+
|
|
496
|
+
欢迎提交 Issue 和 Pull Request!
|
|
497
|
+
|
|
498
|
+
1. Fork 本仓库
|
|
499
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
500
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
501
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
|
502
|
+
5. 开启 Pull Request
|
|
503
|
+
|
|
504
|
+
## 📄 许可证
|
|
505
|
+
|
|
506
|
+
本项目基于 MIT 许可证开源 - 查看 [LICENSE](./LICENSE) 文件了解详情。
|
|
507
|
+
|
|
508
|
+
## 🔗 相关链接
|
|
509
|
+
|
|
510
|
+
- [GitHub 仓库](https://github.com/jiyi1990118/mcp-github-trending)
|
|
511
|
+
- [npm 包地址](https://www.npmjs.com/package/@npm_xiyuan/mcp-github-trending)
|
|
512
|
+
- [Model Context Protocol 文档](https://modelcontextprotocol.io)
|
|
513
|
+
- [Claude Desktop 下载](https://claude.ai/download)
|
|
514
|
+
- [GitHub Trending 页面](https://github.com/trending)
|
|
515
|
+
|
|
516
|
+
## 📮 反馈与支持
|
|
517
|
+
|
|
518
|
+
如有问题或建议,欢迎通过以下方式联系:
|
|
519
|
+
|
|
520
|
+
- 提交 GitHub Issue
|
|
521
|
+
- 发起 Pull Request
|
|
522
|
+
- 在 npm 页面留言
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
526
|
+
**注意**: 本项目通过爬取 GitHub Trending 页面获取数据,非官方 API。如 GitHub 调整页面结构可能影响功能,请及时更新到最新版本。
|
|
527
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
export async function fetchRepoReadme(owner, repo) {
|
|
3
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/readme`;
|
|
4
|
+
const response = await fetch(url, {
|
|
5
|
+
headers: { 'Accept': 'application/vnd.github.raw' }
|
|
6
|
+
});
|
|
7
|
+
if (!response.ok)
|
|
8
|
+
throw new Error(`README not found: ${response.status}`);
|
|
9
|
+
return await response.text();
|
|
10
|
+
}
|
|
11
|
+
export async function fetchRepoFile(owner, repo, path) {
|
|
12
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
headers: { 'Accept': 'application/vnd.github.raw' }
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok)
|
|
17
|
+
throw new Error(`File not found: ${path}`);
|
|
18
|
+
return await response.text();
|
|
19
|
+
}
|
|
20
|
+
export async function fetchRepoStructure(owner, repo, path = '') {
|
|
21
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
|
|
22
|
+
const response = await fetch(url, {
|
|
23
|
+
headers: { 'Accept': 'application/json' }
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
throw new Error(`Path not found: ${path}`);
|
|
27
|
+
return await response.json();
|
|
28
|
+
}
|
|
29
|
+
export async function fetchRepoCommits(owner, repo, limit = 10) {
|
|
30
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/commits?per_page=${limit}`;
|
|
31
|
+
const response = await fetch(url);
|
|
32
|
+
if (!response.ok)
|
|
33
|
+
throw new Error('Failed to fetch commits');
|
|
34
|
+
return (await response.json());
|
|
35
|
+
}
|
|
36
|
+
export async function analyzeRepo(owner, repo, fetchRepoDetails) {
|
|
37
|
+
const [details, readme] = await Promise.all([
|
|
38
|
+
fetchRepoDetails(owner, repo),
|
|
39
|
+
fetchRepoReadme(owner, repo).catch(() => null)
|
|
40
|
+
]);
|
|
41
|
+
const structure = await fetchRepoStructure(owner, repo);
|
|
42
|
+
const rootFiles = structure.filter(item => item.type === 'file').map(item => item.name);
|
|
43
|
+
const directories = structure.filter(item => item.type === 'dir').map(item => item.name);
|
|
44
|
+
const depFiles = ['package.json', 'requirements.txt', 'Cargo.toml', 'go.mod', 'pom.xml'];
|
|
45
|
+
const packageManagerMap = {
|
|
46
|
+
'package.json': 'npm/yarn/pnpm',
|
|
47
|
+
'requirements.txt': 'pip',
|
|
48
|
+
'Cargo.toml': 'cargo',
|
|
49
|
+
'go.mod': 'go modules',
|
|
50
|
+
'pom.xml': 'maven'
|
|
51
|
+
};
|
|
52
|
+
let dependencies = { detected: false };
|
|
53
|
+
for (const file of depFiles) {
|
|
54
|
+
if (rootFiles.includes(file)) {
|
|
55
|
+
const content = await fetchRepoFile(owner, repo, file).catch(() => null);
|
|
56
|
+
if (content) {
|
|
57
|
+
dependencies = {
|
|
58
|
+
detected: true,
|
|
59
|
+
packageManager: packageManagerMap[file] || 'unknown',
|
|
60
|
+
file,
|
|
61
|
+
content
|
|
62
|
+
};
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const commits = await fetchRepoCommits(owner, repo, 10);
|
|
68
|
+
return {
|
|
69
|
+
basic: details,
|
|
70
|
+
readme: readme ? { content: readme, size: readme.length } : null,
|
|
71
|
+
structure: { rootFiles, directories },
|
|
72
|
+
dependencies,
|
|
73
|
+
recentActivity: {
|
|
74
|
+
commits: commits.map((c) => ({
|
|
75
|
+
sha: c.sha?.substring(0, 7) || '',
|
|
76
|
+
message: c.commit?.message?.split('\n')[0] || '',
|
|
77
|
+
author: c.commit?.author?.name || '',
|
|
78
|
+
date: c.commit?.author?.date || ''
|
|
79
|
+
})),
|
|
80
|
+
lastCommitDate: commits[0]?.commit?.author?.date || null
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|