@cloudbase/cloudbase-mcp 1.0.2 → 1.0.3
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 +53 -6
- package/dist/tools/database.js +558 -405
- package/dist/tools/env.js +149 -67
- package/dist/tools/file.js +208 -147
- package/dist/tools/functions.js +218 -109
- package/dist/tools/hosting.js +223 -116
- package/package.json +1 -1
package/dist/tools/hosting.js
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { z } from "zod";
|
|
2
38
|
import CloudBase from "@cloudbase/manager-node";
|
|
3
39
|
// 初始化CloudBase
|
|
4
|
-
|
|
40
|
+
var cloudbase = new CloudBase({
|
|
5
41
|
secretId: process.env.TENCENTCLOUD_SECRETID,
|
|
6
42
|
secretKey: process.env.TENCENTCLOUD_SECRETKEY,
|
|
7
43
|
envId: process.env.CLOUDBASE_ENV_ID,
|
|
8
44
|
token: process.env.TENCENTCLOUD_SESSIONTOKEN
|
|
9
45
|
});
|
|
10
46
|
export function registerHostingTools(server) {
|
|
47
|
+
var _this = this;
|
|
11
48
|
// uploadFiles - 上传文件到静态网站托管
|
|
12
49
|
server.tool("uploadFiles", "上传文件到静态网站托管", {
|
|
13
50
|
localPath: z.string().optional().describe("本地文件或文件夹路径"),
|
|
@@ -17,72 +54,103 @@ export function registerHostingTools(server) {
|
|
|
17
54
|
cloudPath: z.string()
|
|
18
55
|
})).default([]).describe("多文件上传配置"),
|
|
19
56
|
ignore: z.union([z.string(), z.array(z.string())]).optional().describe("忽略文件模式")
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
57
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
58
|
+
var result;
|
|
59
|
+
var localPath = _b.localPath, cloudPath = _b.cloudPath, files = _b.files, ignore = _b.ignore;
|
|
60
|
+
return __generator(this, function (_c) {
|
|
61
|
+
switch (_c.label) {
|
|
62
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.uploadFiles({
|
|
63
|
+
localPath: localPath,
|
|
64
|
+
cloudPath: cloudPath,
|
|
65
|
+
files: files,
|
|
66
|
+
ignore: ignore
|
|
67
|
+
})];
|
|
68
|
+
case 1:
|
|
69
|
+
result = _c.sent();
|
|
70
|
+
return [2 /*return*/, {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: "text",
|
|
74
|
+
text: JSON.stringify(result, null, 2)
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}];
|
|
78
|
+
}
|
|
26
79
|
});
|
|
27
|
-
|
|
28
|
-
content: [
|
|
29
|
-
{
|
|
30
|
-
type: "text",
|
|
31
|
-
text: JSON.stringify(result, null, 2)
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
};
|
|
35
|
-
});
|
|
80
|
+
}); });
|
|
36
81
|
// listFiles - 获取文件列表
|
|
37
|
-
server.tool("listFiles", "获取静态网站托管的文件列表", {},
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
82
|
+
server.tool("listFiles", "获取静态网站托管的文件列表", {}, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
+
var result;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.listFiles()];
|
|
87
|
+
case 1:
|
|
88
|
+
result = _a.sent();
|
|
89
|
+
return [2 /*return*/, {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: JSON.stringify(result, null, 2)
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); });
|
|
48
100
|
// deleteFiles - 删除文件
|
|
49
101
|
server.tool("deleteFiles", "删除静态网站托管的文件或文件夹", {
|
|
50
102
|
cloudPath: z.string().describe("云端文件或文件夹路径"),
|
|
51
103
|
isDir: z.boolean().default(false).describe("是否为文件夹")
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
104
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
105
|
+
var result;
|
|
106
|
+
var cloudPath = _b.cloudPath, isDir = _b.isDir;
|
|
107
|
+
return __generator(this, function (_c) {
|
|
108
|
+
switch (_c.label) {
|
|
109
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.deleteFiles({
|
|
110
|
+
cloudPath: cloudPath,
|
|
111
|
+
isDir: isDir
|
|
112
|
+
})];
|
|
113
|
+
case 1:
|
|
114
|
+
result = _c.sent();
|
|
115
|
+
return [2 /*return*/, {
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: "text",
|
|
119
|
+
text: JSON.stringify(result, null, 2)
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}];
|
|
123
|
+
}
|
|
56
124
|
});
|
|
57
|
-
|
|
58
|
-
content: [
|
|
59
|
-
{
|
|
60
|
-
type: "text",
|
|
61
|
-
text: JSON.stringify(result, null, 2)
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
};
|
|
65
|
-
});
|
|
125
|
+
}); });
|
|
66
126
|
// findFiles - 搜索文件
|
|
67
127
|
server.tool("findFiles", "搜索静态网站托管的文件", {
|
|
68
128
|
prefix: z.string().describe("匹配前缀"),
|
|
69
129
|
marker: z.string().optional().describe("起始对象键标记"),
|
|
70
130
|
maxKeys: z.number().optional().describe("单次返回最大条目数")
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
131
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
132
|
+
var result;
|
|
133
|
+
var prefix = _b.prefix, marker = _b.marker, maxKeys = _b.maxKeys;
|
|
134
|
+
return __generator(this, function (_c) {
|
|
135
|
+
switch (_c.label) {
|
|
136
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.findFiles({
|
|
137
|
+
prefix: prefix,
|
|
138
|
+
marker: marker,
|
|
139
|
+
maxKeys: maxKeys
|
|
140
|
+
})];
|
|
141
|
+
case 1:
|
|
142
|
+
result = _c.sent();
|
|
143
|
+
return [2 /*return*/, {
|
|
144
|
+
content: [
|
|
145
|
+
{
|
|
146
|
+
type: "text",
|
|
147
|
+
text: JSON.stringify(result, null, 2)
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}];
|
|
151
|
+
}
|
|
76
152
|
});
|
|
77
|
-
|
|
78
|
-
content: [
|
|
79
|
-
{
|
|
80
|
-
type: "text",
|
|
81
|
-
text: JSON.stringify(result, null, 2)
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
};
|
|
85
|
-
});
|
|
153
|
+
}); });
|
|
86
154
|
// // setWebsiteDocument - 配置静态网站文档
|
|
87
155
|
// server.tool(
|
|
88
156
|
// "setWebsiteDocument",
|
|
@@ -117,64 +185,95 @@ export function registerHostingTools(server) {
|
|
|
117
185
|
server.tool("createHostingDomain", "绑定自定义域名", {
|
|
118
186
|
domain: z.string().describe("自定义域名"),
|
|
119
187
|
certId: z.string().describe("证书ID")
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
188
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
189
|
+
var result;
|
|
190
|
+
var domain = _b.domain, certId = _b.certId;
|
|
191
|
+
return __generator(this, function (_c) {
|
|
192
|
+
switch (_c.label) {
|
|
193
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.CreateHostingDomain({
|
|
194
|
+
domain: domain,
|
|
195
|
+
certId: certId
|
|
196
|
+
})];
|
|
197
|
+
case 1:
|
|
198
|
+
result = _c.sent();
|
|
199
|
+
return [2 /*return*/, {
|
|
200
|
+
content: [
|
|
201
|
+
{
|
|
202
|
+
type: "text",
|
|
203
|
+
text: JSON.stringify(result, null, 2)
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}];
|
|
207
|
+
}
|
|
124
208
|
});
|
|
125
|
-
|
|
126
|
-
content: [
|
|
127
|
-
{
|
|
128
|
-
type: "text",
|
|
129
|
-
text: JSON.stringify(result, null, 2)
|
|
130
|
-
}
|
|
131
|
-
]
|
|
132
|
-
};
|
|
133
|
-
});
|
|
209
|
+
}); });
|
|
134
210
|
// deleteHostingDomain - 解绑自定义域名
|
|
135
211
|
server.tool("deleteHostingDomain", "解绑自定义域名", {
|
|
136
212
|
domain: z.string().describe("自定义域名")
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
213
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
214
|
+
var result;
|
|
215
|
+
var domain = _b.domain;
|
|
216
|
+
return __generator(this, function (_c) {
|
|
217
|
+
switch (_c.label) {
|
|
218
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.deleteHostingDomain({
|
|
219
|
+
domain: domain
|
|
220
|
+
})];
|
|
221
|
+
case 1:
|
|
222
|
+
result = _c.sent();
|
|
223
|
+
return [2 /*return*/, {
|
|
224
|
+
content: [
|
|
225
|
+
{
|
|
226
|
+
type: "text",
|
|
227
|
+
text: JSON.stringify(result, null, 2)
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}];
|
|
231
|
+
}
|
|
140
232
|
});
|
|
141
|
-
|
|
142
|
-
content: [
|
|
143
|
-
{
|
|
144
|
-
type: "text",
|
|
145
|
-
text: JSON.stringify(result, null, 2)
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
};
|
|
149
|
-
});
|
|
233
|
+
}); });
|
|
150
234
|
// getWebsiteConfig - 获取静态网站配置
|
|
151
|
-
server.tool("getWebsiteConfig", "获取静态网站配置", {},
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
235
|
+
server.tool("getWebsiteConfig", "获取静态网站配置", {}, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
236
|
+
var result;
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
switch (_a.label) {
|
|
239
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.getWebsiteConfig()];
|
|
240
|
+
case 1:
|
|
241
|
+
result = _a.sent();
|
|
242
|
+
return [2 /*return*/, {
|
|
243
|
+
content: [
|
|
244
|
+
{
|
|
245
|
+
type: "text",
|
|
246
|
+
text: JSON.stringify(result, null, 2)
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
}];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}); });
|
|
162
253
|
// tcbCheckResource - 获取域名配置
|
|
163
254
|
server.tool("tcbCheckResource", "获取域名配置", {
|
|
164
255
|
domains: z.array(z.string()).describe("域名列表")
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
|
|
256
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
257
|
+
var result;
|
|
258
|
+
var domains = _b.domains;
|
|
259
|
+
return __generator(this, function (_c) {
|
|
260
|
+
switch (_c.label) {
|
|
261
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.tcbCheckResource({
|
|
262
|
+
domains: domains
|
|
263
|
+
})];
|
|
264
|
+
case 1:
|
|
265
|
+
result = _c.sent();
|
|
266
|
+
return [2 /*return*/, {
|
|
267
|
+
content: [
|
|
268
|
+
{
|
|
269
|
+
type: "text",
|
|
270
|
+
text: JSON.stringify(result, null, 2)
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
}];
|
|
274
|
+
}
|
|
168
275
|
});
|
|
169
|
-
|
|
170
|
-
content: [
|
|
171
|
-
{
|
|
172
|
-
type: "text",
|
|
173
|
-
text: JSON.stringify(result, null, 2)
|
|
174
|
-
}
|
|
175
|
-
]
|
|
176
|
-
};
|
|
177
|
-
});
|
|
276
|
+
}); });
|
|
178
277
|
// tcbModifyAttribute - 修改域名配置
|
|
179
278
|
server.tool("tcbModifyAttribute", "修改域名配置", {
|
|
180
279
|
domain: z.string().describe("域名"),
|
|
@@ -203,19 +302,27 @@ export function registerHostingTools(server) {
|
|
|
203
302
|
Qps: z.number().optional()
|
|
204
303
|
}).optional()
|
|
205
304
|
}).describe("域名配置")
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
305
|
+
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
306
|
+
var result;
|
|
307
|
+
var domain = _b.domain, domainId = _b.domainId, domainConfig = _b.domainConfig;
|
|
308
|
+
return __generator(this, function (_c) {
|
|
309
|
+
switch (_c.label) {
|
|
310
|
+
case 0: return [4 /*yield*/, cloudbase.hosting.tcbModifyAttribute({
|
|
311
|
+
domain: domain,
|
|
312
|
+
domainId: domainId,
|
|
313
|
+
domainConfig: domainConfig
|
|
314
|
+
})];
|
|
315
|
+
case 1:
|
|
316
|
+
result = _c.sent();
|
|
317
|
+
return [2 /*return*/, {
|
|
318
|
+
content: [
|
|
319
|
+
{
|
|
320
|
+
type: "text",
|
|
321
|
+
text: JSON.stringify(result, null, 2)
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
}];
|
|
325
|
+
}
|
|
211
326
|
});
|
|
212
|
-
|
|
213
|
-
content: [
|
|
214
|
-
{
|
|
215
|
-
type: "text",
|
|
216
|
-
text: JSON.stringify(result, null, 2)
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
};
|
|
220
|
-
});
|
|
327
|
+
}); });
|
|
221
328
|
}
|