@cloudbase/cloudbase-mcp 1.3.0 → 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/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
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cloudbase-mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "腾讯云开发 MCP Server,支持静态托管/环境查询/",
5
5
  "main": "index.js",
6
6
  "type": "module",