gopeed-mcp-server 0.1.0__tar.gz
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.
- gopeed_mcp_server-0.1.0/LICENSE +21 -0
- gopeed_mcp_server-0.1.0/PKG-INFO +238 -0
- gopeed_mcp_server-0.1.0/README.md +219 -0
- gopeed_mcp_server-0.1.0/config.py +139 -0
- gopeed_mcp_server-0.1.0/gopeed_client.py +347 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/PKG-INFO +238 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/SOURCES.txt +12 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/dependency_links.txt +1 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/entry_points.txt +2 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/requires.txt +2 -0
- gopeed_mcp_server-0.1.0/gopeed_mcp_server.egg-info/top_level.txt +3 -0
- gopeed_mcp_server-0.1.0/pyproject.toml +33 -0
- gopeed_mcp_server-0.1.0/server.py +238 -0
- gopeed_mcp_server-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gopeed-mcp-server contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gopeed-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server to control the Gopeed download manager from VS Code Copilot Chat
|
|
5
|
+
Author: Panda-Young
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Panda-Young/gopeed-mcp-server
|
|
8
|
+
Project-URL: Repository, https://github.com/Panda-Young/gopeed-mcp-server
|
|
9
|
+
Project-URL: Issues, https://github.com/Panda-Young/gopeed-mcp-server/issues
|
|
10
|
+
Keywords: mcp,gopeed,download,copilot,vscode
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: mcp<2.0.0,>=1.0.0
|
|
17
|
+
Requires-Dist: httpx>=0.27.0
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Gopeed MCP Server
|
|
21
|
+
|
|
22
|
+
一个基于 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 的 Server,让你能在 VS Code Copilot Chat 中通过自然语言控制 [Gopeed](https://github.com/GopeedLab/gopeed) 下载管理器。
|
|
23
|
+
|
|
24
|
+
> **关于 Gopeed**:本项目的被控对象是开源下载管理器 [Gopeed](https://github.com/GopeedLab/gopeed)(由 `GopeedLab` 维护,采用 [GPL-3.0](https://github.com/GopeedLab/gopeed/blob/main/LICENSE) 许可证)。本 Server 仅通过 Gopeed 公开的 **REST API** 与之通信,不修改、不嵌入其任何源代码,因此本仓库以 MIT 许可证独立发布。使用前请先安装并运行 Gopeed 本体。
|
|
25
|
+
|
|
26
|
+
## 功能介绍
|
|
27
|
+
|
|
28
|
+
本 MCP Server 封装了 Gopeed 的 REST API,提供以下 8 个工具:
|
|
29
|
+
|
|
30
|
+
| 工具 | 说明 |
|
|
31
|
+
|------|------|
|
|
32
|
+
| `create_download_task` | 创建下载任务,支持自定义文件名和并发连接数 |
|
|
33
|
+
| `list_tasks` | 列出所有下载任务,可按状态过滤 |
|
|
34
|
+
| `get_task_detail` | 获取单个任务的详细信息 |
|
|
35
|
+
| `pause_task` | 暂停指定任务 |
|
|
36
|
+
| `resume_task` | 恢复(继续)指定任务 |
|
|
37
|
+
| `delete_task` | 删除任务,可选同时删除已下载文件 |
|
|
38
|
+
| `get_config` | 获取 Gopeed 当前配置(下载目录、连接数、代理等) |
|
|
39
|
+
| `update_config` | 更新 Gopeed 配置(只传需要修改的字段) |
|
|
40
|
+
|
|
41
|
+
## 环境要求
|
|
42
|
+
|
|
43
|
+
- Python 3.10+
|
|
44
|
+
- Gopeed 已安装并运行(API 端口每次启动随机分配,无需手动指定)
|
|
45
|
+
- VS Code 安装了 GitHub Copilot Chat 扩展
|
|
46
|
+
|
|
47
|
+
## 安装步骤
|
|
48
|
+
|
|
49
|
+
1. 进入项目目录:
|
|
50
|
+
```bash
|
|
51
|
+
cd gopeed-mcp-server
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
2. (推荐)创建虚拟环境:
|
|
55
|
+
```bash
|
|
56
|
+
python -m venv .venv
|
|
57
|
+
# Windows
|
|
58
|
+
.venv\Scripts\activate
|
|
59
|
+
# macOS / Linux
|
|
60
|
+
source .venv/bin/activate
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
3. 安装依赖(二选一):
|
|
64
|
+
|
|
65
|
+
- 方式 A:从源码安装依赖
|
|
66
|
+
```bash
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- 方式 B:作为 Python 包安装(推荐,可用于 `uvx` 一键启动)
|
|
71
|
+
```bash
|
|
72
|
+
pip install .
|
|
73
|
+
# 或发布后: pip install gopeed-mcp-server
|
|
74
|
+
```
|
|
75
|
+
安装后会得到 `gopeed-mcp-server` 命令,可用 `uvx gopeed-mcp-server` 直接启动。
|
|
76
|
+
|
|
77
|
+
4. (可选)配置环境变量。复制 `.env.example` 为 `.env` 并按需修改:
|
|
78
|
+
```bash
|
|
79
|
+
copy .env.example .env
|
|
80
|
+
```
|
|
81
|
+
可用环境变量:
|
|
82
|
+
- `GOPEED_API_URL`:Gopeed API 地址。**推荐留空端口**(默认 `http://127.0.0.1/api/v1`),server 会自动发现 Gopeed 当前端口(Gopeed 每次重启都会随机换端口,自动发现可免去手动改配置)。仅在确需固定时才写 `http://127.0.0.1:<端口>/api/v1`
|
|
83
|
+
- `GOPEED_API_TOKEN`:API 令牌(可选,Gopeed 配置了令牌时需要)
|
|
84
|
+
- `GOPEED_TIMEOUT`:请求超时秒数,默认 `10`
|
|
85
|
+
|
|
86
|
+
## VS Code Copilot Chat 配置方法
|
|
87
|
+
|
|
88
|
+
**方式一:从 MCP Gallery 安装(推荐,已上架后)**
|
|
89
|
+
|
|
90
|
+
1. 打开 Extensions 视图(`Ctrl+Shift+X`),搜索 `@mcp gopeed`。
|
|
91
|
+
2. 选择 **Install** 安装到用户配置,按提示信任并启动即可。
|
|
92
|
+
|
|
93
|
+
**方式二:手动配置 `mcp.json`**
|
|
94
|
+
|
|
95
|
+
VS Code 1.99+ 使用专用的 `mcp.json`(而不是 `settings.json` 的 `mcpServers` 字段)。
|
|
96
|
+
|
|
97
|
+
1. 按 `Ctrl+Shift+P`,运行 **`MCP: Open User Configuration`**(或在工作区创建 `.vscode/mcp.json`)。
|
|
98
|
+
2. 添加如下配置(使用 `uvx` 启动,无需本地路径):
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"servers": {
|
|
103
|
+
"gopeed": {
|
|
104
|
+
"command": "uvx",
|
|
105
|
+
"args": ["gopeed-mcp-server"],
|
|
106
|
+
"env": {
|
|
107
|
+
"GOPEED_API_URL": "http://127.0.0.1/api/v1"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
若未发布到 PyPI,可改用本地源码方式:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"servers": {
|
|
119
|
+
"gopeed": {
|
|
120
|
+
"command": "python",
|
|
121
|
+
"args": ["<仓库绝对路径>/server.py"],
|
|
122
|
+
"env": {
|
|
123
|
+
"GOPEED_API_URL": "http://127.0.0.1/api/v1"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
> **注意**:
|
|
131
|
+
> - `GOPEED_API_URL` 推荐留空端口(`http://127.0.0.1/api/v1`),server 会自动发现 Gopeed 当前监听端口;若已固定端口则写完整地址。
|
|
132
|
+
> - 如果 Gopeed 配置了 API 令牌,在 `env` 中添加 `"GOPEED_API_TOKEN": "你的令牌"`。
|
|
133
|
+
> - Windows 沙箱(sandbox)目前不可用,本地 stdio server 直接运行。
|
|
134
|
+
|
|
135
|
+
3. 保存 `mcp.json`,重启 VS Code(或 `Developer: Reload Window`)。
|
|
136
|
+
|
|
137
|
+
4. 验证配置:打开 Copilot Chat,输入 `@gopeed` 或直接描述需求,Copilot 应能识别并调用 Gopeed 工具。也可在 MCP 面板中查看 `gopeed` server 状态。
|
|
138
|
+
|
|
139
|
+
## 使用示例
|
|
140
|
+
|
|
141
|
+
在 VS Code Copilot Chat 中,你可以这样说:
|
|
142
|
+
|
|
143
|
+
| 你说的话 | 触发的操作 |
|
|
144
|
+
|----------|-----------|
|
|
145
|
+
| "帮我下载这个文件:https://example.com/file.zip" | 创建下载任务 |
|
|
146
|
+
| "下载 https://example.com/video.mp4,文件名改成我的视频.mp4,用 32 个连接" | 创建任务并指定文件名和并发数 |
|
|
147
|
+
| "看看现在有哪些下载任务" | 列出所有任务 |
|
|
148
|
+
| "显示正在下载的任务" | 按 running 状态过滤任务列表 |
|
|
149
|
+
| "查看任务 abc123 的详细信息" | 获取任务详情 |
|
|
150
|
+
| "暂停任务 abc123" | 暂停任务 |
|
|
151
|
+
| "继续任务 abc123" | 恢复任务 |
|
|
152
|
+
| "删除任务 abc123" | 删除任务(保留文件) |
|
|
153
|
+
| "删除任务 abc123,连文件一起删掉" | 强制删除任务和文件 |
|
|
154
|
+
| "Gopeed 当前配置是什么?" | 获取配置 |
|
|
155
|
+
| "把并发连接数改成 32" | 更新配置 |
|
|
156
|
+
| "把下载目录改成 D:\\Downloads" | 更新下载目录 |
|
|
157
|
+
| "启用代理" / "关闭代理" | 更新代理开关 |
|
|
158
|
+
|
|
159
|
+
## 项目结构
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
gopeed-mcp-server/
|
|
163
|
+
├── server.py # MCP Server 主入口,定义所有 MCP Tools
|
|
164
|
+
├── gopeed_client.py # Gopeed REST API 客户端封装
|
|
165
|
+
├── config.py # 配置管理(从环境变量读取)
|
|
166
|
+
├── pyproject.toml # 打包配置(提供 gopeed-mcp-server 命令)
|
|
167
|
+
├── requirements.txt # Python 依赖
|
|
168
|
+
├── .env.example # 环境变量示例
|
|
169
|
+
├── icon.png # MCP Gallery 图标
|
|
170
|
+
└── README.md # 本文件
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 故障排查
|
|
174
|
+
|
|
175
|
+
### 1. Copilot Chat 无法调用 Gopeed 工具
|
|
176
|
+
|
|
177
|
+
- 确认 `mcp.json` 中 `servers.gopeed` 配置正确(`uvx gopeed-mcp-server` 或本地 `python server.py`),路径使用正斜杠或双反斜杠 `\\`。
|
|
178
|
+
- 若使用本地源码方式,确认 `command` 指向可运行的 Python(如 `...\.venv\Scripts\python.exe` 或裸 `python`),而非错误路径。
|
|
179
|
+
- 重启 VS Code 后再试。
|
|
180
|
+
- 在 VS Code 中打开 **Output** 面板,选择 **MCP** 通道查看 gopeed server 的日志输出。
|
|
181
|
+
|
|
182
|
+
### 2. 提示"无法连接到 Gopeed"
|
|
183
|
+
|
|
184
|
+
- 确认 Gopeed 已启动并正在运行。
|
|
185
|
+
- Gopeed 每次重启会随机分配 API 端口,本 server 默认**自动发现**当前端口;若 `GOPEED_API_URL` 写死了旧端口会失效,建议改为留空端口的 `http://127.0.0.1/api/v1`。
|
|
186
|
+
- 检查防火墙是否阻止了本地回环连接;若系统启用了代理,localhost 请求可能被拦截返回 503,本 server 已对本地请求禁用代理。
|
|
187
|
+
|
|
188
|
+
### 3. 提示"Gopeed 业务错误"或"HTTP 401/403"
|
|
189
|
+
|
|
190
|
+
- Gopeed 可能配置了 API 访问令牌,需要在 `env` 中设置 `GOPEED_API_TOKEN`。
|
|
191
|
+
- 在 Gopeed Web UI 的设置中查看是否启用了令牌认证。
|
|
192
|
+
|
|
193
|
+
### 4. Python 依赖安装失败
|
|
194
|
+
|
|
195
|
+
- 确保 Python 版本 >= 3.10:`python --version`
|
|
196
|
+
- 升级 pip:`pip install --upgrade pip`
|
|
197
|
+
- 使用国内镜像源:`pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
|
|
198
|
+
|
|
199
|
+
### 5. 手动测试 Gopeed API 连通性
|
|
200
|
+
|
|
201
|
+
Gopeed 端口随机,先找到当前端口再用 curl 测试:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Windows:通过 netstat 找到 gopeed 监听的回环端口
|
|
205
|
+
netstat -ano | findstr "LISTENING" | findstr "gopeed"
|
|
206
|
+
|
|
207
|
+
# 假设查到端口为 12345,则:
|
|
208
|
+
curl http://127.0.0.1:12345/api/v1/config
|
|
209
|
+
curl http://127.0.0.1:12345/api/v1/tasks
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
如果 curl 能正常返回 JSON 数据(含 `"code":0`),说明 Gopeed API 正常,问题出在 MCP Server 配置或 Python 环境。
|
|
213
|
+
|
|
214
|
+
## 许可证
|
|
215
|
+
|
|
216
|
+
本项目(Gopeed MCP Server)以 **MIT** 许可证发布,详见 [LICENSE](./LICENSE)。
|
|
217
|
+
|
|
218
|
+
被控对象 [Gopeed](https://github.com/GopeedLab/gopeed) 本身是独立的开源项目,采用 **GPL-3.0** 许可证(© GopeedLab 及其贡献者)。本 Server 仅通过网络调用其公开 REST API 进行集成,不构成对 Gopeed 源代码的修改或衍生,亦不随本仓库分发 Gopeed 的任何代码。如使用 Gopeed 本体,请遵守其对应的许可证条款。
|
|
219
|
+
|
|
220
|
+
## 发布与上架
|
|
221
|
+
|
|
222
|
+
本 server 已打包为 Python 包(见 `pyproject.toml`),提供 `gopeed-mcp-server` 命令,可被 VS Code、社区 registry 等直接引用。
|
|
223
|
+
|
|
224
|
+
- **GitHub(已公开)**:仓库即发布页。别人在 GitHub 搜到后,按上面的 `mcp.json` 片段手动添加即可使用。
|
|
225
|
+
- **PyPI**:`pip install gopeed-mcp-server` 或直接 `uvx gopeed-mcp-server`(需先发布到 PyPI,见下文)。
|
|
226
|
+
- **Glama**:打开 https://glama.ai/mcp/register ,粘贴本仓库 URL(`https://github.com/Panda-Young/gopeed-mcp-server`),会自动读取仓库根的 `mcp.json`。
|
|
227
|
+
- **Smithery**:本地 stdio server 用 CLI 发布(非网页表单)。安装 `@smithery/cli` 后,在仓库目录执行 `smithery login` 再 `smithery mcp publish . -n @<你的用户名>/gopeed-mcp-server`(会读取 `smithery.yaml`)。
|
|
228
|
+
- **VS Code MCP Gallery**:VS Code 内置的 MCP Gallery 目前为微软托管的精选列表,**没有公开的投稿入口**,个人开发者暂无法直接上架。用户可从上面的 GitHub / PyPI / Glama / Smithery 任一渠道获取并手动配置到 `mcp.json`。
|
|
229
|
+
- **手动分享**:任何已安装本包的环境,把上面的 `mcp.json` 片段加入 `mcp.json` 即可使用。
|
|
230
|
+
|
|
231
|
+
### 发布到 PyPI
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# 本地已构建好 dist/ 下的 wheel 与 sdist
|
|
235
|
+
$env:TWINE_USERNAME="__token__"
|
|
236
|
+
$env:TWINE_PASSWORD="pypi-你的PyPI令牌" # 从 https://pypi.org/manage/account/token/ 获取
|
|
237
|
+
.venv/Scripts/twine.exe upload dist/*
|
|
238
|
+
```
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Gopeed MCP Server
|
|
2
|
+
|
|
3
|
+
一个基于 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 的 Server,让你能在 VS Code Copilot Chat 中通过自然语言控制 [Gopeed](https://github.com/GopeedLab/gopeed) 下载管理器。
|
|
4
|
+
|
|
5
|
+
> **关于 Gopeed**:本项目的被控对象是开源下载管理器 [Gopeed](https://github.com/GopeedLab/gopeed)(由 `GopeedLab` 维护,采用 [GPL-3.0](https://github.com/GopeedLab/gopeed/blob/main/LICENSE) 许可证)。本 Server 仅通过 Gopeed 公开的 **REST API** 与之通信,不修改、不嵌入其任何源代码,因此本仓库以 MIT 许可证独立发布。使用前请先安装并运行 Gopeed 本体。
|
|
6
|
+
|
|
7
|
+
## 功能介绍
|
|
8
|
+
|
|
9
|
+
本 MCP Server 封装了 Gopeed 的 REST API,提供以下 8 个工具:
|
|
10
|
+
|
|
11
|
+
| 工具 | 说明 |
|
|
12
|
+
|------|------|
|
|
13
|
+
| `create_download_task` | 创建下载任务,支持自定义文件名和并发连接数 |
|
|
14
|
+
| `list_tasks` | 列出所有下载任务,可按状态过滤 |
|
|
15
|
+
| `get_task_detail` | 获取单个任务的详细信息 |
|
|
16
|
+
| `pause_task` | 暂停指定任务 |
|
|
17
|
+
| `resume_task` | 恢复(继续)指定任务 |
|
|
18
|
+
| `delete_task` | 删除任务,可选同时删除已下载文件 |
|
|
19
|
+
| `get_config` | 获取 Gopeed 当前配置(下载目录、连接数、代理等) |
|
|
20
|
+
| `update_config` | 更新 Gopeed 配置(只传需要修改的字段) |
|
|
21
|
+
|
|
22
|
+
## 环境要求
|
|
23
|
+
|
|
24
|
+
- Python 3.10+
|
|
25
|
+
- Gopeed 已安装并运行(API 端口每次启动随机分配,无需手动指定)
|
|
26
|
+
- VS Code 安装了 GitHub Copilot Chat 扩展
|
|
27
|
+
|
|
28
|
+
## 安装步骤
|
|
29
|
+
|
|
30
|
+
1. 进入项目目录:
|
|
31
|
+
```bash
|
|
32
|
+
cd gopeed-mcp-server
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. (推荐)创建虚拟环境:
|
|
36
|
+
```bash
|
|
37
|
+
python -m venv .venv
|
|
38
|
+
# Windows
|
|
39
|
+
.venv\Scripts\activate
|
|
40
|
+
# macOS / Linux
|
|
41
|
+
source .venv/bin/activate
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. 安装依赖(二选一):
|
|
45
|
+
|
|
46
|
+
- 方式 A:从源码安装依赖
|
|
47
|
+
```bash
|
|
48
|
+
pip install -r requirements.txt
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- 方式 B:作为 Python 包安装(推荐,可用于 `uvx` 一键启动)
|
|
52
|
+
```bash
|
|
53
|
+
pip install .
|
|
54
|
+
# 或发布后: pip install gopeed-mcp-server
|
|
55
|
+
```
|
|
56
|
+
安装后会得到 `gopeed-mcp-server` 命令,可用 `uvx gopeed-mcp-server` 直接启动。
|
|
57
|
+
|
|
58
|
+
4. (可选)配置环境变量。复制 `.env.example` 为 `.env` 并按需修改:
|
|
59
|
+
```bash
|
|
60
|
+
copy .env.example .env
|
|
61
|
+
```
|
|
62
|
+
可用环境变量:
|
|
63
|
+
- `GOPEED_API_URL`:Gopeed API 地址。**推荐留空端口**(默认 `http://127.0.0.1/api/v1`),server 会自动发现 Gopeed 当前端口(Gopeed 每次重启都会随机换端口,自动发现可免去手动改配置)。仅在确需固定时才写 `http://127.0.0.1:<端口>/api/v1`
|
|
64
|
+
- `GOPEED_API_TOKEN`:API 令牌(可选,Gopeed 配置了令牌时需要)
|
|
65
|
+
- `GOPEED_TIMEOUT`:请求超时秒数,默认 `10`
|
|
66
|
+
|
|
67
|
+
## VS Code Copilot Chat 配置方法
|
|
68
|
+
|
|
69
|
+
**方式一:从 MCP Gallery 安装(推荐,已上架后)**
|
|
70
|
+
|
|
71
|
+
1. 打开 Extensions 视图(`Ctrl+Shift+X`),搜索 `@mcp gopeed`。
|
|
72
|
+
2. 选择 **Install** 安装到用户配置,按提示信任并启动即可。
|
|
73
|
+
|
|
74
|
+
**方式二:手动配置 `mcp.json`**
|
|
75
|
+
|
|
76
|
+
VS Code 1.99+ 使用专用的 `mcp.json`(而不是 `settings.json` 的 `mcpServers` 字段)。
|
|
77
|
+
|
|
78
|
+
1. 按 `Ctrl+Shift+P`,运行 **`MCP: Open User Configuration`**(或在工作区创建 `.vscode/mcp.json`)。
|
|
79
|
+
2. 添加如下配置(使用 `uvx` 启动,无需本地路径):
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"servers": {
|
|
84
|
+
"gopeed": {
|
|
85
|
+
"command": "uvx",
|
|
86
|
+
"args": ["gopeed-mcp-server"],
|
|
87
|
+
"env": {
|
|
88
|
+
"GOPEED_API_URL": "http://127.0.0.1/api/v1"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
若未发布到 PyPI,可改用本地源码方式:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"servers": {
|
|
100
|
+
"gopeed": {
|
|
101
|
+
"command": "python",
|
|
102
|
+
"args": ["<仓库绝对路径>/server.py"],
|
|
103
|
+
"env": {
|
|
104
|
+
"GOPEED_API_URL": "http://127.0.0.1/api/v1"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> **注意**:
|
|
112
|
+
> - `GOPEED_API_URL` 推荐留空端口(`http://127.0.0.1/api/v1`),server 会自动发现 Gopeed 当前监听端口;若已固定端口则写完整地址。
|
|
113
|
+
> - 如果 Gopeed 配置了 API 令牌,在 `env` 中添加 `"GOPEED_API_TOKEN": "你的令牌"`。
|
|
114
|
+
> - Windows 沙箱(sandbox)目前不可用,本地 stdio server 直接运行。
|
|
115
|
+
|
|
116
|
+
3. 保存 `mcp.json`,重启 VS Code(或 `Developer: Reload Window`)。
|
|
117
|
+
|
|
118
|
+
4. 验证配置:打开 Copilot Chat,输入 `@gopeed` 或直接描述需求,Copilot 应能识别并调用 Gopeed 工具。也可在 MCP 面板中查看 `gopeed` server 状态。
|
|
119
|
+
|
|
120
|
+
## 使用示例
|
|
121
|
+
|
|
122
|
+
在 VS Code Copilot Chat 中,你可以这样说:
|
|
123
|
+
|
|
124
|
+
| 你说的话 | 触发的操作 |
|
|
125
|
+
|----------|-----------|
|
|
126
|
+
| "帮我下载这个文件:https://example.com/file.zip" | 创建下载任务 |
|
|
127
|
+
| "下载 https://example.com/video.mp4,文件名改成我的视频.mp4,用 32 个连接" | 创建任务并指定文件名和并发数 |
|
|
128
|
+
| "看看现在有哪些下载任务" | 列出所有任务 |
|
|
129
|
+
| "显示正在下载的任务" | 按 running 状态过滤任务列表 |
|
|
130
|
+
| "查看任务 abc123 的详细信息" | 获取任务详情 |
|
|
131
|
+
| "暂停任务 abc123" | 暂停任务 |
|
|
132
|
+
| "继续任务 abc123" | 恢复任务 |
|
|
133
|
+
| "删除任务 abc123" | 删除任务(保留文件) |
|
|
134
|
+
| "删除任务 abc123,连文件一起删掉" | 强制删除任务和文件 |
|
|
135
|
+
| "Gopeed 当前配置是什么?" | 获取配置 |
|
|
136
|
+
| "把并发连接数改成 32" | 更新配置 |
|
|
137
|
+
| "把下载目录改成 D:\\Downloads" | 更新下载目录 |
|
|
138
|
+
| "启用代理" / "关闭代理" | 更新代理开关 |
|
|
139
|
+
|
|
140
|
+
## 项目结构
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
gopeed-mcp-server/
|
|
144
|
+
├── server.py # MCP Server 主入口,定义所有 MCP Tools
|
|
145
|
+
├── gopeed_client.py # Gopeed REST API 客户端封装
|
|
146
|
+
├── config.py # 配置管理(从环境变量读取)
|
|
147
|
+
├── pyproject.toml # 打包配置(提供 gopeed-mcp-server 命令)
|
|
148
|
+
├── requirements.txt # Python 依赖
|
|
149
|
+
├── .env.example # 环境变量示例
|
|
150
|
+
├── icon.png # MCP Gallery 图标
|
|
151
|
+
└── README.md # 本文件
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 故障排查
|
|
155
|
+
|
|
156
|
+
### 1. Copilot Chat 无法调用 Gopeed 工具
|
|
157
|
+
|
|
158
|
+
- 确认 `mcp.json` 中 `servers.gopeed` 配置正确(`uvx gopeed-mcp-server` 或本地 `python server.py`),路径使用正斜杠或双反斜杠 `\\`。
|
|
159
|
+
- 若使用本地源码方式,确认 `command` 指向可运行的 Python(如 `...\.venv\Scripts\python.exe` 或裸 `python`),而非错误路径。
|
|
160
|
+
- 重启 VS Code 后再试。
|
|
161
|
+
- 在 VS Code 中打开 **Output** 面板,选择 **MCP** 通道查看 gopeed server 的日志输出。
|
|
162
|
+
|
|
163
|
+
### 2. 提示"无法连接到 Gopeed"
|
|
164
|
+
|
|
165
|
+
- 确认 Gopeed 已启动并正在运行。
|
|
166
|
+
- Gopeed 每次重启会随机分配 API 端口,本 server 默认**自动发现**当前端口;若 `GOPEED_API_URL` 写死了旧端口会失效,建议改为留空端口的 `http://127.0.0.1/api/v1`。
|
|
167
|
+
- 检查防火墙是否阻止了本地回环连接;若系统启用了代理,localhost 请求可能被拦截返回 503,本 server 已对本地请求禁用代理。
|
|
168
|
+
|
|
169
|
+
### 3. 提示"Gopeed 业务错误"或"HTTP 401/403"
|
|
170
|
+
|
|
171
|
+
- Gopeed 可能配置了 API 访问令牌,需要在 `env` 中设置 `GOPEED_API_TOKEN`。
|
|
172
|
+
- 在 Gopeed Web UI 的设置中查看是否启用了令牌认证。
|
|
173
|
+
|
|
174
|
+
### 4. Python 依赖安装失败
|
|
175
|
+
|
|
176
|
+
- 确保 Python 版本 >= 3.10:`python --version`
|
|
177
|
+
- 升级 pip:`pip install --upgrade pip`
|
|
178
|
+
- 使用国内镜像源:`pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
|
|
179
|
+
|
|
180
|
+
### 5. 手动测试 Gopeed API 连通性
|
|
181
|
+
|
|
182
|
+
Gopeed 端口随机,先找到当前端口再用 curl 测试:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Windows:通过 netstat 找到 gopeed 监听的回环端口
|
|
186
|
+
netstat -ano | findstr "LISTENING" | findstr "gopeed"
|
|
187
|
+
|
|
188
|
+
# 假设查到端口为 12345,则:
|
|
189
|
+
curl http://127.0.0.1:12345/api/v1/config
|
|
190
|
+
curl http://127.0.0.1:12345/api/v1/tasks
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
如果 curl 能正常返回 JSON 数据(含 `"code":0`),说明 Gopeed API 正常,问题出在 MCP Server 配置或 Python 环境。
|
|
194
|
+
|
|
195
|
+
## 许可证
|
|
196
|
+
|
|
197
|
+
本项目(Gopeed MCP Server)以 **MIT** 许可证发布,详见 [LICENSE](./LICENSE)。
|
|
198
|
+
|
|
199
|
+
被控对象 [Gopeed](https://github.com/GopeedLab/gopeed) 本身是独立的开源项目,采用 **GPL-3.0** 许可证(© GopeedLab 及其贡献者)。本 Server 仅通过网络调用其公开 REST API 进行集成,不构成对 Gopeed 源代码的修改或衍生,亦不随本仓库分发 Gopeed 的任何代码。如使用 Gopeed 本体,请遵守其对应的许可证条款。
|
|
200
|
+
|
|
201
|
+
## 发布与上架
|
|
202
|
+
|
|
203
|
+
本 server 已打包为 Python 包(见 `pyproject.toml`),提供 `gopeed-mcp-server` 命令,可被 VS Code、社区 registry 等直接引用。
|
|
204
|
+
|
|
205
|
+
- **GitHub(已公开)**:仓库即发布页。别人在 GitHub 搜到后,按上面的 `mcp.json` 片段手动添加即可使用。
|
|
206
|
+
- **PyPI**:`pip install gopeed-mcp-server` 或直接 `uvx gopeed-mcp-server`(需先发布到 PyPI,见下文)。
|
|
207
|
+
- **Glama**:打开 https://glama.ai/mcp/register ,粘贴本仓库 URL(`https://github.com/Panda-Young/gopeed-mcp-server`),会自动读取仓库根的 `mcp.json`。
|
|
208
|
+
- **Smithery**:本地 stdio server 用 CLI 发布(非网页表单)。安装 `@smithery/cli` 后,在仓库目录执行 `smithery login` 再 `smithery mcp publish . -n @<你的用户名>/gopeed-mcp-server`(会读取 `smithery.yaml`)。
|
|
209
|
+
- **VS Code MCP Gallery**:VS Code 内置的 MCP Gallery 目前为微软托管的精选列表,**没有公开的投稿入口**,个人开发者暂无法直接上架。用户可从上面的 GitHub / PyPI / Glama / Smithery 任一渠道获取并手动配置到 `mcp.json`。
|
|
210
|
+
- **手动分享**:任何已安装本包的环境,把上面的 `mcp.json` 片段加入 `mcp.json` 即可使用。
|
|
211
|
+
|
|
212
|
+
### 发布到 PyPI
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# 本地已构建好 dist/ 下的 wheel 与 sdist
|
|
216
|
+
$env:TWINE_USERNAME="__token__"
|
|
217
|
+
$env:TWINE_PASSWORD="pypi-你的PyPI令牌" # 从 https://pypi.org/manage/account/token/ 获取
|
|
218
|
+
.venv/Scripts/twine.exe upload dist/*
|
|
219
|
+
```
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""
|
|
2
|
+
配置管理模块
|
|
3
|
+
|
|
4
|
+
通过环境变量配置 Gopeed MCP Server 的运行参数。
|
|
5
|
+
|
|
6
|
+
Gopeed 每次重启都会随机分配一个本地 API 端口,且端口不会持久化到可读配置。
|
|
7
|
+
因此本模块支持「自动发现」:当未显式配置具体端口时,通过 netstat 定位
|
|
8
|
+
gopeed.exe 实际监听的回环端口,并验证其响应标准 Gopeed API。
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import subprocess
|
|
13
|
+
|
|
14
|
+
# 如果 GOPEED_API_URL 未指定具体端口(只给 host 或无路径),则触发自动发现。
|
|
15
|
+
# 显式配置完整 URL(含端口)时优先使用,不做发现。
|
|
16
|
+
_AUTO_DISCOVER = os.getenv("GOPEED_API_AUTO_DISCOVER", "1").lower() in ("1", "true", "yes")
|
|
17
|
+
|
|
18
|
+
# 候选进程名(用于在 netstat 结果中识别 Gopeed 监听端口)
|
|
19
|
+
_GOPEED_PROC_NAMES = ("gopeed.exe", "gopeed")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Settings:
|
|
23
|
+
"""运行时配置,从环境变量读取。"""
|
|
24
|
+
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
# Gopeed REST API 基础地址(可能由自动发现动态解析)
|
|
27
|
+
raw = os.getenv("GOPEED_API_URL", "").strip()
|
|
28
|
+
if raw:
|
|
29
|
+
# 用户显式配置了 URL:若包含端口则直接使用,否则走自动发现
|
|
30
|
+
self._explicit_url = raw
|
|
31
|
+
else:
|
|
32
|
+
# 未配置:使用默认 host 并自动发现端口
|
|
33
|
+
self._explicit_url = "http://127.0.0.1/api/v1"
|
|
34
|
+
# API 令牌(可选,Gopeed 配置了令牌时需要)
|
|
35
|
+
self.api_token: str | None = os.getenv("GOPEED_API_TOKEN") or None
|
|
36
|
+
# HTTP 请求超时(秒)
|
|
37
|
+
self.timeout: float = float(os.getenv("GOPEED_TIMEOUT", "10"))
|
|
38
|
+
# 自动发现缓存
|
|
39
|
+
self._discovered_url: str | None = None
|
|
40
|
+
self._discover_attempted = False
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def api_url(self) -> str:
|
|
44
|
+
"""Gopeed API 地址;必要时自动发现当前端口。"""
|
|
45
|
+
explicit = self._explicit_url
|
|
46
|
+
# 若显式 URL 的 host 部分已含具体端口,则直接使用,不触发发现
|
|
47
|
+
host_part = explicit.split("//", 1)[-1].split("/", 1)[0]
|
|
48
|
+
if ":" in host_part:
|
|
49
|
+
return explicit
|
|
50
|
+
# 否则按需自动发现当前 Gopeed 端口
|
|
51
|
+
return self._discover_url() or explicit
|
|
52
|
+
|
|
53
|
+
def reset_discovery_cache(self) -> None:
|
|
54
|
+
"""清除端口发现缓存。Gopeed 重启换端口后必须调用此方法才能重新发现。"""
|
|
55
|
+
self._discovered_url = None
|
|
56
|
+
self._discover_attempted = False
|
|
57
|
+
|
|
58
|
+
def _discover_url(self) -> str | None:
|
|
59
|
+
"""通过 netstat 定位 gopeed 监听端口并验证 API。"""
|
|
60
|
+
if self._discover_attempted and self._discovered_url is not None:
|
|
61
|
+
return self._discovered_url
|
|
62
|
+
self._discover_attempted = True
|
|
63
|
+
ports = self._find_gopeed_ports()
|
|
64
|
+
for port in ports:
|
|
65
|
+
url = f"http://127.0.0.1:{port}/api/v1"
|
|
66
|
+
if self._probe(url):
|
|
67
|
+
self._discovered_url = url
|
|
68
|
+
return url
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def _find_gopeed_ports() -> list[str]:
|
|
73
|
+
"""返回 gopeed 进程在 127.0.0.1 上监听的端口列表(有序)。"""
|
|
74
|
+
try:
|
|
75
|
+
out = subprocess.run(
|
|
76
|
+
["netstat", "-ano"], capture_output=True, text=True,
|
|
77
|
+
encoding="utf-8", errors="replace", timeout=10
|
|
78
|
+
).stdout
|
|
79
|
+
except Exception:
|
|
80
|
+
return []
|
|
81
|
+
# 收集 gopeed 进程 PID
|
|
82
|
+
pids: set[str] = set()
|
|
83
|
+
try:
|
|
84
|
+
ps = subprocess.run(
|
|
85
|
+
["powershell", "-NoProfile", "-Command",
|
|
86
|
+
"Get-Process gopeed -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id"],
|
|
87
|
+
capture_output=True, text=True,
|
|
88
|
+
encoding="utf-8", errors="replace", timeout=10,
|
|
89
|
+
).stdout
|
|
90
|
+
pids = {p.strip() for p in ps.split() if p.strip().isdigit()}
|
|
91
|
+
except Exception:
|
|
92
|
+
pass
|
|
93
|
+
ports: list[str] = []
|
|
94
|
+
for line in out.splitlines():
|
|
95
|
+
if "LISTENING" not in line or "127.0.0.1:" not in line:
|
|
96
|
+
continue
|
|
97
|
+
parts = line.split()
|
|
98
|
+
if len(parts) < 5:
|
|
99
|
+
continue
|
|
100
|
+
addr = parts[1]
|
|
101
|
+
pid = parts[-1]
|
|
102
|
+
if pids and pid not in pids:
|
|
103
|
+
continue # 已知 PID 时按进程过滤
|
|
104
|
+
port = addr.split(":")[-1]
|
|
105
|
+
if port.isdigit() and port not in ports:
|
|
106
|
+
ports.append(port)
|
|
107
|
+
return ports
|
|
108
|
+
|
|
109
|
+
def _probe(self, url: str) -> bool:
|
|
110
|
+
"""快速验证某 URL 是否为有效的 Gopeed API。"""
|
|
111
|
+
try:
|
|
112
|
+
import httpx
|
|
113
|
+
r = httpx.get(f"{url}/config", timeout=2.0, proxy=None,
|
|
114
|
+
headers=self.headers if self.api_token else None)
|
|
115
|
+
if r.status_code != 200:
|
|
116
|
+
return False
|
|
117
|
+
body = r.json()
|
|
118
|
+
return body.get("code", -1) == 0
|
|
119
|
+
except Exception:
|
|
120
|
+
return False
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def headers(self) -> dict[str, str]:
|
|
124
|
+
"""构造请求头,包含令牌(如有)。"""
|
|
125
|
+
headers: dict[str, str] = {"Content-Type": "application/json"}
|
|
126
|
+
if self.api_token:
|
|
127
|
+
headers["Authorization"] = f"Bearer {self.api_token}"
|
|
128
|
+
return headers
|
|
129
|
+
|
|
130
|
+
def __repr__(self) -> str:
|
|
131
|
+
return (
|
|
132
|
+
f"Settings(api_url={self.api_url!r}, "
|
|
133
|
+
f"api_token={'***' if self.api_token else None}, "
|
|
134
|
+
f"timeout={self.timeout})"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# 全局单例
|
|
139
|
+
settings = Settings()
|