@cloudbase/cloudbase-mcp 1.4.2 → 1.6.0
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/README.md +124 -51
- package/dist/index.js +4 -1
- package/dist/tools/functions.js +20 -2
- package/dist/tools/rag.js +4 -3
- package/dist/tools/setup.js +186 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -22,10 +22,15 @@
|
|
|
22
22
|
[](https://github.com/TencentCloudBase/CloudBase-AI-ToolKit/commits)
|
|
23
23
|
[](https://github.com/TencentCloudBase/CloudBase-AI-ToolKit/graphs/contributors)
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
[](https://cnb.cool/tencent/cloud/cloudbase/CloudBase-AI-ToolKit)
|
|
27
|
+
|
|
25
28
|
当你在**Cursor/ VSCode GitHub Copilot/WinSurf/CodeBuddy**等AI编程工具里写代码时,它能自动帮你生成可直接部署的前后端应用+小程序,并一键发布到腾讯云开发 CloudBase。
|
|
26
29
|
|
|
27
30
|
<a href="https://www.producthunt.com/posts/cloudbase-ai-tookit?embed=true&utm_source=badge-featured&utm_medium=badge&utm_source=badge-cloudbase-ai-tookit" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=971451&theme=light&t=1748519563832" alt="CloudBase AI Tookit - Prompt to Production: Full-stack, DB & functions—zero setup. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
28
31
|
|
|
32
|
+
[](https://cursor.com/install-mcp?name=CloudBase&config=eyJjb21tYW5kIjoibnB4IEBjbG91ZGJhc2UvY2xvdWRiYXNlLW1jcEBsYXRlc3QiLCJlbnYiOnsiQ0xPVURCQVNFX0VOVl9JRCI6IllPVVJfRU5WX0lEIn0sImRpc2FibGVkIjpmYWxzZX0%3D)
|
|
33
|
+
|
|
29
34
|
|
|
30
35
|
|
|
31
36
|
### 🚀 三大核心能力
|
|
@@ -51,12 +56,13 @@ https://github.com/user-attachments/assets/2b402fa6-c5c4-495a-b85b-f5d4a25daa4a
|
|
|
51
56
|
| **📱 全栈应用支持** | Web + 小程序 + 数据库 + 后端一体化 | 支持小程序/web 等多种应用形式,提供后端托管和数据库 |
|
|
52
57
|
| **🔧 智能修复** | AI 自动查看日志并修复问题 | 降低运维成本 |
|
|
53
58
|
| **⚡ 极速体验** | 国内 CDN 加速 | 比海外平台访问速度更快 |
|
|
59
|
+
| **📚 智能知识库检索** | 内置支持云开发、微信小程序等专业知识库的智能向量检索 |
|
|
54
60
|
|
|
55
61
|
|
|
56
62
|
## 🚀 快速开始
|
|
57
63
|
|
|
58
64
|
|
|
59
|
-
### 0
|
|
65
|
+
### 0. 前置条件
|
|
60
66
|
|
|
61
67
|
#### 安装 AI 开发工具
|
|
62
68
|
例如 [Cursor](https://www.cursor.com/) | [WindSurf](https://windsurf.com/editor) | [CodeBuddy](https://copilot.tencent.com/) 等
|
|
@@ -66,29 +72,48 @@ https://github.com/user-attachments/assets/2b402fa6-c5c4-495a-b85b-f5d4a25daa4a
|
|
|
66
72
|
2. 在控制台「概览」页面右侧获取 **环境ID**
|
|
67
73
|
(后续部署需要此 ID)
|
|
68
74
|
|
|
69
|
-
### 1.
|
|
75
|
+
### 1. 快速初始化或增强你的项目
|
|
76
|
+
|
|
77
|
+
我们为你准备了内置云开发最佳实践和 AI IDE 规则的项目模板,推荐如下两种方式:
|
|
78
|
+
|
|
79
|
+
#### 🚀 新项目推荐
|
|
80
|
+
|
|
81
|
+
选择适合你的模板,一键初始化:
|
|
82
|
+
|
|
83
|
+
- **React Web 应用 + 云开发模板**
|
|
84
|
+
[下载代码包](https://static.cloudbase.net/cloudbase-examples/web-cloudbase-react-template.zip?v=2025053001) | [开源代码地址](https://github.com/TencentCloudBase/awesome-cloudbase-examples/tree/master/web/cloudbase-react-template)
|
|
85
|
+
|
|
86
|
+
- **微信小程序 + 云开发模板**
|
|
87
|
+
[下载代码包](https://static.cloudbase.net/cloudbase-examples/miniprogram-cloudbase-miniprogram-template.zip?v=2025053001) | [开源代码地址](https://github.com/TencentCloudBase/awesome-cloudbase-examples/tree/master/miniprogram/cloudbase-miniprogram-template)
|
|
88
|
+
|
|
89
|
+
- **通用云开发模板**
|
|
90
|
+
[下载代码包](https://static.cloudbase.net/cloudbase-examples/web-cloudbase-project.zip) | [开源代码地址](https://github.com/TencentCloudBase/awesome-cloudbase-examples/tree/master/web/cloudbase-project)
|
|
70
91
|
|
|
71
|
-
|
|
92
|
+
#### 🛠️ 已有项目增强
|
|
72
93
|
|
|
73
|
-
|
|
94
|
+
如果你已经有自己的项目,只需在配置好 MCP 后,让 AI 调用 `downloadTemplate` 工具,选择 `rules` 模板,即可一键下载并补全 AI 编辑器规则配置到当前项目目录,无需手动操作。
|
|
74
95
|
|
|
75
|
-
- React Web应用+云开发模板:[下载代码包](https://static.cloudbase.net/cloudbase-examples/web-cloudbase-react-template.zip?v=2025053001) | [开源代码地址](https://github.com/TencentCloudBase/awesome-cloudbase-examples/tree/master/web/cloudbase-react-template)
|
|
76
|
-
- 小程序+云开发模板:[下载代码包](https://static.cloudbase.net/cloudbase-examples/miniprogram-cloudbase-miniprogram-template.zip?v=2025053001) | [开源代码地址](https://github.com/TencentCloudBase/awesome-cloudbase-examples/tree/master/miniprogram/cloudbase-miniprogram-template)
|
|
77
96
|
|
|
78
97
|
### 2. 配置你的 AI IDE
|
|
79
98
|
|
|
99
|
+
> 💡 **使用提示**:如果你在 Cursor 等工具中开启了自动执行(auto-run)模式,建议在"Command denylist"中添加敏感命令,避免自动运行如删除数据等敏感的操作
|
|
100
|
+
>
|
|
101
|
+
> 默认模式下需要手动确认执行,较为安全。
|
|
102
|
+
|
|
80
103
|
以下工具均支持 CloudBase AI ToolKit,可根据你的开发环境选择合适的工具:
|
|
81
104
|
|
|
82
105
|
| 工具 | 支持平台 |
|
|
83
106
|
|------|----------|
|
|
84
107
|
| [Cursor](https://cursor.com/) | 独立 IDE|
|
|
85
108
|
| [WindSurf](https://windsurf.com/editor) | 独立 IDE,VSCode、JetBrains 插件 |
|
|
86
|
-
| [CodeBuddy](https://copilot.tencent.com/) | VS Code
|
|
109
|
+
| [CodeBuddy](https://copilot.tencent.com/) | VS Code、JetBrains、微信开发者工具插件 |
|
|
87
110
|
| [CLINE](https://cline.so/) | VS Code 插件 |
|
|
88
111
|
| [GitHub Copilot](https://github.com/features/copilot) | VS Code 插件 |
|
|
89
112
|
| [Trae](https://www.trae.ai/) | 独立 IDE |
|
|
90
|
-
| [通义灵码](https://tongyi.aliyun.com/lingma) | 独立 IDE,VS Code
|
|
113
|
+
| [通义灵码](https://tongyi.aliyun.com/lingma) | 独立 IDE,VS Code、 JetBrains插件 |
|
|
91
114
|
| [RooCode](https://roocode.com/) | VS Code插件 |
|
|
115
|
+
| [文心快码](https://comate.baidu.com/) | VS Code、JetBrains插件|
|
|
116
|
+
|
|
92
117
|
|
|
93
118
|
选择工具后,请按照下方对应的配置说明进行设置。每个工具都需要配置云开发环境 ID 才能使用 MCP 功能。如果你还没有云开发环境,请先[开通云开发环境](#0前置条件)。
|
|
94
119
|
|
|
@@ -102,6 +127,10 @@ https://github.com/user-attachments/assets/2b402fa6-c5c4-495a-b85b-f5d4a25daa4a
|
|
|
102
127
|
|
|
103
128
|
#### 步骤2:配置 MCP
|
|
104
129
|
|
|
130
|
+
模板中已经包含 mcp 配置,如果不是从模板开始,可以点击下方按钮安装到 Cursor 中
|
|
131
|
+
|
|
132
|
+
[](https://cursor.com/install-mcp?name=CloudBase&config=eyJjb21tYW5kIjoibnB4IEBjbG91ZGJhc2UvY2xvdWRiYXNlLW1jcEBsYXRlc3QiLCJlbnYiOnsiQ0xPVURCQVNFX0VOVl9JRCI6IllPVVJfRU5WX0lEIn0sImRpc2FibGVkIjpmYWxzZX0%3D)
|
|
133
|
+
|
|
105
134
|
1. 请修改项目中的 `.cursor/mcp.json` ,填写你的云开发环境 ID
|
|
106
135
|
|
|
107
136
|
```json
|
|
@@ -399,6 +428,46 @@ https://github.com/user-attachments/assets/2b402fa6-c5c4-495a-b85b-f5d4a25daa4a
|
|
|
399
428
|
|
|
400
429
|
</details>
|
|
401
430
|
|
|
431
|
+
<details>
|
|
432
|
+
<summary><strong>🤖 文心快码(Baidu Comate) 配置</strong></summary>
|
|
433
|
+
|
|
434
|
+
#### 步骤1:自动应用 AI 规则
|
|
435
|
+
|
|
436
|
+
模板中已包含 `.comate/rules` 目录,文心快码会自动识别云开发最佳实践
|
|
437
|
+
|
|
438
|
+
#### 步骤2:配置 MCP
|
|
439
|
+
|
|
440
|
+
模板中已包含 `.comate/mcp.json` 目录,文心快码会自动识别项目中的 MCP
|
|
441
|
+
|
|
442
|
+
**配置云开发 MCP Server**
|
|
443
|
+
|
|
444
|
+
在文心快码的 Zulu 模式中,选择 MCP 配置-设置,在打开的文件中修改 MCP 配置
|
|
445
|
+
|
|
446
|
+
其中 CLOUDBASE_ENV_ID 填写你的云开发环境 ID
|
|
447
|
+
|
|
448
|
+
```json
|
|
449
|
+
{
|
|
450
|
+
"mcpServers": {
|
|
451
|
+
"cloudbase": {
|
|
452
|
+
"command": "npx",
|
|
453
|
+
"args": [
|
|
454
|
+
"@cloudbase/cloudbase-mcp@latest"
|
|
455
|
+
],
|
|
456
|
+
"env": {
|
|
457
|
+
"CLOUDBASE_ENV_ID": "你的云开发环境ID"
|
|
458
|
+
},
|
|
459
|
+
"disabled": false
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
#### 步骤3:使用 AI 对话
|
|
466
|
+
|
|
467
|
+
在对话窗口中切换到 Zulu 模式,然后使用 AI 进行代码生成和自动化操作
|
|
468
|
+
|
|
469
|
+
</details>
|
|
470
|
+
|
|
402
471
|
### 3. 开始开发
|
|
403
472
|
|
|
404
473
|
确认 AI 已经连接到云开发
|
|
@@ -505,11 +574,57 @@ AI 会自动:
|
|
|
505
574
|
|
|
506
575
|
---
|
|
507
576
|
|
|
577
|
+
## 🌟 为什么选择 CloudBase?
|
|
578
|
+
|
|
579
|
+
- **⚡ 极速部署**:国内节点,访问速度比海外更快
|
|
580
|
+
- **🛡️ 稳定可靠**:330 万开发者选择的 Serverless 平台
|
|
581
|
+
- **🔧 开发友好**:专为AI时代设计的全栈平台
|
|
582
|
+
- **💰 成本优化**:Serverless 架构更具弹性,新用户开发期间可以免费体验
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
## 📋 常见问题 FAQ
|
|
586
|
+
|
|
587
|
+
如有迁移、集成等常见疑问,请查阅 [FAQ 常见问题](./FAQ.md)。
|
|
588
|
+
|
|
589
|
+
## 💬 技术交流群
|
|
590
|
+
|
|
591
|
+
遇到问题或想要交流经验?加入我们的技术社区!
|
|
592
|
+
|
|
593
|
+
### 🔥 微信交流群
|
|
594
|
+
|
|
595
|
+
<div align="center">
|
|
596
|
+
<img src="https://7463-tcb-advanced-a656fc-1257967285.tcb.qcloud.la/mcp/toolkit-qrcode.png" width="200" alt="微信群二维码">
|
|
597
|
+
<br>
|
|
598
|
+
<i>扫码加入微信技术交流群</i>
|
|
599
|
+
</div>
|
|
600
|
+
|
|
601
|
+
**群内你可以:**
|
|
602
|
+
- 💡 分享你的 AI + 云开发项目
|
|
603
|
+
- 🤝 技术交流和开发问题沟通
|
|
604
|
+
- 📢 获取最新功能更新和最佳实践
|
|
605
|
+
- 🎯 参与产品功能讨论和建议
|
|
606
|
+
|
|
607
|
+
### 📱 其他交流方式
|
|
608
|
+
|
|
609
|
+
| 平台 | 链接 | 说明 |
|
|
610
|
+
|------|------|------|
|
|
611
|
+
| **官方文档** | [📖 查看文档](https://docs.cloudbase.net/) | 完整的云开发文档 |
|
|
612
|
+
| **Issue 反馈** | [🐛 提交问题](https://github.com/TencentCloudBase/CloudBase-AI-ToolKit/issues) | Bug 反馈和功能请求 |
|
|
613
|
+
|
|
614
|
+
### 🎉 社区活动
|
|
615
|
+
|
|
616
|
+
- **每周技术分享**:群内定期分享 AI + 云开发最佳实践
|
|
617
|
+
- **项目展示**:展示你用 AI 开发的精彩项目
|
|
618
|
+
- **问题答疑**:腾讯云开发团队成员在线答疑
|
|
619
|
+
- **新功能预览**:第一时间体验最新功能
|
|
620
|
+
|
|
621
|
+
|
|
508
622
|
## 🛠️ 云开发 MCP 工具一览
|
|
509
623
|
|
|
510
624
|
| 工具名称 | 功能简介 |
|
|
511
625
|
|----------|----------|
|
|
512
626
|
| logout | 登出当前云开发账户 |
|
|
627
|
+
| downloadTemplate | 下载CloudBase项目模板(React、小程序、AI编辑器配置等) |
|
|
513
628
|
| listEnvs | 获取所有云开发环境信息 |
|
|
514
629
|
| getEnvAuthDomains | 获取云开发环境的合法域名列表 |
|
|
515
630
|
| createEnvDomain | 为云开发环境添加安全域名 |
|
|
@@ -547,7 +662,7 @@ AI 会自动:
|
|
|
547
662
|
| deleteFunctionTrigger | 删除云函数触发器 |
|
|
548
663
|
| downloadRemoteFile | 下载远程文件到本地临时文件 |
|
|
549
664
|
| uploadFile | 上传文件到云存储(适合存储业务数据文件) |
|
|
550
|
-
|
|
|
665
|
+
| searchKnowledgeBase | 智能检索云开发知识库(支持云开发与云函数),通过向量搜索快速获取专业文档与答案。|
|
|
551
666
|
|
|
552
667
|
## 🏗️ 架构原理
|
|
553
668
|
|
|
@@ -566,45 +681,6 @@ graph TD
|
|
|
566
681
|
J --> K[Web/小程序/API]
|
|
567
682
|
```
|
|
568
683
|
|
|
569
|
-
## 🌟 为什么选择 CloudBase?
|
|
570
|
-
|
|
571
|
-
- **⚡ 极速部署**:国内节点,访问速度比海外更快
|
|
572
|
-
- **🛡️ 稳定可靠**:330 万开发者选择的 Serverless 平台
|
|
573
|
-
- **🔧 开发友好**:专为AI时代设计的全栈平台
|
|
574
|
-
- **💰 成本优化**:Serverless 架构更具弹性,新用户开发期间可以免费体验
|
|
575
|
-
|
|
576
|
-
## 💬 技术交流群
|
|
577
|
-
|
|
578
|
-
遇到问题或想要交流经验?加入我们的技术社区!
|
|
579
|
-
|
|
580
|
-
### 🔥 微信交流群
|
|
581
|
-
|
|
582
|
-
<div align="center">
|
|
583
|
-
<img src="https://7463-tcb-advanced-a656fc-1257967285.tcb.qcloud.la/mcp/toolkit-qrcode.png" width="200" alt="微信群二维码">
|
|
584
|
-
<br>
|
|
585
|
-
<i>扫码加入微信技术交流群</i>
|
|
586
|
-
</div>
|
|
587
|
-
|
|
588
|
-
**群内你可以:**
|
|
589
|
-
- 💡 分享你的 AI + 云开发项目
|
|
590
|
-
- 🤝 技术交流和开发问题沟通
|
|
591
|
-
- 📢 获取最新功能更新和最佳实践
|
|
592
|
-
- 🎯 参与产品功能讨论和建议
|
|
593
|
-
|
|
594
|
-
### 📱 其他交流方式
|
|
595
|
-
|
|
596
|
-
| 平台 | 链接 | 说明 |
|
|
597
|
-
|------|------|------|
|
|
598
|
-
| **官方文档** | [📖 查看文档](https://docs.cloudbase.net/) | 完整的云开发文档 |
|
|
599
|
-
| **Issue 反馈** | [🐛 提交问题](https://github.com/TencentCloudBase/CloudBase-AI-ToolKit/issues) | Bug 反馈和功能请求 |
|
|
600
|
-
|
|
601
|
-
### 🎉 社区活动
|
|
602
|
-
|
|
603
|
-
- **每周技术分享**:群内定期分享 AI + 云开发最佳实践
|
|
604
|
-
- **项目展示**:展示你用 AI 开发的精彩项目
|
|
605
|
-
- **问题答疑**:腾讯云开发团队成员在线答疑
|
|
606
|
-
- **新功能预览**:第一时间体验最新功能
|
|
607
|
-
|
|
608
684
|
## 🤝 贡献指南
|
|
609
685
|
|
|
610
686
|
欢迎提交 Issue 和 Pull Request!请查看我们的[贡献指南](CONTRIBUTING.md)了解如何参与项目开发。
|
|
@@ -617,6 +693,3 @@ graph TD
|
|
|
617
693
|
|
|
618
694
|
⭐ 如果这个项目对你有帮助,请给我们一个 Star!
|
|
619
695
|
|
|
620
|
-
## 📋 [常见问题 FAQ](./FAQ.md)
|
|
621
|
-
|
|
622
|
-
如有迁移、集成等常见疑问,请查阅 [FAQ 常见问题](./FAQ.md)。
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { registerHostingTools } from "./tools/hosting.js";
|
|
|
8
8
|
import { registerDownloadTools } from "./tools/download.js";
|
|
9
9
|
import { registerStorageTools } from "./tools/storage.js";
|
|
10
10
|
import { registerRagTools } from './tools/rag.js';
|
|
11
|
+
import { registerSetupTools } from "./tools/setup.js";
|
|
11
12
|
// Create server instance
|
|
12
13
|
const server = new McpServer({
|
|
13
14
|
name: "cloudbase-mcp",
|
|
@@ -33,10 +34,12 @@ registerFunctionTools(server);
|
|
|
33
34
|
registerDownloadTools(server);
|
|
34
35
|
// Register storage tools
|
|
35
36
|
registerStorageTools(server);
|
|
37
|
+
// Register setup tools
|
|
38
|
+
registerSetupTools(server);
|
|
36
39
|
async function main() {
|
|
37
40
|
const transport = new StdioServerTransport();
|
|
38
41
|
await server.connect(transport);
|
|
39
|
-
console.
|
|
42
|
+
console.log("TencentCloudBase MCP Server running on stdio");
|
|
40
43
|
}
|
|
41
44
|
main().catch((error) => {
|
|
42
45
|
console.error("Fatal error in main():", error);
|
package/dist/tools/functions.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { getCloudBaseManager } from '../cloudbase-manager.js';
|
|
3
|
+
// 支持的 Node.js 运行时列表
|
|
4
|
+
export const SUPPORTED_NODEJS_RUNTIMES = [
|
|
5
|
+
'Nodejs 18.15',
|
|
6
|
+
'Nodejs 16.13',
|
|
7
|
+
'Nodejs 14.18',
|
|
8
|
+
'Nodejs 12.16',
|
|
9
|
+
'Nodejs 10.15',
|
|
10
|
+
'Nodejs 8.9(即将下线)',
|
|
11
|
+
];
|
|
12
|
+
export const DEFAULT_NODEJS_RUNTIME = 'Nodejs 18.15';
|
|
3
13
|
export function registerFunctionTools(server) {
|
|
4
14
|
// getFunctionList - 获取云函数列表(推荐)
|
|
5
15
|
server.tool("getFunctionList", "获取云函数列表", {
|
|
@@ -27,7 +37,7 @@ export function registerFunctionTools(server) {
|
|
|
27
37
|
vpcId: z.string(),
|
|
28
38
|
subnetId: z.string()
|
|
29
39
|
}).optional().describe("私有网络配置"),
|
|
30
|
-
runtime: z.string().optional().describe("
|
|
40
|
+
runtime: z.string().optional().describe("运行时环境,可选值:" + SUPPORTED_NODEJS_RUNTIMES.join(',') + ",默认 Nodejs 18.15"),
|
|
31
41
|
installDependency: z.boolean().optional().describe("是否安装依赖,建议传 true"),
|
|
32
42
|
triggers: z.array(z.object({
|
|
33
43
|
name: z.string(),
|
|
@@ -45,6 +55,10 @@ export function registerFunctionTools(server) {
|
|
|
45
55
|
functionRootPath: z.string().optional().describe("函数根目录(云函数目录的父目录),这里需要传操作系统上文件的绝对路径,指定之后可以自动上传这部分的文件作为代码"),
|
|
46
56
|
force: z.boolean().describe("是否覆盖")
|
|
47
57
|
}, async ({ func, functionRootPath, force }) => {
|
|
58
|
+
// 自动填充默认 runtime
|
|
59
|
+
if (!func.runtime) {
|
|
60
|
+
func.runtime = DEFAULT_NODEJS_RUNTIME;
|
|
61
|
+
}
|
|
48
62
|
const cloudbase = await getCloudBaseManager();
|
|
49
63
|
const result = await cloudbase.functions.createFunction({
|
|
50
64
|
func,
|
|
@@ -94,9 +108,13 @@ export function registerFunctionTools(server) {
|
|
|
94
108
|
vpcId: z.string(),
|
|
95
109
|
subnetId: z.string()
|
|
96
110
|
}).optional().describe("VPC配置"),
|
|
97
|
-
runtime: z.string().optional().describe("
|
|
111
|
+
runtime: z.string().optional().describe("运行时(可选值:" + SUPPORTED_NODEJS_RUNTIMES.join(',') + ",默认 Nodejs 18.15)")
|
|
98
112
|
}).describe("函数配置")
|
|
99
113
|
}, async ({ funcParam }) => {
|
|
114
|
+
// 自动填充默认 runtime
|
|
115
|
+
if (!funcParam.runtime) {
|
|
116
|
+
funcParam.runtime = DEFAULT_NODEJS_RUNTIME;
|
|
117
|
+
}
|
|
100
118
|
const cloudbase = await getCloudBaseManager();
|
|
101
119
|
const result = await cloudbase.functions.updateFunctionConfig(funcParam);
|
|
102
120
|
return {
|
package/dist/tools/rag.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
// 1. 枚举定义
|
|
3
|
-
const KnowledgeBaseEnum = z.enum(["cloudbase", "scf"]);
|
|
3
|
+
const KnowledgeBaseEnum = z.enum(["cloudbase", "scf", "miniprogram"]);
|
|
4
4
|
// 2. 枚举到后端 id 的映射
|
|
5
5
|
const KnowledgeBaseIdMap = {
|
|
6
6
|
cloudbase: "ykfzskv4_ad28",
|
|
7
7
|
scf: "scfsczskzyws_4bdc",
|
|
8
|
+
miniprogram: "xcxzskws_25d8",
|
|
8
9
|
};
|
|
9
10
|
// 安全 JSON.parse
|
|
10
11
|
function safeParse(str) {
|
|
@@ -34,9 +35,9 @@ function safeStringify(obj) {
|
|
|
34
35
|
}
|
|
35
36
|
export function registerRagTools(server) {
|
|
36
37
|
// 知识库检索
|
|
37
|
-
server.tool('
|
|
38
|
+
server.tool('searchKnowledgeBase', '云开发知识库智能检索工具,支持云开发与云函数知识的向量查询', {
|
|
38
39
|
threshold: z.number().default(0.5).optional().describe("相似性检索阈值"),
|
|
39
|
-
id: KnowledgeBaseEnum.describe("知识库范围,cloudbase=云开发全量知识,scf
|
|
40
|
+
id: KnowledgeBaseEnum.describe("知识库范围,cloudbase=云开发全量知识,scf=云开发的云函数知识, miniprogram=小程序知识(不包含云开发与云函数知识)"),
|
|
40
41
|
content: z.string().describe("检索内容"),
|
|
41
42
|
options: z.object({
|
|
42
43
|
chunkExpand: z.array(z.number()).min(2).max(2).default([3, 3]).describe("指定返回的文档内容的展开长度,例如 [3,3]代表前后展开长度"),
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as fsPromises from "fs/promises";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import * as os from "os";
|
|
6
|
+
import * as https from "https";
|
|
7
|
+
import * as http from "http";
|
|
8
|
+
import * as unzipper from "unzipper";
|
|
9
|
+
// CloudBase 模板配置
|
|
10
|
+
const TEMPLATES = {
|
|
11
|
+
"react": {
|
|
12
|
+
description: "React + CloudBase 全栈应用模板",
|
|
13
|
+
url: "https://static.cloudbase.net/cloudbase-examples/web-cloudbase-react-template.zip"
|
|
14
|
+
},
|
|
15
|
+
"miniprogram": {
|
|
16
|
+
description: "微信小程序 + 云开发模板",
|
|
17
|
+
url: "https://static.cloudbase.net/cloudbase-examples/miniprogram-cloudbase-miniprogram-template.zip"
|
|
18
|
+
},
|
|
19
|
+
"rules": {
|
|
20
|
+
description: "AI编辑器配置模板(包含所有主流编辑器配置)",
|
|
21
|
+
url: "https://static.cloudbase.net/cloudbase-examples/web-cloudbase-project.zip"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
// 下载文件到临时目录
|
|
25
|
+
async function downloadFile(url, filePath) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const client = url.startsWith('https:') ? https : http;
|
|
28
|
+
client.get(url, (res) => {
|
|
29
|
+
if (res.statusCode === 200) {
|
|
30
|
+
const file = fs.createWriteStream(filePath);
|
|
31
|
+
res.pipe(file);
|
|
32
|
+
file.on('finish', () => {
|
|
33
|
+
file.close();
|
|
34
|
+
resolve();
|
|
35
|
+
});
|
|
36
|
+
file.on('error', reject);
|
|
37
|
+
}
|
|
38
|
+
else if (res.statusCode === 302 || res.statusCode === 301) {
|
|
39
|
+
// 处理重定向
|
|
40
|
+
if (res.headers.location) {
|
|
41
|
+
downloadFile(res.headers.location, filePath).then(resolve).catch(reject);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
reject(new Error('重定向但没有location header'));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
reject(new Error(`下载失败,状态码: ${res.statusCode}`));
|
|
49
|
+
}
|
|
50
|
+
}).on('error', reject);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// 解压ZIP文件
|
|
54
|
+
async function extractZip(zipPath, extractPath) {
|
|
55
|
+
try {
|
|
56
|
+
// 创建解压目录
|
|
57
|
+
await fsPromises.mkdir(extractPath, { recursive: true });
|
|
58
|
+
// 使用 unzipper 库进行解压,兼容性更好
|
|
59
|
+
await fs.createReadStream(zipPath)
|
|
60
|
+
.pipe(unzipper.Extract({ path: extractPath }))
|
|
61
|
+
.promise();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`解压失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 获取目录下所有文件的相对路径列表
|
|
68
|
+
async function getAllFiles(dir, baseDir = dir) {
|
|
69
|
+
const files = [];
|
|
70
|
+
const entries = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const fullPath = path.join(dir, entry.name);
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
const subFiles = await getAllFiles(fullPath, baseDir);
|
|
75
|
+
files.push(...subFiles);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
files.push(path.relative(baseDir, fullPath));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return files;
|
|
82
|
+
}
|
|
83
|
+
// 复制文件,不覆盖已存在的文件
|
|
84
|
+
async function copyFileIfNotExists(src, dest) {
|
|
85
|
+
try {
|
|
86
|
+
// 检查目标文件是否存在
|
|
87
|
+
if (fs.existsSync(dest)) {
|
|
88
|
+
return { copied: false, reason: '文件已存在' };
|
|
89
|
+
}
|
|
90
|
+
// 创建目标目录
|
|
91
|
+
await fsPromises.mkdir(path.dirname(dest), { recursive: true });
|
|
92
|
+
// 复制文件
|
|
93
|
+
await fsPromises.copyFile(src, dest);
|
|
94
|
+
return { copied: true };
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return { copied: false, reason: `复制失败: ${error instanceof Error ? error.message : '未知错误'}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function registerSetupTools(server) {
|
|
101
|
+
server.tool("downloadTemplate", `自动下载并部署CloudBase项目模板。
|
|
102
|
+
|
|
103
|
+
支持的模板:
|
|
104
|
+
- react: React + CloudBase 全栈应用模板
|
|
105
|
+
- miniprogram: 微信小程序 + 云开发模板
|
|
106
|
+
- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置
|
|
107
|
+
|
|
108
|
+
工具会自动下载模板到临时目录,解压后如果检测到WORKSPACE_FOLDER_PATHS环境变量,则复制到项目目录(不覆盖已存在文件)。`, {
|
|
109
|
+
template: z.enum(["react", "miniprogram", "rules"]).describe("要下载的模板类型")
|
|
110
|
+
}, async ({ template }) => {
|
|
111
|
+
try {
|
|
112
|
+
const templateConfig = TEMPLATES[template];
|
|
113
|
+
if (!templateConfig) {
|
|
114
|
+
return {
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
type: "text",
|
|
118
|
+
text: `❌ 不支持的模板类型: ${template}`
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// 创建临时目录
|
|
124
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cloudbase-template-'));
|
|
125
|
+
const zipPath = path.join(tempDir, 'template.zip');
|
|
126
|
+
const extractDir = path.join(tempDir, 'extracted');
|
|
127
|
+
// 下载和解压
|
|
128
|
+
await downloadFile(templateConfig.url, zipPath);
|
|
129
|
+
await extractZip(zipPath, extractDir);
|
|
130
|
+
const extractedFiles = await getAllFiles(extractDir);
|
|
131
|
+
// 检查是否需要复制到项目目录
|
|
132
|
+
const workspaceFolder = process.env.WORKSPACE_FOLDER_PATHS;
|
|
133
|
+
let finalFiles = [];
|
|
134
|
+
let copiedCount = 0;
|
|
135
|
+
let skippedCount = 0;
|
|
136
|
+
const results = [];
|
|
137
|
+
if (workspaceFolder) {
|
|
138
|
+
for (const relativePath of extractedFiles) {
|
|
139
|
+
const srcPath = path.join(extractDir, relativePath);
|
|
140
|
+
const destPath = path.join(workspaceFolder, relativePath);
|
|
141
|
+
const copyResult = await copyFileIfNotExists(srcPath, destPath);
|
|
142
|
+
if (copyResult.copied) {
|
|
143
|
+
copiedCount++;
|
|
144
|
+
finalFiles.push(destPath);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
skippedCount++;
|
|
148
|
+
finalFiles.push(srcPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
results.push(`✅ ${templateConfig.description} 同步完成`);
|
|
152
|
+
results.push(`📁 保存在临时目录: ${extractDir}`);
|
|
153
|
+
results.push(`📊 复制了 ${copiedCount} 个文件${skippedCount > 0 ? `,跳过 ${skippedCount} 个已存在文件` : ''}`);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
finalFiles = extractedFiles.map(relativePath => path.join(extractDir, relativePath));
|
|
157
|
+
results.push(`✅ ${templateConfig.description} 下载完成`);
|
|
158
|
+
results.push(`📁 保存在临时目录: ${extractDir}`);
|
|
159
|
+
}
|
|
160
|
+
// 文件路径列表
|
|
161
|
+
results.push('');
|
|
162
|
+
results.push('📋 文件列表:');
|
|
163
|
+
finalFiles.forEach(filePath => {
|
|
164
|
+
results.push(`${filePath}`);
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
type: "text",
|
|
170
|
+
text: results.join('\n')
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return {
|
|
177
|
+
content: [
|
|
178
|
+
{
|
|
179
|
+
type: "text",
|
|
180
|
+
text: `❌ 下载模板失败: ${error instanceof Error ? error.message : '未知错误'}`
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cloudbase-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "腾讯云开发 MCP Server,支持静态托管/环境查询/",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"@cloudbase/mcp": "^1.0.0-beta.25",
|
|
30
30
|
"@cloudbase/toolbox": "^0.7.5",
|
|
31
31
|
"@modelcontextprotocol/sdk": "1.9.0",
|
|
32
|
+
"@types/unzipper": "^0.10.11",
|
|
33
|
+
"unzipper": "^0.12.3",
|
|
32
34
|
"zod": "^3.24.3"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|