@cloudbase/cloudbase-mcp 1.2.1 → 1.4.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 +55 -7
- package/dist/index.js +3 -0
- package/dist/tools/env.js +5 -5
- package/dist/tools/hosting.js +2 -2
- package/dist/tools/rag.js +108 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,20 @@
|
|
|
45
45
|
|
|
46
46
|
## 🚀 快速开始
|
|
47
47
|
|
|
48
|
+
|
|
49
|
+
### 0.前置条件
|
|
50
|
+
|
|
51
|
+
#### 1. 安装 AI 开发工具
|
|
52
|
+
例如:
|
|
53
|
+
- [Cursor](https://www.cursor.com/)
|
|
54
|
+
- [WindSurf](https://windsurf.com/editor)
|
|
55
|
+
- [CodeBuddy](https://copilot.tencent.com/)
|
|
56
|
+
|
|
57
|
+
#### 2. 开通云开发环境
|
|
58
|
+
1. 访问 [腾讯云开发控制台](https://tcb.cloud.tencent.com/dev)开通环境,新用户可以免费开通体验
|
|
59
|
+
2. 在控制台「概览」页面右侧获取 **环境ID**
|
|
60
|
+
(后续部署需要此 ID)
|
|
61
|
+
|
|
48
62
|
### 1. 使用模板创建项目
|
|
49
63
|
|
|
50
64
|
以下模板已经内置了云开发面向 AI IDE 的规则配置
|
|
@@ -68,7 +82,7 @@
|
|
|
68
82
|
"mcpServers": {
|
|
69
83
|
"cloudbase-mcp": {
|
|
70
84
|
"command": "npx",
|
|
71
|
-
"args": ["@cloudbase/cloudbase-mcp"],
|
|
85
|
+
"args": ["@cloudbase/cloudbase-mcp@latest"],
|
|
72
86
|
"env": {
|
|
73
87
|
"CLOUDBASE_ENV_ID": "你的云开发环境ID"
|
|
74
88
|
}
|
|
@@ -79,7 +93,7 @@
|
|
|
79
93
|
|
|
80
94
|
2. 启用云开发 MCP Server
|
|
81
95
|
|
|
82
|
-
点击 Cursor 客户端右上角的 ⚙️
|
|
96
|
+
点击 Cursor 客户端右上角的 ⚙️ 图标,点击进入之后,选择"MCP",在 MCP Server 页面,找到 cloudbase 右边的开关按钮,点击启用
|
|
83
97
|
|
|
84
98
|
#### 步骤2:添加 AI 规则
|
|
85
99
|
|
|
@@ -92,14 +106,14 @@
|
|
|
92
106
|
|
|
93
107
|
#### 步骤1:配置 MCP
|
|
94
108
|
|
|
95
|
-
点击 windsurf 的 Plugins icon
|
|
109
|
+
点击 windsurf 的 Plugins icon,点击"View raw config",在其中加入 clodubase-mcp,同时设置环境 id
|
|
96
110
|
|
|
97
111
|
```json
|
|
98
112
|
{
|
|
99
113
|
"mcpServers": {
|
|
100
114
|
"cloudbase-mcp": {
|
|
101
115
|
"command": "npx",
|
|
102
|
-
"args": ["@cloudbase/cloudbase-mcp"],
|
|
116
|
+
"args": ["@cloudbase/cloudbase-mcp@latest"],
|
|
103
117
|
"env": {
|
|
104
118
|
"CLOUDBASE_ENV_ID": "你的云开发环境ID"
|
|
105
119
|
}
|
|
@@ -123,7 +137,7 @@
|
|
|
123
137
|
"mcpServers": {
|
|
124
138
|
"cloudbase-mcp": {
|
|
125
139
|
"command": "npx",
|
|
126
|
-
"args": ["@cloudbase/cloudbase-mcp"],
|
|
140
|
+
"args": ["@cloudbase/cloudbase-mcp@latest"],
|
|
127
141
|
"env": {
|
|
128
142
|
"TENCENTCLOUD_SECRETID": "你的腾讯云SecretId",
|
|
129
143
|
"TENCENTCLOUD_SECRETKEY": "你的腾讯云SecretKey",
|
|
@@ -168,7 +182,7 @@ CodeBuddy 需要手动添加规则文件:
|
|
|
168
182
|
"mcpServers": {
|
|
169
183
|
"cloudbase-mcp": {
|
|
170
184
|
"command": "npx",
|
|
171
|
-
"args": ["@cloudbase/cloudbase-mcp"],
|
|
185
|
+
"args": ["@cloudbase/cloudbase-mcp@latest"],
|
|
172
186
|
"env": {
|
|
173
187
|
"CLOUDBASE_ENV_ID": "你的云开发环境ID"
|
|
174
188
|
}
|
|
@@ -289,7 +303,41 @@ graph TD
|
|
|
289
303
|
- **⚡ 极速部署**:国内节点,访问速度比海外更快
|
|
290
304
|
- **🛡️ 稳定可靠**:330 万开发者选择的 Serverless 平台
|
|
291
305
|
- **🔧 开发友好**:专为AI时代设计的全栈平台
|
|
292
|
-
- **💰 成本优化**:Serverless
|
|
306
|
+
- **💰 成本优化**:Serverless 架构更具弹性,新用户开发期间可以免费体验
|
|
307
|
+
|
|
308
|
+
## 💬 技术交流群
|
|
309
|
+
|
|
310
|
+
遇到问题或想要交流经验?加入我们的技术社区!
|
|
311
|
+
|
|
312
|
+
### 🔥 微信交流群
|
|
313
|
+
|
|
314
|
+
<div align="center">
|
|
315
|
+
<img src="https://7463-tcb-advanced-a656fc-1257967285.tcb.qcloud.la/mcp/toolkit-qrcode.png" width="200" alt="微信群二维码">
|
|
316
|
+
<br>
|
|
317
|
+
<i>扫码加入微信技术交流群</i>
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
**群内你可以:**
|
|
321
|
+
- 💡 分享你的 AI + 云开发项目
|
|
322
|
+
- 🤝 技术交流和开发问题沟通
|
|
323
|
+
- 📢 获取最新功能更新和最佳实践
|
|
324
|
+
- 🎯 参与产品功能讨论和建议
|
|
325
|
+
|
|
326
|
+
### 📱 其他交流方式
|
|
327
|
+
|
|
328
|
+
| 平台 | 链接 | 说明 |
|
|
329
|
+
|------|------|------|
|
|
330
|
+
| **官方文档** | [📖 查看文档](https://docs.cloudbase.net/) | 完整的云开发文档 |
|
|
331
|
+
| **Issue 反馈** | [🐛 提交问题](https://github.com/TencentCloudBase/CloudBase-AI-ToolKit/issues) | Bug 反馈和功能请求 |
|
|
332
|
+
|
|
333
|
+
### 🎉 社区活动
|
|
334
|
+
|
|
335
|
+
- **每周技术分享**:群内定期分享 AI + 云开发最佳实践
|
|
336
|
+
- **项目展示**:展示你用 AI 开发的精彩项目
|
|
337
|
+
- **问题答疑**:腾讯云开发团队成员在线答疑
|
|
338
|
+
- **新功能预览**:第一时间体验最新功能
|
|
339
|
+
|
|
340
|
+
> 💡 **提示**:加群时请备注 "CloudBase AI",方便快速通过验证
|
|
293
341
|
|
|
294
342
|
## 🤝 贡献指南
|
|
295
343
|
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { registerDatabaseTools } from "./tools/database.js";
|
|
|
7
7
|
import { registerHostingTools } from "./tools/hosting.js";
|
|
8
8
|
import { registerDownloadTools } from "./tools/download.js";
|
|
9
9
|
import { registerStorageTools } from "./tools/storage.js";
|
|
10
|
+
import { registerRagTools } from './tools/rag.js';
|
|
10
11
|
// Create server instance
|
|
11
12
|
const server = new McpServer({
|
|
12
13
|
name: "cloudbase-mcp",
|
|
@@ -18,6 +19,8 @@ const server = new McpServer({
|
|
|
18
19
|
});
|
|
19
20
|
// Register environment management tools
|
|
20
21
|
registerEnvTools(server);
|
|
22
|
+
// Register RAG tools
|
|
23
|
+
registerRagTools(server);
|
|
21
24
|
// // Register file management tools
|
|
22
25
|
// registerFileTools(server);
|
|
23
26
|
// Register database management tools
|
package/dist/tools/env.js
CHANGED
|
@@ -4,21 +4,21 @@ import { logout } from '../auth.js';
|
|
|
4
4
|
export function registerEnvTools(server) {
|
|
5
5
|
// logout
|
|
6
6
|
server.tool("logout", "登出当前云开发账户", {
|
|
7
|
-
confirm: z.literal("yes").describe("
|
|
7
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
8
8
|
}, async ({ confirm }) => {
|
|
9
9
|
const result = await logout();
|
|
10
10
|
return {
|
|
11
11
|
content: [
|
|
12
12
|
{
|
|
13
13
|
type: "text",
|
|
14
|
-
text:
|
|
14
|
+
text: "success"
|
|
15
15
|
}
|
|
16
16
|
]
|
|
17
17
|
};
|
|
18
18
|
});
|
|
19
19
|
// listEnvs
|
|
20
20
|
server.tool("listEnvs", "获取所有云开发环境信息", {
|
|
21
|
-
confirm: z.literal("yes").describe("
|
|
21
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
22
22
|
}, async () => {
|
|
23
23
|
const cloudbase = await getCloudBaseManager();
|
|
24
24
|
const result = await cloudbase.env.listEnvs();
|
|
@@ -33,7 +33,7 @@ export function registerEnvTools(server) {
|
|
|
33
33
|
});
|
|
34
34
|
// getEnvAuthDomains
|
|
35
35
|
server.tool("getEnvAuthDomains", "获取云开发环境的合法域名列表", {
|
|
36
|
-
confirm: z.literal("yes").describe("
|
|
36
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
37
37
|
}, async () => {
|
|
38
38
|
const cloudbase = await getCloudBaseManager();
|
|
39
39
|
const result = await cloudbase.env.getEnvAuthDomains();
|
|
@@ -78,7 +78,7 @@ export function registerEnvTools(server) {
|
|
|
78
78
|
});
|
|
79
79
|
// getEnvInfo
|
|
80
80
|
server.tool("getEnvInfo", "获取当前云开发环境信息", {
|
|
81
|
-
confirm: z.literal("yes").describe("
|
|
81
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
82
82
|
}, async () => {
|
|
83
83
|
const cloudbase = await getCloudBaseManager();
|
|
84
84
|
const result = await cloudbase.env.getEnvInfo();
|
package/dist/tools/hosting.js
CHANGED
|
@@ -43,7 +43,7 @@ export function registerHostingTools(server) {
|
|
|
43
43
|
});
|
|
44
44
|
// listFiles - 获取文件列表
|
|
45
45
|
server.tool("listFiles", "获取静态网站托管的文件列表", {
|
|
46
|
-
confirm: z.literal("yes").describe("
|
|
46
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
47
47
|
}, async () => {
|
|
48
48
|
const cloudbase = await getCloudBaseManager();
|
|
49
49
|
const result = await cloudbase.hosting.listFiles();
|
|
@@ -165,7 +165,7 @@ export function registerHostingTools(server) {
|
|
|
165
165
|
});
|
|
166
166
|
// getWebsiteConfig - 获取静态网站配置
|
|
167
167
|
server.tool("getWebsiteConfig", "获取静态网站配置", {
|
|
168
|
-
confirm: z.literal("yes").describe("
|
|
168
|
+
confirm: z.literal("yes").describe("确认操作,默认传 yes")
|
|
169
169
|
}, async () => {
|
|
170
170
|
const cloudbase = await getCloudBaseManager();
|
|
171
171
|
const result = await cloudbase.hosting.getWebsiteConfig();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// 1. 枚举定义
|
|
3
|
+
const KnowledgeBaseEnum = z.enum(["cloudbase", "scf"]);
|
|
4
|
+
// 2. 枚举到后端 id 的映射
|
|
5
|
+
const KnowledgeBaseIdMap = {
|
|
6
|
+
cloudbase: "ykfzskv4_ad28",
|
|
7
|
+
scf: "scfsczskzyws_4bdc",
|
|
8
|
+
};
|
|
9
|
+
// 安全 JSON.parse
|
|
10
|
+
function safeParse(str) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(str);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// 安全 JSON.stringify,处理循环引用
|
|
19
|
+
function safeStringify(obj) {
|
|
20
|
+
const seen = new WeakSet();
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(obj, function (key, value) {
|
|
23
|
+
if (typeof value === "object" && value !== null) {
|
|
24
|
+
if (seen.has(value))
|
|
25
|
+
return;
|
|
26
|
+
seen.add(value);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function registerRagTools(server) {
|
|
36
|
+
// 知识库检索
|
|
37
|
+
server.tool('search_knowledge_base', '云开发知识库智能检索工具,支持云开发与云函数知识的向量查询', {
|
|
38
|
+
threshold: z.number().default(0.5).optional().describe("相似性检索阈值"),
|
|
39
|
+
id: KnowledgeBaseEnum.describe("知识库范围,cloudbase=云开发全量知识,scf=云开发的云函数知识"),
|
|
40
|
+
content: z.string().describe("检索内容"),
|
|
41
|
+
options: z.object({
|
|
42
|
+
chunkExpand: z.array(z.number()).min(2).max(2).default([3, 3]).describe("指定返回的文档内容的展开长度,例如 [3,3]代表前后展开长度"),
|
|
43
|
+
}).optional().describe("其他选项"),
|
|
44
|
+
limit: z.number().default(5).optional().describe("指定返回最相似的 Top K 的 K 的值")
|
|
45
|
+
}, async ({ id, content, options: { chunkExpand = [3, 3] } = {}, limit = 5, threshold = 0.5 }) => {
|
|
46
|
+
// 枚举到后端 id 映射
|
|
47
|
+
const backendId = KnowledgeBaseIdMap[id] || id;
|
|
48
|
+
const signInRes = await fetch('https://tcb-advanced-a656fc.api.tcloudbasegateway.com/auth/v1/signin/anonymously', {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
'Content-Type': 'application/json',
|
|
52
|
+
'Accept': 'application/json',
|
|
53
|
+
'x-device-id': 'cloudbase-ai-toolkit'
|
|
54
|
+
},
|
|
55
|
+
body: safeStringify({
|
|
56
|
+
collectionView: backendId,
|
|
57
|
+
options: {
|
|
58
|
+
chunkExpand
|
|
59
|
+
},
|
|
60
|
+
search: {
|
|
61
|
+
content: content,
|
|
62
|
+
limit
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
const token = (await signInRes.json()).access_token;
|
|
67
|
+
const res = await fetch(`https://tcb-advanced-a656fc.api.tcloudbasegateway.com/v1/knowledge/search`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'Authorization': `Bearer ${token}`
|
|
72
|
+
},
|
|
73
|
+
body: safeStringify({
|
|
74
|
+
collectionView: backendId,
|
|
75
|
+
options: {
|
|
76
|
+
chunkExpand
|
|
77
|
+
},
|
|
78
|
+
search: {
|
|
79
|
+
content: content,
|
|
80
|
+
limit
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
const result = await res.json();
|
|
85
|
+
if (result.code) {
|
|
86
|
+
throw new Error(result.message);
|
|
87
|
+
}
|
|
88
|
+
console.log(result);
|
|
89
|
+
return {
|
|
90
|
+
content: [{
|
|
91
|
+
type: "text",
|
|
92
|
+
text: safeStringify(result.data.documents
|
|
93
|
+
.filter((item) => item.score >= threshold)
|
|
94
|
+
.map((item) => {
|
|
95
|
+
return {
|
|
96
|
+
score: item.score,
|
|
97
|
+
fileTile: item.documentSet.fileTitle,
|
|
98
|
+
url: safeParse(item.documentSet.fileMetaData).url,
|
|
99
|
+
paragraphTitle: item.data.paragraphTitle,
|
|
100
|
+
text: `${item.data.pre?.join('\n') || ''}
|
|
101
|
+
${item.data.text}
|
|
102
|
+
${item.data.next?.join('\n') || ''}`,
|
|
103
|
+
};
|
|
104
|
+
}))
|
|
105
|
+
}]
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|