@cloudbase/cloudbase-mcp 1.0.1 → 1.0.2

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.
@@ -0,0 +1,382 @@
1
+ import { z } from "zod";
2
+ import CloudBase from "@cloudbase/manager-node";
3
+ // 初始化CloudBase
4
+ const cloudbase = new CloudBase({
5
+ secretId: process.env.TENCENTCLOUD_SECRETID,
6
+ secretKey: process.env.TENCENTCLOUD_SECRETKEY,
7
+ envId: process.env.CLOUDBASE_ENV_ID,
8
+ token: process.env.TENCENTCLOUD_SESSIONTOKEN
9
+ });
10
+ export function registerFunctionTools(server) {
11
+ // getFunctionList - 获取云函数列表(推荐)
12
+ server.tool("getFunctionList", "获取云函数列表", {
13
+ limit: z.number().optional().describe("范围"),
14
+ offset: z.number().optional().describe("偏移")
15
+ }, async ({ limit, offset }) => {
16
+ const result = await cloudbase.functions.getFunctionList(limit, offset);
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: JSON.stringify(result, null, 2)
22
+ }
23
+ ]
24
+ };
25
+ });
26
+ // createFunction - 创建云函数
27
+ server.tool("createFunction", "创建云函数", {
28
+ func: z.object({
29
+ name: z.string().describe("函数名称"),
30
+ timeout: z.number().optional().describe("函数超时时间"),
31
+ envVariables: z.record(z.string()).optional().describe("环境变量"),
32
+ vpc: z.object({
33
+ vpcId: z.string(),
34
+ subnetId: z.string()
35
+ }).optional().describe("私有网络配置"),
36
+ runtime: z.string().optional().describe("运行时环境"),
37
+ installDependency: z.boolean().optional().describe("是否安装依赖"),
38
+ triggers: z.array(z.object({
39
+ name: z.string(),
40
+ type: z.string(),
41
+ config: z.string()
42
+ })).optional().describe("触发器配置"),
43
+ handler: z.string().optional().describe("函数入口"),
44
+ ignore: z.union([z.string(), z.array(z.string())]).optional().describe("忽略文件"),
45
+ isWaitInstall: z.boolean().optional().describe("是否等待依赖安装"),
46
+ layers: z.array(z.object({
47
+ name: z.string(),
48
+ version: z.number()
49
+ })).optional().describe("Layer配置")
50
+ }).describe("函数配置"),
51
+ functionRootPath: z.string().optional().describe("函数根目录"),
52
+ force: z.boolean().describe("是否覆盖"),
53
+ base64Code: z.string().optional().describe("base64编码的代码"),
54
+ codeSecret: z.string().optional().describe("代码保护密钥")
55
+ }, async ({ func, functionRootPath, force, base64Code, codeSecret }) => {
56
+ const result = await cloudbase.functions.createFunction({
57
+ func,
58
+ functionRootPath,
59
+ force,
60
+ base64Code,
61
+ codeSecret
62
+ });
63
+ return {
64
+ content: [
65
+ {
66
+ type: "text",
67
+ text: JSON.stringify(result, null, 2)
68
+ }
69
+ ]
70
+ };
71
+ });
72
+ // updateFunctionCode - 更新函数代码
73
+ server.tool("updateFunctionCode", "更新云函数代码", {
74
+ func: z.object({
75
+ name: z.string().describe("函数名称")
76
+ }).describe("函数配置"),
77
+ functionRootPath: z.string().optional().describe("函数根目录"),
78
+ base64Code: z.string().optional().describe("base64编码的代码"),
79
+ codeSecret: z.string().optional().describe("代码保护密钥")
80
+ }, async ({ func, functionRootPath, base64Code, codeSecret }) => {
81
+ const result = await cloudbase.functions.updateFunctionCode({
82
+ func,
83
+ functionRootPath,
84
+ base64Code,
85
+ codeSecret
86
+ });
87
+ return {
88
+ content: [
89
+ {
90
+ type: "text",
91
+ text: JSON.stringify(result, null, 2)
92
+ }
93
+ ]
94
+ };
95
+ });
96
+ // updateFunctionConfig - 更新函数配置
97
+ server.tool("updateFunctionConfig", "更新云函数配置", {
98
+ funcParam: z.object({
99
+ name: z.string().describe("函数名称"),
100
+ timeout: z.number().optional().describe("超时时间"),
101
+ envVariables: z.record(z.string()).optional().describe("环境变量"),
102
+ vpc: z.object({
103
+ vpcId: z.string(),
104
+ subnetId: z.string()
105
+ }).optional().describe("VPC配置"),
106
+ runtime: z.string().optional().describe("运行时")
107
+ }).describe("函数配置")
108
+ }, async ({ funcParam }) => {
109
+ const result = await cloudbase.functions.updateFunctionConfig(funcParam);
110
+ return {
111
+ content: [
112
+ {
113
+ type: "text",
114
+ text: JSON.stringify(result, null, 2)
115
+ }
116
+ ]
117
+ };
118
+ });
119
+ // getFunctionDetail - 获取函数详情
120
+ server.tool("getFunctionDetail", "获取云函数详情", {
121
+ name: z.string().describe("函数名称"),
122
+ codeSecret: z.string().optional().describe("代码保护密钥")
123
+ }, async ({ name, codeSecret }) => {
124
+ const result = await cloudbase.functions.getFunctionDetail(name, codeSecret);
125
+ return {
126
+ content: [
127
+ {
128
+ type: "text",
129
+ text: JSON.stringify(result, null, 2)
130
+ }
131
+ ]
132
+ };
133
+ });
134
+ // invokeFunction - 调用函数
135
+ server.tool("invokeFunction", "调用云函数", {
136
+ name: z.string().describe("函数名称"),
137
+ params: z.record(z.any()).optional().describe("调用参数")
138
+ }, async ({ name, params }) => {
139
+ const result = await cloudbase.functions.invokeFunction(name, params);
140
+ return {
141
+ content: [
142
+ {
143
+ type: "text",
144
+ text: JSON.stringify(result, null, 2)
145
+ }
146
+ ]
147
+ };
148
+ });
149
+ // getFunctionLogs - 获取函数日志
150
+ server.tool("getFunctionLogs", "获取云函数日志", {
151
+ options: z.object({
152
+ name: z.string().describe("函数名称"),
153
+ offset: z.number().optional().describe("偏移量"),
154
+ limit: z.number().optional().describe("返回数量"),
155
+ order: z.string().optional().describe("排序方式"),
156
+ orderBy: z.string().optional().describe("排序字段"),
157
+ startTime: z.string().optional().describe("开始时间"),
158
+ endTime: z.string().optional().describe("结束时间"),
159
+ requestId: z.string().optional().describe("请求ID")
160
+ }).describe("日志查询选项")
161
+ }, async ({ options }) => {
162
+ const result = await cloudbase.functions.getFunctionLogs(options);
163
+ return {
164
+ content: [
165
+ {
166
+ type: "text",
167
+ text: JSON.stringify(result, null, 2)
168
+ }
169
+ ]
170
+ };
171
+ });
172
+ // createFunctionTriggers - 创建函数触发器
173
+ server.tool("createFunctionTriggers", "创建云函数触发器", {
174
+ name: z.string().describe("函数名"),
175
+ triggers: z.array(z.object({
176
+ name: z.string().describe("触发器名称"),
177
+ type: z.string().describe("触发器类型"),
178
+ config: z.string().describe("触发器配置")
179
+ })).describe("触发器配置数组")
180
+ }, async ({ name, triggers }) => {
181
+ const result = await cloudbase.functions.createFunctionTriggers(name, triggers);
182
+ return {
183
+ content: [
184
+ {
185
+ type: "text",
186
+ text: JSON.stringify(result, null, 2)
187
+ }
188
+ ]
189
+ };
190
+ });
191
+ // deleteFunctionTrigger - 删除函数触发器
192
+ server.tool("deleteFunctionTrigger", "删除云函数触发器", {
193
+ name: z.string().describe("函数名"),
194
+ triggerName: z.string().describe("触发器名称")
195
+ }, async ({ name, triggerName }) => {
196
+ const result = await cloudbase.functions.deleteFunctionTrigger(name, triggerName);
197
+ return {
198
+ content: [
199
+ {
200
+ type: "text",
201
+ text: JSON.stringify(result, null, 2)
202
+ }
203
+ ]
204
+ };
205
+ });
206
+ // // Layer相关功能
207
+ // // createLayer - 创建Layer
208
+ // server.tool(
209
+ // "createLayer",
210
+ // "创建Layer",
211
+ // {
212
+ // options: z.object({
213
+ // contentPath: z.string().optional().describe("Layer内容路径"),
214
+ // base64Content: z.string().optional().describe("base64编码的内容"),
215
+ // name: z.string().describe("Layer名称"),
216
+ // runtimes: z.array(z.string()).describe("运行时列表"),
217
+ // description: z.string().optional().describe("描述"),
218
+ // licenseInfo: z.string().optional().describe("许可证信息")
219
+ // }).describe("Layer配置")
220
+ // },
221
+ // async ({ options }) => {
222
+ // const result = await cloudbase.functions.createLayer(options);
223
+ // return {
224
+ // content: [
225
+ // {
226
+ // type: "text",
227
+ // text: JSON.stringify(result, null, 2)
228
+ // }
229
+ // ]
230
+ // };
231
+ // }
232
+ // );
233
+ // // listLayers - 获取Layer列表
234
+ // server.tool(
235
+ // "listLayers",
236
+ // "获取Layer列表",
237
+ // {
238
+ // options: z.object({
239
+ // offset: z.number().optional().describe("偏移"),
240
+ // limit: z.number().optional().describe("数量限制"),
241
+ // runtime: z.string().optional().describe("运行时"),
242
+ // searchKey: z.string().optional().describe("搜索关键字")
243
+ // }).optional().describe("查询选项")
244
+ // },
245
+ // async ({ options }) => {
246
+ // const result = await cloudbase.functions.listLayers(options || {});
247
+ // return {
248
+ // content: [
249
+ // {
250
+ // type: "text",
251
+ // text: JSON.stringify(result, null, 2)
252
+ // }
253
+ // ]
254
+ // };
255
+ // }
256
+ // );
257
+ // // getLayerVersion - 获取Layer版本详情
258
+ // server.tool(
259
+ // "getLayerVersion",
260
+ // "获取Layer版本详情",
261
+ // {
262
+ // options: z.object({
263
+ // name: z.string().describe("Layer名称"),
264
+ // version: z.number().describe("版本号")
265
+ // }).describe("查询选项")
266
+ // },
267
+ // async ({ options }) => {
268
+ // const result = await cloudbase.functions.getLayerVersion(options);
269
+ // return {
270
+ // content: [
271
+ // {
272
+ // type: "text",
273
+ // text: JSON.stringify(result, null, 2)
274
+ // }
275
+ // ]
276
+ // };
277
+ // }
278
+ // );
279
+ // // 版本管理相关功能
280
+ // // publishVersion - 发布新版本
281
+ // server.tool(
282
+ // "publishVersion",
283
+ // "发布函数新版本",
284
+ // {
285
+ // options: z.object({
286
+ // functionName: z.string().describe("函数名称"),
287
+ // description: z.string().optional().describe("版本描述")
288
+ // }).describe("发布选项")
289
+ // },
290
+ // async ({ options }) => {
291
+ // const result = await cloudbase.functions.publishVersion(options);
292
+ // return {
293
+ // content: [
294
+ // {
295
+ // type: "text",
296
+ // text: JSON.stringify(result, null, 2)
297
+ // }
298
+ // ]
299
+ // };
300
+ // }
301
+ // );
302
+ // // listVersionByFunction - 获取版本列表
303
+ // server.tool(
304
+ // "listVersionByFunction",
305
+ // "获取函数版本列表",
306
+ // {
307
+ // options: z.object({
308
+ // functionName: z.string().describe("函数名称"),
309
+ // offset: z.number().optional().describe("偏移"),
310
+ // limit: z.number().optional().describe("数量限制"),
311
+ // order: z.string().optional().describe("排序方式"),
312
+ // orderBy: z.string().optional().describe("排序字段")
313
+ // }).describe("查询选项")
314
+ // },
315
+ // async ({ options }) => {
316
+ // const result = await cloudbase.functions.listVersionByFunction(options);
317
+ // return {
318
+ // content: [
319
+ // {
320
+ // type: "text",
321
+ // text: JSON.stringify(result, null, 2)
322
+ // }
323
+ // ]
324
+ // };
325
+ // }
326
+ // );
327
+ // // 别名配置相关功能
328
+ // // updateFunctionAliasConfig - 更新别名配置
329
+ // server.tool(
330
+ // "updateFunctionAliasConfig",
331
+ // "更新函数别名配置",
332
+ // {
333
+ // options: z.object({
334
+ // functionName: z.string().describe("函数名称"),
335
+ // name: z.string().describe("别名名称"),
336
+ // functionVersion: z.string().describe("函数版本"),
337
+ // description: z.string().optional().describe("描述"),
338
+ // routingConfig: z.object({
339
+ // AddtionVersionMatchs: z.array(z.object({
340
+ // Version: z.string(),
341
+ // Key: z.string(),
342
+ // Method: z.string(),
343
+ // Expression: z.string()
344
+ // }))
345
+ // }).optional().describe("路由配置")
346
+ // }).describe("别名配置")
347
+ // },
348
+ // async ({ options }) => {
349
+ // const result = await cloudbase.functions.updateFunctionAliasConfig(options);
350
+ // return {
351
+ // content: [
352
+ // {
353
+ // type: "text",
354
+ // text: JSON.stringify(result, null, 2)
355
+ // }
356
+ // ]
357
+ // };
358
+ // }
359
+ // );
360
+ // // getFunctionAlias - 获取别名配置
361
+ // server.tool(
362
+ // "getFunctionAlias",
363
+ // "获取函数别名配置",
364
+ // {
365
+ // options: z.object({
366
+ // functionName: z.string().describe("函数名称"),
367
+ // name: z.string().describe("别名名称")
368
+ // }).describe("查询选项")
369
+ // },
370
+ // async ({ options }) => {
371
+ // const result = await cloudbase.functions.getFunctionAlias(options);
372
+ // return {
373
+ // content: [
374
+ // {
375
+ // type: "text",
376
+ // text: JSON.stringify(result, null, 2)
377
+ // }
378
+ // ]
379
+ // };
380
+ // }
381
+ // );
382
+ }
@@ -0,0 +1,221 @@
1
+ import { z } from "zod";
2
+ import CloudBase from "@cloudbase/manager-node";
3
+ // 初始化CloudBase
4
+ const cloudbase = new CloudBase({
5
+ secretId: process.env.TENCENTCLOUD_SECRETID,
6
+ secretKey: process.env.TENCENTCLOUD_SECRETKEY,
7
+ envId: process.env.CLOUDBASE_ENV_ID,
8
+ token: process.env.TENCENTCLOUD_SESSIONTOKEN
9
+ });
10
+ export function registerHostingTools(server) {
11
+ // uploadFiles - 上传文件到静态网站托管
12
+ server.tool("uploadFiles", "上传文件到静态网站托管", {
13
+ localPath: z.string().optional().describe("本地文件或文件夹路径"),
14
+ cloudPath: z.string().optional().describe("云端文件或文件夹路径"),
15
+ files: z.array(z.object({
16
+ localPath: z.string(),
17
+ cloudPath: z.string()
18
+ })).default([]).describe("多文件上传配置"),
19
+ ignore: z.union([z.string(), z.array(z.string())]).optional().describe("忽略文件模式")
20
+ }, async ({ localPath, cloudPath, files, ignore }) => {
21
+ const result = await cloudbase.hosting.uploadFiles({
22
+ localPath,
23
+ cloudPath,
24
+ files,
25
+ ignore
26
+ });
27
+ return {
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: JSON.stringify(result, null, 2)
32
+ }
33
+ ]
34
+ };
35
+ });
36
+ // listFiles - 获取文件列表
37
+ server.tool("listFiles", "获取静态网站托管的文件列表", {}, async () => {
38
+ const result = await cloudbase.hosting.listFiles();
39
+ return {
40
+ content: [
41
+ {
42
+ type: "text",
43
+ text: JSON.stringify(result, null, 2)
44
+ }
45
+ ]
46
+ };
47
+ });
48
+ // deleteFiles - 删除文件
49
+ server.tool("deleteFiles", "删除静态网站托管的文件或文件夹", {
50
+ cloudPath: z.string().describe("云端文件或文件夹路径"),
51
+ isDir: z.boolean().default(false).describe("是否为文件夹")
52
+ }, async ({ cloudPath, isDir }) => {
53
+ const result = await cloudbase.hosting.deleteFiles({
54
+ cloudPath,
55
+ isDir
56
+ });
57
+ return {
58
+ content: [
59
+ {
60
+ type: "text",
61
+ text: JSON.stringify(result, null, 2)
62
+ }
63
+ ]
64
+ };
65
+ });
66
+ // findFiles - 搜索文件
67
+ server.tool("findFiles", "搜索静态网站托管的文件", {
68
+ prefix: z.string().describe("匹配前缀"),
69
+ marker: z.string().optional().describe("起始对象键标记"),
70
+ maxKeys: z.number().optional().describe("单次返回最大条目数")
71
+ }, async ({ prefix, marker, maxKeys }) => {
72
+ const result = await cloudbase.hosting.findFiles({
73
+ prefix,
74
+ marker,
75
+ maxKeys
76
+ });
77
+ return {
78
+ content: [
79
+ {
80
+ type: "text",
81
+ text: JSON.stringify(result, null, 2)
82
+ }
83
+ ]
84
+ };
85
+ });
86
+ // // setWebsiteDocument - 配置静态网站文档
87
+ // server.tool(
88
+ // "setWebsiteDocument",
89
+ // "配置静态网站的错误文档、索引文档和重定向规则",
90
+ // {
91
+ // indexDocument: z.string().describe("索引文档路径"),
92
+ // errorDocument: z.string().optional().describe("错误文档路径"),
93
+ // routingRules: z.array(z.object({
94
+ // keyPrefixEquals: z.string().optional(),
95
+ // httpErrorCodeReturnedEquals: z.string().optional(),
96
+ // replaceKeyWith: z.string().optional(),
97
+ // replaceKeyPrefixWith: z.string().optional()
98
+ // })).optional().describe("重定向规则")
99
+ // },
100
+ // async ({ indexDocument, errorDocument, routingRules }) => {
101
+ // const result = await cloudbase.hosting.setWebsiteDocument({
102
+ // indexDocument,
103
+ // errorDocument,
104
+ // routingRules
105
+ // });
106
+ // return {
107
+ // content: [
108
+ // {
109
+ // type: "text",
110
+ // text: JSON.stringify(result, null, 2)
111
+ // }
112
+ // ]
113
+ // };
114
+ // }
115
+ // );
116
+ // createHostingDomain - 绑定自定义域名
117
+ server.tool("createHostingDomain", "绑定自定义域名", {
118
+ domain: z.string().describe("自定义域名"),
119
+ certId: z.string().describe("证书ID")
120
+ }, async ({ domain, certId }) => {
121
+ const result = await cloudbase.hosting.CreateHostingDomain({
122
+ domain,
123
+ certId
124
+ });
125
+ return {
126
+ content: [
127
+ {
128
+ type: "text",
129
+ text: JSON.stringify(result, null, 2)
130
+ }
131
+ ]
132
+ };
133
+ });
134
+ // deleteHostingDomain - 解绑自定义域名
135
+ server.tool("deleteHostingDomain", "解绑自定义域名", {
136
+ domain: z.string().describe("自定义域名")
137
+ }, async ({ domain }) => {
138
+ const result = await cloudbase.hosting.deleteHostingDomain({
139
+ domain
140
+ });
141
+ return {
142
+ content: [
143
+ {
144
+ type: "text",
145
+ text: JSON.stringify(result, null, 2)
146
+ }
147
+ ]
148
+ };
149
+ });
150
+ // getWebsiteConfig - 获取静态网站配置
151
+ server.tool("getWebsiteConfig", "获取静态网站配置", {}, async () => {
152
+ const result = await cloudbase.hosting.getWebsiteConfig();
153
+ return {
154
+ content: [
155
+ {
156
+ type: "text",
157
+ text: JSON.stringify(result, null, 2)
158
+ }
159
+ ]
160
+ };
161
+ });
162
+ // tcbCheckResource - 获取域名配置
163
+ server.tool("tcbCheckResource", "获取域名配置", {
164
+ domains: z.array(z.string()).describe("域名列表")
165
+ }, async ({ domains }) => {
166
+ const result = await cloudbase.hosting.tcbCheckResource({
167
+ domains
168
+ });
169
+ return {
170
+ content: [
171
+ {
172
+ type: "text",
173
+ text: JSON.stringify(result, null, 2)
174
+ }
175
+ ]
176
+ };
177
+ });
178
+ // tcbModifyAttribute - 修改域名配置
179
+ server.tool("tcbModifyAttribute", "修改域名配置", {
180
+ domain: z.string().describe("域名"),
181
+ domainId: z.number().describe("域名ID"),
182
+ domainConfig: z.object({
183
+ Refer: z.object({
184
+ Switch: z.string(),
185
+ RefererRules: z.array(z.object({
186
+ RefererType: z.string(),
187
+ Referers: z.array(z.string()),
188
+ AllowEmpty: z.boolean()
189
+ })).optional()
190
+ }).optional(),
191
+ Cache: z.array(z.object({
192
+ RuleType: z.string(),
193
+ RuleValue: z.string(),
194
+ CacheTtl: z.number()
195
+ })).optional(),
196
+ IpFilter: z.object({
197
+ Switch: z.string(),
198
+ FilterType: z.string().optional(),
199
+ Filters: z.array(z.string()).optional()
200
+ }).optional(),
201
+ IpFreqLimit: z.object({
202
+ Switch: z.string(),
203
+ Qps: z.number().optional()
204
+ }).optional()
205
+ }).describe("域名配置")
206
+ }, async ({ domain, domainId, domainConfig }) => {
207
+ const result = await cloudbase.hosting.tcbModifyAttribute({
208
+ domain,
209
+ domainId,
210
+ domainConfig
211
+ });
212
+ return {
213
+ content: [
214
+ {
215
+ type: "text",
216
+ text: JSON.stringify(result, null, 2)
217
+ }
218
+ ]
219
+ };
220
+ });
221
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cloudbase-mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "腾讯云开发 MCP Server,支持静态托管/环境查询/",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "clean": "rm -rf dist",
12
12
  "prebuild": "npm run clean",
13
- "build": "tsc && chmod 755 build/index.js",
13
+ "build": "tsc && chmod 755 dist/index.js",
14
14
  "prepublishOnly": "npm run build"
15
15
  },
16
16
  "files": [