@cloudbase/cloudbase-mcp 1.0.3 → 1.0.5
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 +7 -53
- package/dist/tools/database.js +405 -558
- package/dist/tools/env.js +67 -149
- package/dist/tools/file.js +147 -208
- package/dist/tools/functions.js +109 -218
- package/dist/tools/hosting.js +118 -225
- package/package.json +1 -1
package/dist/tools/database.js
CHANGED
|
@@ -1,155 +1,90 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { z } from "zod";
|
|
38
2
|
import CloudBase from "@cloudbase/manager-node";
|
|
39
3
|
// 初始化CloudBase
|
|
40
|
-
|
|
4
|
+
const cloudbase = new CloudBase({
|
|
41
5
|
secretId: process.env.TENCENTCLOUD_SECRETID,
|
|
42
6
|
secretKey: process.env.TENCENTCLOUD_SECRETKEY,
|
|
43
7
|
envId: process.env.CLOUDBASE_ENV_ID,
|
|
44
8
|
token: process.env.TENCENTCLOUD_SESSIONTOKEN
|
|
45
9
|
});
|
|
46
10
|
// 获取数据库实例ID
|
|
47
|
-
function getDatabaseInstanceId() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
case 0: return [4 /*yield*/, cloudbase.env.getEnvInfo()];
|
|
54
|
-
case 1:
|
|
55
|
-
EnvInfo = (_c.sent()).EnvInfo;
|
|
56
|
-
if (!((_b = (_a = EnvInfo === null || EnvInfo === void 0 ? void 0 : EnvInfo.Databases) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.InstanceId)) {
|
|
57
|
-
throw new Error("无法获取数据库实例ID");
|
|
58
|
-
}
|
|
59
|
-
return [2 /*return*/, EnvInfo.Databases[0].InstanceId];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
11
|
+
async function getDatabaseInstanceId() {
|
|
12
|
+
const { EnvInfo } = await cloudbase.env.getEnvInfo();
|
|
13
|
+
if (!EnvInfo?.Databases?.[0]?.InstanceId) {
|
|
14
|
+
throw new Error("无法获取数据库实例ID");
|
|
15
|
+
}
|
|
16
|
+
return EnvInfo.Databases[0].InstanceId;
|
|
63
17
|
}
|
|
64
18
|
export function registerDatabaseTools(server) {
|
|
65
|
-
var _this = this;
|
|
66
19
|
// 创建云开发数据库集合
|
|
67
20
|
server.tool("createCollection", "创建一个新的云开发数据库集合", {
|
|
68
21
|
collectionName: z.string().describe("云开发数据库集合名称")
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
message: "云开发数据库集合创建失败"
|
|
101
|
-
}, null, 2)
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}];
|
|
105
|
-
case 3: return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}); });
|
|
22
|
+
}, async ({ collectionName }) => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await cloudbase.database.createCollection(collectionName);
|
|
25
|
+
return {
|
|
26
|
+
content: [
|
|
27
|
+
{
|
|
28
|
+
type: "text",
|
|
29
|
+
text: JSON.stringify({
|
|
30
|
+
success: true,
|
|
31
|
+
requestId: result.RequestId,
|
|
32
|
+
message: "云开发数据库集合创建成功"
|
|
33
|
+
}, null, 2)
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: JSON.stringify({
|
|
44
|
+
success: false,
|
|
45
|
+
error: error.message,
|
|
46
|
+
message: "云开发数据库集合创建失败"
|
|
47
|
+
}, null, 2)
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
109
53
|
// 检查云开发数据库集合是否存在
|
|
110
54
|
server.tool("checkCollectionExists", "检查云开发数据库集合是否存在", {
|
|
111
55
|
collectionName: z.string().describe("云开发数据库集合名称")
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
message: "检查云开发数据库集合失败"
|
|
145
|
-
}, null, 2)
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
}];
|
|
149
|
-
case 3: return [2 /*return*/];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}); });
|
|
56
|
+
}, async ({ collectionName }) => {
|
|
57
|
+
try {
|
|
58
|
+
const result = await cloudbase.database.checkCollectionExists(collectionName);
|
|
59
|
+
return {
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: "text",
|
|
63
|
+
text: JSON.stringify({
|
|
64
|
+
success: true,
|
|
65
|
+
exists: result.Exists,
|
|
66
|
+
requestId: result.RequestId,
|
|
67
|
+
message: result.Exists ? "云开发数据库集合已存在" : "云开发数据库集合不存在"
|
|
68
|
+
}, null, 2)
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: JSON.stringify({
|
|
79
|
+
success: false,
|
|
80
|
+
error: error.message,
|
|
81
|
+
message: "检查云开发数据库集合失败"
|
|
82
|
+
}, null, 2)
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
153
88
|
// // 删除云开发数据库集合
|
|
154
89
|
// server.tool(
|
|
155
90
|
// "deleteCollection",
|
|
@@ -207,185 +142,149 @@ export function registerDatabaseTools(server) {
|
|
|
207
142
|
IndexName: z.string()
|
|
208
143
|
})).optional()
|
|
209
144
|
}).describe("更新选项,支持创建和删除索引")
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
message: "云开发数据库集合更新失败"
|
|
242
|
-
}, null, 2)
|
|
243
|
-
}
|
|
244
|
-
]
|
|
245
|
-
}];
|
|
246
|
-
case 3: return [2 /*return*/];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}); });
|
|
145
|
+
}, async ({ collectionName, options }) => {
|
|
146
|
+
try {
|
|
147
|
+
const result = await cloudbase.database.updateCollection(collectionName, options);
|
|
148
|
+
return {
|
|
149
|
+
content: [
|
|
150
|
+
{
|
|
151
|
+
type: "text",
|
|
152
|
+
text: JSON.stringify({
|
|
153
|
+
success: true,
|
|
154
|
+
requestId: result.RequestId,
|
|
155
|
+
message: "云开发数据库集合更新成功"
|
|
156
|
+
}, null, 2)
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
type: "text",
|
|
166
|
+
text: JSON.stringify({
|
|
167
|
+
success: false,
|
|
168
|
+
error: error.message,
|
|
169
|
+
message: "云开发数据库集合更新失败"
|
|
170
|
+
}, null, 2)
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
});
|
|
250
176
|
// 查询云开发数据库集合详情
|
|
251
177
|
server.tool("describeCollection", "获取云开发数据库集合的详细信息", {
|
|
252
178
|
collectionName: z.string().describe("云开发数据库集合名称")
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
message: "获取云开发数据库集合信息失败"
|
|
287
|
-
}, null, 2)
|
|
288
|
-
}
|
|
289
|
-
]
|
|
290
|
-
}];
|
|
291
|
-
case 3: return [2 /*return*/];
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}); });
|
|
179
|
+
}, async ({ collectionName }) => {
|
|
180
|
+
try {
|
|
181
|
+
const result = await cloudbase.database.describeCollection(collectionName);
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "text",
|
|
186
|
+
text: JSON.stringify({
|
|
187
|
+
success: true,
|
|
188
|
+
requestId: result.RequestId,
|
|
189
|
+
indexNum: result.IndexNum,
|
|
190
|
+
indexes: result.Indexes,
|
|
191
|
+
message: "获取云开发数据库集合信息成功"
|
|
192
|
+
}, null, 2)
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return {
|
|
199
|
+
content: [
|
|
200
|
+
{
|
|
201
|
+
type: "text",
|
|
202
|
+
text: JSON.stringify({
|
|
203
|
+
success: false,
|
|
204
|
+
error: error.message,
|
|
205
|
+
message: "获取云开发数据库集合信息失败"
|
|
206
|
+
}, null, 2)
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
295
212
|
// 获取云开发数据库集合列表
|
|
296
213
|
server.tool("listCollections", "获取云开发数据库集合列表", {
|
|
297
214
|
offset: z.number().optional().describe("偏移量"),
|
|
298
215
|
limit: z.number().optional().describe("返回数量限制")
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
message: "获取云开发数据库集合列表失败"
|
|
336
|
-
}, null, 2)
|
|
337
|
-
}
|
|
338
|
-
]
|
|
339
|
-
}];
|
|
340
|
-
case 3: return [2 /*return*/];
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}); });
|
|
216
|
+
}, async ({ offset, limit }) => {
|
|
217
|
+
try {
|
|
218
|
+
const result = await cloudbase.database.listCollections({
|
|
219
|
+
MgoOffset: offset,
|
|
220
|
+
MgoLimit: limit
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
type: "text",
|
|
226
|
+
text: JSON.stringify({
|
|
227
|
+
success: true,
|
|
228
|
+
requestId: result.RequestId,
|
|
229
|
+
collections: result.Collections,
|
|
230
|
+
pager: result.Pager,
|
|
231
|
+
message: "获取云开发数据库集合列表成功"
|
|
232
|
+
}, null, 2)
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
return {
|
|
239
|
+
content: [
|
|
240
|
+
{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: JSON.stringify({
|
|
243
|
+
success: false,
|
|
244
|
+
error: error.message,
|
|
245
|
+
message: "获取云开发数据库集合列表失败"
|
|
246
|
+
}, null, 2)
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
});
|
|
344
252
|
// 检查索引是否存在
|
|
345
253
|
server.tool("checkIndexExists", "检查索引是否存在", {
|
|
346
254
|
collectionName: z.string().describe("云开发数据库集合名称"),
|
|
347
255
|
indexName: z.string().describe("索引名称")
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
message: "检查索引失败"
|
|
381
|
-
}, null, 2)
|
|
382
|
-
}
|
|
383
|
-
]
|
|
384
|
-
}];
|
|
385
|
-
case 3: return [2 /*return*/];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
}); });
|
|
256
|
+
}, async ({ collectionName, indexName }) => {
|
|
257
|
+
try {
|
|
258
|
+
const result = await cloudbase.database.checkIndexExists(collectionName, indexName);
|
|
259
|
+
return {
|
|
260
|
+
content: [
|
|
261
|
+
{
|
|
262
|
+
type: "text",
|
|
263
|
+
text: JSON.stringify({
|
|
264
|
+
success: true,
|
|
265
|
+
exists: result.Exists,
|
|
266
|
+
requestId: result.RequestId,
|
|
267
|
+
message: result.Exists ? "索引已存在" : "索引不存在"
|
|
268
|
+
}, null, 2)
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
return {
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: "text",
|
|
278
|
+
text: JSON.stringify({
|
|
279
|
+
success: false,
|
|
280
|
+
error: error.message,
|
|
281
|
+
message: "检查索引失败"
|
|
282
|
+
}, null, 2)
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
});
|
|
389
288
|
// // 导入数据
|
|
390
289
|
// server.tool(
|
|
391
290
|
// "importData",
|
|
@@ -528,101 +427,82 @@ export function registerDatabaseTools(server) {
|
|
|
528
427
|
// }
|
|
529
428
|
// );
|
|
530
429
|
// 查询数据分布
|
|
531
|
-
server.tool("distribution", "查询数据库中云开发数据库集合的数据分布情况", {},
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}, null, 2)
|
|
564
|
-
}
|
|
565
|
-
]
|
|
566
|
-
}];
|
|
567
|
-
case 3: return [2 /*return*/];
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}); });
|
|
430
|
+
server.tool("distribution", "查询数据库中云开发数据库集合的数据分布情况", {}, async () => {
|
|
431
|
+
try {
|
|
432
|
+
const result = await cloudbase.database.distribution();
|
|
433
|
+
return {
|
|
434
|
+
content: [
|
|
435
|
+
{
|
|
436
|
+
type: "text",
|
|
437
|
+
text: JSON.stringify({
|
|
438
|
+
success: true,
|
|
439
|
+
requestId: result.RequestId,
|
|
440
|
+
collections: result.Collections,
|
|
441
|
+
message: "获取数据分布成功"
|
|
442
|
+
}, null, 2)
|
|
443
|
+
}
|
|
444
|
+
]
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
return {
|
|
449
|
+
content: [
|
|
450
|
+
{
|
|
451
|
+
type: "text",
|
|
452
|
+
text: JSON.stringify({
|
|
453
|
+
success: false,
|
|
454
|
+
error: error.message,
|
|
455
|
+
message: "获取数据分布失败"
|
|
456
|
+
}, null, 2)
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
});
|
|
571
462
|
// 插入文档
|
|
572
463
|
server.tool("insertDocuments", "向云开发数据库集合中插入一个或多个文档", {
|
|
573
464
|
collectionName: z.string().describe("云开发数据库集合名称"),
|
|
574
465
|
documents: z.array(z.string()).describe("要插入的文档数组,每个文档都是JSON字符串")
|
|
575
|
-
},
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
success: false,
|
|
616
|
-
error: error_8.message,
|
|
617
|
-
message: "文档插入失败"
|
|
618
|
-
}, null, 2)
|
|
619
|
-
}
|
|
620
|
-
]
|
|
621
|
-
}];
|
|
622
|
-
case 4: return [2 /*return*/];
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
}); });
|
|
466
|
+
}, async ({ collectionName, documents }) => {
|
|
467
|
+
try {
|
|
468
|
+
const instanceId = await getDatabaseInstanceId();
|
|
469
|
+
const result = await cloudbase.commonService('flexdb').call({
|
|
470
|
+
Action: 'PutItem',
|
|
471
|
+
Param: {
|
|
472
|
+
TableName: collectionName,
|
|
473
|
+
MgoDocs: documents,
|
|
474
|
+
Tag: instanceId
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
return {
|
|
478
|
+
content: [
|
|
479
|
+
{
|
|
480
|
+
type: "text",
|
|
481
|
+
text: JSON.stringify({
|
|
482
|
+
success: true,
|
|
483
|
+
requestId: result.RequestId,
|
|
484
|
+
insertedIds: result.InsertedIds,
|
|
485
|
+
message: "文档插入成功"
|
|
486
|
+
}, null, 2)
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
return {
|
|
493
|
+
content: [
|
|
494
|
+
{
|
|
495
|
+
type: "text",
|
|
496
|
+
text: JSON.stringify({
|
|
497
|
+
success: false,
|
|
498
|
+
error: error.message,
|
|
499
|
+
message: "文档插入失败"
|
|
500
|
+
}, null, 2)
|
|
501
|
+
}
|
|
502
|
+
]
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
});
|
|
626
506
|
// 查询文档
|
|
627
507
|
server.tool("queryDocuments", "查询云开发数据库集合中的文档", {
|
|
628
508
|
collectionName: z.string().describe("云开发数据库集合名称"),
|
|
@@ -631,62 +511,51 @@ export function registerDatabaseTools(server) {
|
|
|
631
511
|
sort: z.string().optional().describe("排序条件(JSON字符串)"),
|
|
632
512
|
limit: z.number().optional().describe("返回数量限制"),
|
|
633
513
|
offset: z.number().optional().describe("跳过的记录数")
|
|
634
|
-
},
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
success: false,
|
|
680
|
-
error: error_9.message,
|
|
681
|
-
message: "文档查询失败"
|
|
682
|
-
}, null, 2)
|
|
683
|
-
}
|
|
684
|
-
]
|
|
685
|
-
}];
|
|
686
|
-
case 4: return [2 /*return*/];
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
}); });
|
|
514
|
+
}, async ({ collectionName, query, projection, sort, limit, offset }) => {
|
|
515
|
+
try {
|
|
516
|
+
const instanceId = await getDatabaseInstanceId();
|
|
517
|
+
const result = await cloudbase.commonService('flexdb').call({
|
|
518
|
+
Action: 'Query',
|
|
519
|
+
Param: {
|
|
520
|
+
TableName: collectionName,
|
|
521
|
+
MgoQuery: query,
|
|
522
|
+
MgoProjection: projection,
|
|
523
|
+
MgoSort: sort,
|
|
524
|
+
MgoLimit: limit,
|
|
525
|
+
MgoOffset: offset,
|
|
526
|
+
Tag: instanceId
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
return {
|
|
530
|
+
content: [
|
|
531
|
+
{
|
|
532
|
+
type: "text",
|
|
533
|
+
text: JSON.stringify({
|
|
534
|
+
success: true,
|
|
535
|
+
requestId: result.RequestId,
|
|
536
|
+
data: result.Data,
|
|
537
|
+
pager: result.Pager,
|
|
538
|
+
message: "文档查询成功"
|
|
539
|
+
}, null, 2)
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
catch (error) {
|
|
545
|
+
return {
|
|
546
|
+
content: [
|
|
547
|
+
{
|
|
548
|
+
type: "text",
|
|
549
|
+
text: JSON.stringify({
|
|
550
|
+
success: false,
|
|
551
|
+
error: error.message,
|
|
552
|
+
message: "文档查询失败"
|
|
553
|
+
}, null, 2)
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
});
|
|
690
559
|
// 更新文档
|
|
691
560
|
server.tool("updateDocuments", "更新云开发数据库集合中的文档", {
|
|
692
561
|
collectionName: z.string().describe("云开发数据库集合名称"),
|
|
@@ -694,117 +563,95 @@ export function registerDatabaseTools(server) {
|
|
|
694
563
|
update: z.string().describe("更新内容(JSON字符串)"),
|
|
695
564
|
isMulti: z.boolean().optional().describe("是否更新多条记录"),
|
|
696
565
|
upsert: z.boolean().optional().describe("是否在不存在时插入")
|
|
697
|
-
},
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
success: false,
|
|
743
|
-
error: error_10.message,
|
|
744
|
-
message: "文档更新失败"
|
|
745
|
-
}, null, 2)
|
|
746
|
-
}
|
|
747
|
-
]
|
|
748
|
-
}];
|
|
749
|
-
case 4: return [2 /*return*/];
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
}); });
|
|
566
|
+
}, async ({ collectionName, query, update, isMulti, upsert }) => {
|
|
567
|
+
try {
|
|
568
|
+
const instanceId = await getDatabaseInstanceId();
|
|
569
|
+
const result = await cloudbase.commonService('flexdb').call({
|
|
570
|
+
Action: 'UpdateItem',
|
|
571
|
+
Param: {
|
|
572
|
+
TableName: collectionName,
|
|
573
|
+
MgoQuery: query,
|
|
574
|
+
MgoUpdate: update,
|
|
575
|
+
MgoIsMulti: isMulti,
|
|
576
|
+
MgoUpsert: upsert,
|
|
577
|
+
Tag: instanceId
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
return {
|
|
581
|
+
content: [
|
|
582
|
+
{
|
|
583
|
+
type: "text",
|
|
584
|
+
text: JSON.stringify({
|
|
585
|
+
success: true,
|
|
586
|
+
requestId: result.RequestId,
|
|
587
|
+
modifiedCount: result.ModifiedNum,
|
|
588
|
+
matchedCount: result.MatchedNum,
|
|
589
|
+
upsertedId: result.UpsertedId,
|
|
590
|
+
message: "文档更新成功"
|
|
591
|
+
}, null, 2)
|
|
592
|
+
}
|
|
593
|
+
]
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
return {
|
|
598
|
+
content: [
|
|
599
|
+
{
|
|
600
|
+
type: "text",
|
|
601
|
+
text: JSON.stringify({
|
|
602
|
+
success: false,
|
|
603
|
+
error: error.message,
|
|
604
|
+
message: "文档更新失败"
|
|
605
|
+
}, null, 2)
|
|
606
|
+
}
|
|
607
|
+
]
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
});
|
|
753
611
|
// 删除文档
|
|
754
612
|
server.tool("deleteDocuments", "删除云开发数据库集合中的文档", {
|
|
755
613
|
collectionName: z.string().describe("云开发数据库集合名称"),
|
|
756
614
|
query: z.string().describe("查询条件(JSON字符串)"),
|
|
757
615
|
isMulti: z.boolean().optional().describe("是否删除多条记录")
|
|
758
|
-
},
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
instanceId
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
success: false,
|
|
800
|
-
error: error_11.message,
|
|
801
|
-
message: "文档删除失败"
|
|
802
|
-
}, null, 2)
|
|
803
|
-
}
|
|
804
|
-
]
|
|
805
|
-
}];
|
|
806
|
-
case 4: return [2 /*return*/];
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
}); });
|
|
616
|
+
}, async ({ collectionName, query, isMulti }) => {
|
|
617
|
+
try {
|
|
618
|
+
const instanceId = await getDatabaseInstanceId();
|
|
619
|
+
const result = await cloudbase.commonService('flexdb').call({
|
|
620
|
+
Action: 'DeleteItem',
|
|
621
|
+
Param: {
|
|
622
|
+
TableName: collectionName,
|
|
623
|
+
MgoQuery: query,
|
|
624
|
+
MgoIsMulti: isMulti,
|
|
625
|
+
Tag: instanceId
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
return {
|
|
629
|
+
content: [
|
|
630
|
+
{
|
|
631
|
+
type: "text",
|
|
632
|
+
text: JSON.stringify({
|
|
633
|
+
success: true,
|
|
634
|
+
requestId: result.RequestId,
|
|
635
|
+
deleted: result.Deleted,
|
|
636
|
+
message: "文档删除成功"
|
|
637
|
+
}, null, 2)
|
|
638
|
+
}
|
|
639
|
+
]
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
return {
|
|
644
|
+
content: [
|
|
645
|
+
{
|
|
646
|
+
type: "text",
|
|
647
|
+
text: JSON.stringify({
|
|
648
|
+
success: false,
|
|
649
|
+
error: error.message,
|
|
650
|
+
message: "文档删除失败"
|
|
651
|
+
}, null, 2)
|
|
652
|
+
}
|
|
653
|
+
]
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
});
|
|
810
657
|
}
|