devlake-mcp 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.
- devlake_mcp-0.1.0/LICENSE +21 -0
- devlake_mcp-0.1.0/PKG-INFO +494 -0
- devlake_mcp-0.1.0/README.md +464 -0
- devlake_mcp-0.1.0/pyproject.toml +70 -0
- devlake_mcp-0.1.0/setup.cfg +4 -0
- devlake_mcp-0.1.0/src/devlake_mcp/__init__.py +7 -0
- devlake_mcp-0.1.0/src/devlake_mcp/__main__.py +10 -0
- devlake_mcp-0.1.0/src/devlake_mcp/client.py +212 -0
- devlake_mcp-0.1.0/src/devlake_mcp/config.py +69 -0
- devlake_mcp-0.1.0/src/devlake_mcp/git_utils.py +264 -0
- devlake_mcp-0.1.0/src/devlake_mcp/server.py +607 -0
- devlake_mcp-0.1.0/src/devlake_mcp/utils.py +154 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/PKG-INFO +494 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/SOURCES.txt +17 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/dependency_links.txt +1 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/entry_points.txt +2 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/requires.txt +7 -0
- devlake_mcp-0.1.0/src/devlake_mcp.egg-info/top_level.txt +1 -0
- devlake_mcp-0.1.0/tests/test_mcp_tools.py +271 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DevLake MCP 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,494 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devlake-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Model Context Protocol server for DevLake
|
|
5
|
+
Author-email: wangzhong <wangzhong@g7.com.cn>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://git.chinawayltd.com/engineering-efficiency/devlake-mcp
|
|
8
|
+
Project-URL: Repository, https://git.chinawayltd.com/engineering-efficiency/devlake-mcp
|
|
9
|
+
Project-URL: Issues, https://git.chinawayltd.com/engineering-efficiency/devlake-mcp
|
|
10
|
+
Keywords: mcp,devlake,model-context-protocol,ai,llm
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: fastmcp>=0.5.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
27
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# DevLake MCP Server
|
|
32
|
+
|
|
33
|
+
一个基于 [FastMCP](https://gofastmcp.com) 框架的 DevLake MCP 服务器,允许 AI 助手(如 Claude)与 DevLake 进行交互。
|
|
34
|
+
|
|
35
|
+
## 功能特性
|
|
36
|
+
|
|
37
|
+
- 🚀 基于强大的 FastMCP 框架(第三方)
|
|
38
|
+
- 📦 支持通过 pipx 安装
|
|
39
|
+
- 🔧 可扩展的工具系统
|
|
40
|
+
- 💻 与 Claude Desktop、Cursor 等 MCP 客户端兼容
|
|
41
|
+
- 🔐 支持认证和中间件(FastMCP 高级功能)
|
|
42
|
+
- 🌐 支持多种传输协议(STDIO、HTTP、SSE)
|
|
43
|
+
|
|
44
|
+
## 为什么选择 FastMCP?
|
|
45
|
+
|
|
46
|
+
我们使用 [jlowin/fastmcp](https://github.com/jlowin/fastmcp) 而不是官方 MCP SDK:
|
|
47
|
+
|
|
48
|
+
- ✅ 更简洁优雅的 API 设计
|
|
49
|
+
- ✅ 生产环境就绪
|
|
50
|
+
- ✅ 内置认证和授权支持
|
|
51
|
+
- ✅ 强大的中间件系统
|
|
52
|
+
- ✅ 支持 HTTP/SSE 传输
|
|
53
|
+
- ✅ 可集成 OpenAPI 和 FastAPI
|
|
54
|
+
- ✅ 活跃的社区维护
|
|
55
|
+
|
|
56
|
+
## 安装
|
|
57
|
+
|
|
58
|
+
### 方式 1: 使用 pipx(推荐)
|
|
59
|
+
|
|
60
|
+
pipx 会在隔离环境中安装 Python 应用程序:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 安装 pipx(如果还没有安装)
|
|
64
|
+
# macOS
|
|
65
|
+
brew install pipx
|
|
66
|
+
|
|
67
|
+
# Linux
|
|
68
|
+
python3 -m pip install --user pipx
|
|
69
|
+
python3 -m pipx ensurepath
|
|
70
|
+
|
|
71
|
+
# 使用 pipx 安装 devlake-mcp
|
|
72
|
+
pipx install devlake-mcp
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 方式 2: 从源码安装
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 克隆仓库
|
|
79
|
+
git clone https://github.com/yourusername/devlake-mcp.git
|
|
80
|
+
cd devlake-mcp
|
|
81
|
+
|
|
82
|
+
# 使用 pip 安装(开发模式)
|
|
83
|
+
pip install -e .
|
|
84
|
+
|
|
85
|
+
# 或使用 uv(推荐用于开发)
|
|
86
|
+
uv pip install -e .
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 方式 3: 本地开发
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# 安装 uv(如果还没有安装)
|
|
93
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
94
|
+
|
|
95
|
+
# 创建虚拟环境并安装依赖
|
|
96
|
+
uv venv
|
|
97
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
98
|
+
uv pip install -e ".[dev]"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 使用方法
|
|
102
|
+
|
|
103
|
+
### 作为命令行工具运行
|
|
104
|
+
|
|
105
|
+
安装后,可以直接运行服务器:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
devlake-mcp
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 与 Claude Desktop 集成
|
|
112
|
+
|
|
113
|
+
1. 找到 Claude Desktop 配置文件:
|
|
114
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
115
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
116
|
+
|
|
117
|
+
2. 添加服务器配置:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"mcpServers": {
|
|
122
|
+
"devlake": {
|
|
123
|
+
"command": "devlake-mcp"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
如果从源码运行:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"devlake": {
|
|
135
|
+
"command": "uv",
|
|
136
|
+
"args": [
|
|
137
|
+
"--directory",
|
|
138
|
+
"/绝对路径/到/devlake-mcp",
|
|
139
|
+
"run",
|
|
140
|
+
"devlake-mcp"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. 重启 Claude Desktop
|
|
148
|
+
|
|
149
|
+
## 环境变量配置
|
|
150
|
+
|
|
151
|
+
在使用前,需要配置 DevLake API 连接信息。
|
|
152
|
+
|
|
153
|
+
### 方式 1: 使用 .env 文件(推荐)
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# 复制示例配置文件
|
|
157
|
+
cp .env.example .env
|
|
158
|
+
|
|
159
|
+
# 编辑配置文件,填写实际值
|
|
160
|
+
vim .env
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`.env` 文件内容:
|
|
164
|
+
```bash
|
|
165
|
+
# DevLake API 地址(必需)
|
|
166
|
+
DEVLAKE_BASE_URL=http://devlake.test.chinawayltd.com
|
|
167
|
+
|
|
168
|
+
# API 超时时间(秒,默认 30)
|
|
169
|
+
DEVLAKE_TIMEOUT=30
|
|
170
|
+
|
|
171
|
+
# API 认证 Token(可选)
|
|
172
|
+
# DEVLAKE_API_TOKEN=your-token-here
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 方式 2: 直接设置环境变量
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
export DEVLAKE_BASE_URL="http://devlake.test.chinawayltd.com"
|
|
179
|
+
export DEVLAKE_TIMEOUT=30
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Git 配置(必需)
|
|
183
|
+
|
|
184
|
+
工具会自动从 Git 配置读取用户信息,请确保已配置:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# 配置 Git 用户信息
|
|
188
|
+
git config user.name "Your Name"
|
|
189
|
+
git config user.email "your.email@example.com"
|
|
190
|
+
|
|
191
|
+
# 配置仓库远程地址
|
|
192
|
+
git remote add origin <repository-url>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 与 Cursor 集成
|
|
196
|
+
|
|
197
|
+
1. 打开 Cursor 设置(Settings)
|
|
198
|
+
2. 进入 MCP 标签页
|
|
199
|
+
3. 点击 "Add new global MCP server"
|
|
200
|
+
4. 添加配置:
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"devlake": {
|
|
205
|
+
"command": "devlake-mcp",
|
|
206
|
+
"description": "DevLake MCP Server for querying DevLake data"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 可用工具
|
|
212
|
+
|
|
213
|
+
当前服务器提供 3 个核心工具,用于记录 AI 编程会话和文件变更:
|
|
214
|
+
|
|
215
|
+
### `record_session`
|
|
216
|
+
记录 AI 会话的元数据和统计信息。
|
|
217
|
+
|
|
218
|
+
**参数**:
|
|
219
|
+
- `session_id` (string, 可选): 会话 ID,不提供则自动生成 UUID
|
|
220
|
+
- `metadata` (dict, 可选): 会话元数据,支持字段:
|
|
221
|
+
- `user_intent`: 用户意图描述
|
|
222
|
+
- `model`: 模型名称(如 "claude-sonnet-4-5")
|
|
223
|
+
- `ide`: IDE 类型(如 "cursor", "claude-code")
|
|
224
|
+
- `project_path`: 项目路径
|
|
225
|
+
|
|
226
|
+
**返回**:
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"success": true,
|
|
230
|
+
"session_id": "uuid-xxx",
|
|
231
|
+
"timestamp": "2025-01-07T10:00:00Z",
|
|
232
|
+
"git_info": {
|
|
233
|
+
"git_repo_path": "yourorg/devlake",
|
|
234
|
+
"git_branch": "main",
|
|
235
|
+
"git_author": "Your Name"
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**示例**:
|
|
241
|
+
```
|
|
242
|
+
调用 record_session 工具,metadata 设置为 {"ide": "cursor", "model": "claude-sonnet-4-5"}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
### `before_edit_file`
|
|
248
|
+
在文件变更前调用,记录文件的当前状态。
|
|
249
|
+
|
|
250
|
+
**参数**:
|
|
251
|
+
- `session_id` (string, 必需): 会话唯一标识
|
|
252
|
+
- `file_paths` (list[string], 必需): 即将变更的文件绝对路径列表
|
|
253
|
+
|
|
254
|
+
**返回**:
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"success": true,
|
|
258
|
+
"session_id": "session-123",
|
|
259
|
+
"files_snapshot": {
|
|
260
|
+
"/path/to/file.py": {
|
|
261
|
+
"exists": true,
|
|
262
|
+
"line_count": 100,
|
|
263
|
+
"size": 2048
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**示例**:
|
|
270
|
+
```
|
|
271
|
+
调用 before_edit_file 工具,session_id 为 "session-123",file_paths 为 ["/path/to/file.py"]
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### `after_edit_file`
|
|
277
|
+
在文件变更后调用,上传变更数据到 DevLake API。
|
|
278
|
+
|
|
279
|
+
**参数**:
|
|
280
|
+
- `session_id` (string, 必需): 会话唯一标识(与 before_edit_file 一致)
|
|
281
|
+
- `file_paths` (list[string], 必需): 已变更的文件绝对路径列表
|
|
282
|
+
|
|
283
|
+
**返回**:
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"success": true,
|
|
287
|
+
"session_id": "session-123",
|
|
288
|
+
"uploaded_count": 1,
|
|
289
|
+
"changes": [
|
|
290
|
+
{
|
|
291
|
+
"file_path": "src/main.py",
|
|
292
|
+
"change_type": "edit",
|
|
293
|
+
"file_type": "py"
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**工作流程**:
|
|
300
|
+
```
|
|
301
|
+
1. before_edit_file() - 记录文件变更前状态
|
|
302
|
+
2. [执行文件变更操作]
|
|
303
|
+
3. after_edit_file() - 对比差异并上传
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**示例**:
|
|
307
|
+
```
|
|
308
|
+
调用 after_edit_file 工具,session_id 为 "session-123",file_paths 为 ["/path/to/file.py"]
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## 开发指南
|
|
312
|
+
|
|
313
|
+
### 添加新工具
|
|
314
|
+
|
|
315
|
+
在 `src/devlake_mcp/server.py` 中使用 `@mcp.tool` 装饰器定义新工具:
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
@mcp.tool
|
|
319
|
+
def your_tool_name(param1: str, param2: int) -> dict:
|
|
320
|
+
"""
|
|
321
|
+
工具描述(AI 会看到这个)
|
|
322
|
+
|
|
323
|
+
Args:
|
|
324
|
+
param1: 参数1的描述
|
|
325
|
+
param2: 参数2的描述
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
dict: 返回值描述
|
|
329
|
+
"""
|
|
330
|
+
# 你的工具逻辑
|
|
331
|
+
return {"result": "success"}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### 添加资源(Resources)
|
|
335
|
+
|
|
336
|
+
资源用于暴露静态或动态数据:
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
@mcp.resource("config://settings")
|
|
340
|
+
def get_settings() -> dict:
|
|
341
|
+
"""提供配置信息"""
|
|
342
|
+
return {"theme": "dark", "version": "1.0"}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### 添加提示(Prompts)
|
|
346
|
+
|
|
347
|
+
提示用于引导 AI 的交互:
|
|
348
|
+
|
|
349
|
+
```python
|
|
350
|
+
@mcp.prompt
|
|
351
|
+
def analyze_data(data_type: str) -> str:
|
|
352
|
+
"""生成数据分析提示"""
|
|
353
|
+
return f"请分析以下 {data_type} 类型的数据..."
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### 运行测试
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# 安装开发依赖
|
|
360
|
+
uv pip install -e ".[dev]"
|
|
361
|
+
|
|
362
|
+
# 运行测试
|
|
363
|
+
pytest
|
|
364
|
+
|
|
365
|
+
# 运行测试并显示输出
|
|
366
|
+
pytest -s
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### 代码格式化
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
# 使用 black 格式化代码
|
|
373
|
+
black src/
|
|
374
|
+
|
|
375
|
+
# 使用 ruff 检查代码
|
|
376
|
+
ruff check src/
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## 项目结构
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
devlake-mcp/
|
|
383
|
+
├── src/
|
|
384
|
+
│ └── devlake_mcp/
|
|
385
|
+
│ ├── __init__.py # 包初始化
|
|
386
|
+
│ ├── __main__.py # CLI 入口点
|
|
387
|
+
│ └── server.py # MCP 服务器实现
|
|
388
|
+
├── tests/ # 测试文件
|
|
389
|
+
├── pyproject.toml # 项目配置和依赖
|
|
390
|
+
├── README.md # 本文件
|
|
391
|
+
└── .gitignore # Git 忽略文件
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## 技术栈
|
|
395
|
+
|
|
396
|
+
- **FastMCP**: 强大的第三方 MCP 框架 (by jlowin)
|
|
397
|
+
- **Python 3.9+**: 需要 Python 3.9 或更高版本
|
|
398
|
+
|
|
399
|
+
## FastMCP 高级功能
|
|
400
|
+
|
|
401
|
+
### HTTP 传输
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
if __name__ == "__main__":
|
|
405
|
+
mcp.run(transport="http", port=8000)
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### 添加认证
|
|
409
|
+
|
|
410
|
+
```python
|
|
411
|
+
from fastmcp.server.auth import GoogleProvider
|
|
412
|
+
|
|
413
|
+
auth = GoogleProvider(
|
|
414
|
+
client_id="your-client-id",
|
|
415
|
+
client_secret="your-client-secret"
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
mcp = FastMCP("devlake-mcp", auth=auth)
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### 使用中间件
|
|
422
|
+
|
|
423
|
+
```python
|
|
424
|
+
from fastmcp.server.middleware import Middleware
|
|
425
|
+
|
|
426
|
+
class LoggingMiddleware(Middleware):
|
|
427
|
+
async def __call__(self, context, call_next):
|
|
428
|
+
print(f"Request: {context.method}")
|
|
429
|
+
result = await call_next(context)
|
|
430
|
+
print(f"Response: {result}")
|
|
431
|
+
return result
|
|
432
|
+
|
|
433
|
+
mcp.add_middleware(LoggingMiddleware())
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### 从 OpenAPI 生成工具
|
|
437
|
+
|
|
438
|
+
```python
|
|
439
|
+
import httpx
|
|
440
|
+
|
|
441
|
+
async def setup():
|
|
442
|
+
async with httpx.AsyncClient() as client:
|
|
443
|
+
response = await client.get("https://api.example.com/openapi.json")
|
|
444
|
+
spec = response.json()
|
|
445
|
+
|
|
446
|
+
mcp = FastMCP.from_openapi(
|
|
447
|
+
spec,
|
|
448
|
+
name="API Server",
|
|
449
|
+
base_url="https://api.example.com"
|
|
450
|
+
)
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## 故障排查
|
|
454
|
+
|
|
455
|
+
### pipx 安装失败
|
|
456
|
+
|
|
457
|
+
确保包中定义了 entry point:
|
|
458
|
+
```bash
|
|
459
|
+
# 检查 pyproject.toml 中的 [project.scripts] 部分
|
|
460
|
+
cat pyproject.toml | grep -A 2 "\[project.scripts\]"
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Claude Desktop 无法连接
|
|
464
|
+
|
|
465
|
+
1. 检查配置文件路径是否正确
|
|
466
|
+
2. 确保命令路径使用绝对路径
|
|
467
|
+
3. 重启 Claude Desktop
|
|
468
|
+
4. 查看 Claude Desktop 的日志文件
|
|
469
|
+
|
|
470
|
+
### 开发模式下找不到模块
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
# 确保在虚拟环境中
|
|
474
|
+
source .venv/bin/activate
|
|
475
|
+
|
|
476
|
+
# 重新安装
|
|
477
|
+
pip install -e .
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
## 贡献
|
|
481
|
+
|
|
482
|
+
欢迎贡献!请随时提交 Issue 或 Pull Request。
|
|
483
|
+
|
|
484
|
+
## 许可证
|
|
485
|
+
|
|
486
|
+
MIT License
|
|
487
|
+
|
|
488
|
+
## 相关资源
|
|
489
|
+
|
|
490
|
+
- [Model Context Protocol 官方文档](https://modelcontextprotocol.io)
|
|
491
|
+
- [FastMCP 官方文档](https://gofastmcp.com)
|
|
492
|
+
- [FastMCP GitHub](https://github.com/jlowin/fastmcp)
|
|
493
|
+
- [Claude Desktop](https://claude.ai/download)
|
|
494
|
+
- [Cursor 编辑器](https://cursor.sh)
|