@cloudbase/cloudbase-mcp 1.8.41 → 1.8.43

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.
Files changed (4) hide show
  1. package/dist/cli.cjs +336 -127
  2. package/dist/index.cjs +336 -127
  3. package/dist/index.js +335 -125
  4. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,11 +31,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", ({ value: true }));
32
32
  exports.CLOUDRUN_ACCESS_TYPES = exports.CLOUDRUN_SERVICE_TYPES = void 0;
33
33
  exports.registerCloudRunTools = registerCloudRunTools;
34
+ const child_process_1 = __webpack_require__(814);
35
+ const fs_1 = __importDefault(__webpack_require__(421));
36
+ const path_1 = __importDefault(__webpack_require__(521));
34
37
  const zod_1 = __webpack_require__(971);
35
38
  const cloudbase_manager_js_1 = __webpack_require__(431);
36
- const path_1 = __importDefault(__webpack_require__(521));
37
- const fs_1 = __importDefault(__webpack_require__(421));
38
- const child_process_1 = __webpack_require__(814);
39
39
  // CloudRun service types
40
40
  exports.CLOUDRUN_SERVICE_TYPES = ['function', 'container'];
41
41
  // CloudRun access types
@@ -47,7 +47,7 @@ const queryCloudRunInputSchema = {
47
47
  pageSize: zod_1.z.number().min(1).max(100).optional().default(10).describe('分页大小,控制每页返回的服务数量。取值范围:1-100,默认值:10。建议根据网络性能和显示需求调整'),
48
48
  pageNum: zod_1.z.number().min(1).optional().default(1).describe('页码,用于分页查询。从1开始,默认值:1。配合pageSize使用可实现分页浏览'),
49
49
  serverName: zod_1.z.string().optional().describe('服务名称筛选条件,支持模糊匹配。例如:输入"test"可匹配"test-service"、"my-test-app"等服务名称。留空则查询所有服务'),
50
- serverType: zod_1.z.enum(exports.CLOUDRUN_SERVICE_TYPES).optional().describe('服务类型筛选条件:function=函数型云托管(简化开发模式,支持WebSocket/SSE/文件上传等特性,适合快速开发),container=容器型服务(传统容器部署模式,支持任意语言和框架,适合复杂应用)'),
50
+ serverType: zod_1.z.enum(exports.CLOUDRUN_SERVICE_TYPES).optional().describe('服务类型筛选条件:function=函数型云托管(仅支持Node.js,有特殊的开发要求和限制,适合简单的API服务),container=容器型服务(推荐使用,支持任意语言和框架如Java/Go/Python/PHP/.NET等,适合大多数应用场景)'),
51
51
  // Detail operation parameters
52
52
  detailServerName: zod_1.z.string().optional().describe('要查询详细信息的服务名称。当action为detail时必需提供,必须是已存在的服务名称。可通过list操作获取可用的服务名称列表'),
53
53
  };
@@ -61,7 +61,7 @@ const ManageCloudRunInputSchema = {
61
61
  OpenAccessTypes: zod_1.z.array(zod_1.z.enum(exports.CLOUDRUN_ACCESS_TYPES)).optional().describe('公网访问类型配置,控制服务的访问权限:WEB=公网访问(默认,可通过HTTPS域名访问),VPC=私有网络访问(仅同VPC内可访问),PRIVATE=内网访问(仅云开发环境内可访问)。可配置多个类型'),
62
62
  Cpu: zod_1.z.number().positive().optional().describe('CPU规格配置,单位为核。可选值:0.25、0.5、1、2、4、8等。注意:内存规格必须是CPU规格的2倍(如CPU=0.25时内存=0.5,CPU=1时内存=2)。影响服务性能和计费'),
63
63
  Mem: zod_1.z.number().positive().optional().describe('内存规格配置,单位为GB。可选值:0.5、1、2、4、8、16等。注意:必须是CPU规格的2倍。影响服务性能和计费'),
64
- MinNum: zod_1.z.number().min(0).optional().describe('最小实例数配置,控制服务的最小运行实例数量。设置为0时支持缩容到0(无请求时不产生费用),设置为大于0时始终保持指定数量的实例运行(确保快速响应但会增加成本)'),
64
+ MinNum: zod_1.z.number().min(0).optional().describe('最小实例数配置,控制服务的最小运行实例数量。设置为0时支持缩容到0(无请求时不产生费用),设置为大于0时始终保持指定数量的实例运行(确保快速响应但会增加成本)。建议设置为1以降低冷启动延迟,提升用户体验'),
65
65
  MaxNum: zod_1.z.number().min(1).optional().describe('最大实例数配置,控制服务的最大运行实例数量。当请求量增加时,服务最多可以扩展到指定数量的实例,超过此数量后将拒绝新的请求。建议根据业务峰值设置'),
66
66
  Port: zod_1.z.number().min(1).max(65535).optional().describe('服务监听端口配置。函数型服务固定为3000,容器型服务可自定义。服务代码必须监听此端口才能正常接收请求'),
67
67
  EnvParams: zod_1.z.record(zod_1.z.string()).optional().describe('环境变量配置,用于传递配置信息给服务代码。格式为键值对,如{"DATABASE_URL":"mysql://..."}。敏感信息建议使用环境变量而非硬编码'),
@@ -89,6 +89,7 @@ const ManageCloudRunInputSchema = {
89
89
  }).optional().describe('Agent配置项,仅在createAgent操作时使用'),
90
90
  // Common parameters
91
91
  force: zod_1.z.boolean().optional().default(false).describe('强制操作开关,用于跳过确认提示。默认false(需要确认),设置为true时跳过所有确认步骤。删除操作时强烈建议设置为true以避免误操作'),
92
+ serverType: zod_1.z.enum(exports.CLOUDRUN_SERVICE_TYPES).optional().describe('服务类型配置:function=函数型云托管(仅支持Node.js,有特殊的开发要求和限制,适合简单的API服务),container=容器型服务(推荐使用,支持任意语言和框架如Java/Go/Python/PHP/.NET等,适合大多数应用场景)。不提供时自动检测:1)现有服务类型 2)有Dockerfile→container 3)有@cloudbase/aiagent-framework依赖→function 4)其他情况→container'),
92
93
  };
93
94
  /**
94
95
  * Check if a project is an Agent project
@@ -463,21 +464,47 @@ for await (let x of res.textStream) {
463
464
  if (!targetPath) {
464
465
  throw new Error("targetPath is required for deploy operation");
465
466
  }
466
- // Determine service type automatically
467
+ // Determine service type - use input.serverType if provided, otherwise auto-detect
467
468
  let serverType;
468
- try {
469
- // First try to get existing service details
470
- const details = await cloudrunService.detail({ serverName: input.serverName });
471
- serverType = details.BaseInfo?.ServerType || 'function';
469
+ if (input.serverType) {
470
+ serverType = input.serverType;
472
471
  }
473
- catch (e) {
474
- // If service doesn't exist, determine by project structure
475
- const dockerfilePath = path_1.default.join(targetPath, 'Dockerfile');
476
- if (fs_1.default.existsSync(dockerfilePath)) {
477
- serverType = 'container';
472
+ else {
473
+ try {
474
+ // First try to get existing service details
475
+ const details = await cloudrunService.detail({ serverName: input.serverName });
476
+ serverType = details.BaseInfo?.ServerType || 'container';
478
477
  }
479
- else {
480
- serverType = 'function';
478
+ catch (e) {
479
+ // If service doesn't exist, determine by project structure
480
+ const dockerfilePath = path_1.default.join(targetPath, 'Dockerfile');
481
+ if (fs_1.default.existsSync(dockerfilePath)) {
482
+ serverType = 'container';
483
+ }
484
+ else {
485
+ // Check if it's a Node.js function project (has package.json with specific structure)
486
+ const packageJsonPath = path_1.default.join(targetPath, 'package.json');
487
+ if (fs_1.default.existsSync(packageJsonPath)) {
488
+ try {
489
+ const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf8'));
490
+ // If it has function-specific dependencies or scripts, treat as function
491
+ if (packageJson.dependencies?.['@cloudbase/aiagent-framework'] ||
492
+ packageJson.scripts?.['dev']?.includes('cloudrun run')) {
493
+ serverType = 'function';
494
+ }
495
+ else {
496
+ serverType = 'container';
497
+ }
498
+ }
499
+ catch (parseError) {
500
+ serverType = 'container';
501
+ }
502
+ }
503
+ else {
504
+ // No package.json, default to container
505
+ serverType = 'container';
506
+ }
507
+ }
481
508
  }
482
509
  }
483
510
  const deployParams = {
@@ -1491,58 +1518,9 @@ function downloadFile(url) {
1491
1518
  });
1492
1519
  }
1493
1520
  function registerDownloadTools(server) {
1494
- // downloadRemoteFile - 下载远程文件到临时目录 (cloud-incompatible)
1495
1521
  server.registerTool("downloadRemoteFile", {
1496
- title: "下载远程文件到临时目录",
1497
- description: "下载远程文件到本地临时文件,返回一个系统的绝对路径。适用于需要临时处理文件的场景。",
1498
- inputSchema: {
1499
- url: zod_1.z.string().describe("远程文件的 URL 地址")
1500
- },
1501
- annotations: {
1502
- readOnlyHint: false,
1503
- destructiveHint: false,
1504
- idempotentHint: false,
1505
- openWorldHint: true,
1506
- category: "download"
1507
- }
1508
- }, async ({ url }) => {
1509
- try {
1510
- const result = await downloadFile(url);
1511
- return {
1512
- content: [
1513
- {
1514
- type: "text",
1515
- text: JSON.stringify({
1516
- success: true,
1517
- filePath: result.filePath,
1518
- contentType: result.contentType,
1519
- fileSize: result.fileSize,
1520
- message: "文件下载成功到临时目录",
1521
- note: "文件保存在临时目录中,请注意及时处理"
1522
- }, null, 2)
1523
- }
1524
- ]
1525
- };
1526
- }
1527
- catch (error) {
1528
- return {
1529
- content: [
1530
- {
1531
- type: "text",
1532
- text: JSON.stringify({
1533
- success: false,
1534
- error: error.message,
1535
- message: "文件下载失败"
1536
- }, null, 2)
1537
- }
1538
- ]
1539
- };
1540
- }
1541
- });
1542
- // downloadRemoteFileToPath - 下载远程文件到指定路径 (cloud-incompatible)
1543
- server.registerTool("downloadRemoteFileToPath", {
1544
1522
  title: "下载远程文件到指定路径",
1545
- description: "下载远程文件到项目根目录下的指定相对路径。Claude Code: WORKSPACE_FOLDER_PATHS, Qwen Code: PROJECT_ROOT, CodeBuddy: GITHUB_WORKSPACE。例如:小程序的 Tabbar 等素材图片,必须使用 **png** 格式,可以从 Unsplash、wikimedia【一般选用 500 大小即可、Pexels、Apple 官方 UI 等资源中选择来下载。",
1523
+ description: "下载远程文件到项目根目录下的指定相对路径。例如:小程序的 Tabbar 等素材图片,必须使用 **png** 格式,可以从 Unsplash、wikimedia【一般选用 500 大小即可、Pexels、Apple 官方 UI 等资源中选择来下载。",
1546
1524
  inputSchema: {
1547
1525
  url: zod_1.z.string().describe("远程文件的 URL 地址"),
1548
1526
  relativePath: zod_1.z.string().describe("相对于项目根目录的路径,例如:'assets/images/logo.png' 或 'docs/api.md'。不允许使用 ../ 等路径遍历操作。")
@@ -2105,9 +2083,9 @@ async function getLoginState() {
2105
2083
  }
2106
2084
  const loginState = await auth.getLoginState();
2107
2085
  if (!loginState) {
2108
- (0, logger_js_1.debug)('loginByApiSecret');
2109
2086
  await auth.loginByWebAuth({});
2110
2087
  const loginState = await auth.getLoginState();
2088
+ (0, logger_js_1.debug)('loginByWebAuth', loginState);
2111
2089
  return loginState;
2112
2090
  }
2113
2091
  else {
@@ -2184,8 +2162,8 @@ exports.resetInteractiveServer = resetInteractiveServer;
2184
2162
  exports.getInteractiveServerSafe = getInteractiveServerSafe;
2185
2163
  const express_1 = __importDefault(__webpack_require__(674));
2186
2164
  const http_1 = __importDefault(__webpack_require__(782));
2187
- const ws_1 = __webpack_require__(220);
2188
2165
  const open_1 = __importDefault(__webpack_require__(241));
2166
+ const ws_1 = __webpack_require__(220);
2189
2167
  const logger_js_1 = __webpack_require__(39);
2190
2168
  // 动态导入 open 模块,兼容 ESM/CJS 环境
2191
2169
  async function openUrl(url, options, server) {
@@ -3068,8 +3046,8 @@ class InteractiveServer {
3068
3046
  </div>
3069
3047
 
3070
3048
  <div class="content">
3071
- <h1 class="content-title">选择云开发环境</h1>
3072
- <p class="content-subtitle">请选择您要使用的云开发环境</p>
3049
+ <h1 class="content-title">选择 CloudBase 环境</h1>
3050
+ <p class="content-subtitle">请选择您要使用的 CloudBase 环境</p>
3073
3051
 
3074
3052
  <div class="env-list" id="envList">
3075
3053
  ${(envs || []).length > 0 ?
@@ -3086,8 +3064,8 @@ class InteractiveServer {
3086
3064
  `).join('') :
3087
3065
  `
3088
3066
  <div class="empty-state">
3089
- <h3 class="empty-title">暂无云开发环境</h3>
3090
- <p class="empty-message">当前没有可用的云开发 CloudBase 环境,请新建后重新在 AI 对话中重试</p>
3067
+ <h3 class="empty-title">暂无 CloudBase 环境</h3>
3068
+ <p class="empty-message">当前没有可用的 CloudBase 环境,请新建后重新在 AI 对话中重试</p>
3091
3069
  <button class="btn btn-primary create-env-btn" onclick="createNewEnv()">
3092
3070
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
3093
3071
  <path d="M12 5v14M5 12h14"/>
@@ -3125,7 +3103,7 @@ class InteractiveServer {
3125
3103
  </svg>
3126
3104
  </div>
3127
3105
  <h2 class="success-title">环境配置成功!</h2>
3128
- <p class="success-message">已成功选择云开发环境</p>
3106
+ <p class="success-message">已成功选择 CloudBase 环境</p>
3129
3107
  <div class="selected-env-info">
3130
3108
  <span class="env-label">环境 ID:</span>
3131
3109
  <span class="env-value" id="selectedEnvDisplay"></span>
@@ -5057,7 +5035,7 @@ ${envIdSection}
5057
5035
  ## 环境信息
5058
5036
  - 操作系统: ${os_1.default.type()} ${os_1.default.release()}
5059
5037
  - Node.js版本: ${process.version}
5060
- - MCP 版本:${process.env.npm_package_version || "1.8.41" || 0}
5038
+ - MCP 版本:${process.env.npm_package_version || "1.8.43" || 0}
5061
5039
  - 系统架构: ${os_1.default.arch()}
5062
5040
  - 时间: ${new Date().toISOString()}
5063
5041
  - 请求ID: ${requestId}
@@ -5370,11 +5348,11 @@ exports.getEnvId = getEnvId;
5370
5348
  exports.resetCloudBaseManagerCache = resetCloudBaseManagerCache;
5371
5349
  exports.getCloudBaseManager = getCloudBaseManager;
5372
5350
  exports.createCloudBaseManagerWithOptions = createCloudBaseManagerWithOptions;
5351
+ const manager_node_1 = __importDefault(__webpack_require__(665));
5373
5352
  const auth_js_1 = __webpack_require__(291);
5374
5353
  const interactive_js_1 = __webpack_require__(461);
5375
- const manager_node_1 = __importDefault(__webpack_require__(665));
5376
5354
  const logger_js_1 = __webpack_require__(39);
5377
- const ENV_ID_TIMEOUT = 600000; // 600 seconds
5355
+ const ENV_ID_TIMEOUT = 60000000; // 60000 seconds
5378
5356
  // 统一的环境ID管理类
5379
5357
  class EnvironmentManager {
5380
5358
  cachedEnvId = null;
@@ -5549,14 +5527,14 @@ exports.saveEnvIdToUserConfig = saveEnvIdToUserConfig;
5549
5527
  exports.loadEnvIdFromUserConfig = loadEnvIdFromUserConfig;
5550
5528
  exports.clearUserEnvId = clearUserEnvId;
5551
5529
  exports.autoSetupEnvironmentId = autoSetupEnvironmentId;
5530
+ const promises_1 = __importDefault(__webpack_require__(932));
5531
+ const os_1 = __importDefault(__webpack_require__(116));
5532
+ const path_1 = __importDefault(__webpack_require__(521));
5552
5533
  const zod_1 = __webpack_require__(971);
5553
- const interactive_server_js_1 = __webpack_require__(341);
5554
- const cloudbase_manager_js_1 = __webpack_require__(431);
5555
5534
  const auth_js_1 = __webpack_require__(291);
5535
+ const cloudbase_manager_js_1 = __webpack_require__(431);
5536
+ const interactive_server_js_1 = __webpack_require__(341);
5556
5537
  const logger_js_1 = __webpack_require__(39);
5557
- const promises_1 = __importDefault(__webpack_require__(932));
5558
- const path_1 = __importDefault(__webpack_require__(521));
5559
- const os_1 = __importDefault(__webpack_require__(116));
5560
5538
  function registerInteractiveTools(server) {
5561
5539
  // 统一的交互式对话工具 (cloud-incompatible)
5562
5540
  server.registerTool("interactiveDialog", {
@@ -6100,7 +6078,7 @@ function registerSetupTools(server) {
6100
6078
  // downloadTemplate - 下载项目模板 (cloud-incompatible)
6101
6079
  server.registerTool("downloadTemplate", {
6102
6080
  title: "下载项目模板",
6103
- description: `自动下载并部署CloudBase项目模板。\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "1.8.41" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
6081
+ description: `自动下载并部署CloudBase项目模板。\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "1.8.43" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
6104
6082
  inputSchema: {
6105
6083
  template: zod_1.z.enum(["react", "vue", "miniprogram", "uniapp", "rules"]).describe("要下载的模板类型"),
6106
6084
  ide: zod_1.z.enum(IDE_TYPES).optional().default("all").describe("指定要下载的IDE类型,默认为all(下载所有IDE配置)"),
@@ -6292,9 +6270,6 @@ function registerEnvTools(server) {
6292
6270
  if (error) {
6293
6271
  return { content: [{ type: "text", text: error }] };
6294
6272
  }
6295
- if (noEnvs) {
6296
- return { content: [{ type: "text", text: "当前账户下暂无可用的云开发环境,请先在腾讯云控制台创建环境 https://tcb.cloud.tencent.com/dev?from=AIToolkit" }] };
6297
- }
6298
6273
  if (cancelled) {
6299
6274
  return { content: [{ type: "text", text: "用户取消了登录" }] };
6300
6275
  }
@@ -6372,12 +6347,12 @@ function registerEnvTools(server) {
6372
6347
  switch (action) {
6373
6348
  case "list":
6374
6349
  try {
6375
- const cloudbaseList = await (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions, requireEnvId: false });
6350
+ const cloudbaseList = await (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions, requireEnvId: true });
6376
6351
  result = await cloudbaseList.env.listEnvs();
6377
6352
  }
6378
6353
  catch (error) {
6379
6354
  (0, logger_js_1.debug)('获取环境列表时出错:', error);
6380
- return { content: [{ type: "text", text: "当前账户下暂无可用的云开发环境,请先在腾讯云控制台创建环境 https://tcb.cloud.tencent.com/dev?from=AIToolkit \n错误信息:" + (error instanceof Error ? error.message : String(error)) }]
6355
+ return { content: [{ type: "text", text: "获取环境列表时出错: " + (error instanceof Error ? error.message : String(error)) }]
6381
6356
  };
6382
6357
  }
6383
6358
  break;
@@ -8256,7 +8231,11 @@ function shouldRegisterTool(toolName) {
8256
8231
  'setupEnvironmentId',
8257
8232
  'clearUserEnvId',
8258
8233
  // Interactive tools - local server and file operations
8259
- 'interactiveDialog'
8234
+ 'interactiveDialog',
8235
+ // CloudRun tools - local file operations
8236
+ 'manageCloudRun',
8237
+ // Download tools - local file downloads
8238
+ 'manageStorage',
8260
8239
  ];
8261
8240
  const shouldRegister = !cloudIncompatibleTools.includes(toolName);
8262
8241
  if (!shouldRegister) {
@@ -8383,54 +8362,285 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
8383
8362
  exports.registerStorageTools = registerStorageTools;
8384
8363
  const zod_1 = __webpack_require__(971);
8385
8364
  const cloudbase_manager_js_1 = __webpack_require__(431);
8365
+ // Input schema for queryStorage tool
8366
+ const queryStorageInputSchema = {
8367
+ action: zod_1.z.enum(['list', 'info', 'url']).describe('查询操作类型:list=列出目录下的所有文件,info=获取指定文件的详细信息,url=获取文件的临时下载链接'),
8368
+ cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt 或 files/(目录)'),
8369
+ maxAge: zod_1.z.number().min(1).max(86400).optional().default(3600).describe('临时链接有效期,单位为秒,取值范围:1-86400,默认值:3600(1小时)')
8370
+ };
8371
+ // Input schema for manageStorage tool
8372
+ const manageStorageInputSchema = {
8373
+ action: zod_1.z.enum(['upload', 'download', 'delete']).describe('管理操作类型:upload=上传文件或目录,download=下载文件或目录,delete=删除文件或目录'),
8374
+ localPath: zod_1.z.string().describe('本地文件路径,建议传入绝对路径,例如 /tmp/files/data.txt'),
8375
+ cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt'),
8376
+ force: zod_1.z.boolean().optional().default(false).describe('强制操作开关,删除操作时建议设置为true以确认删除,默认false'),
8377
+ isDirectory: zod_1.z.boolean().optional().default(false).describe('是否为目录操作,true=目录操作,false=文件操作,默认false')
8378
+ };
8386
8379
  function registerStorageTools(server) {
8387
8380
  // 获取 cloudBaseOptions,如果没有则为 undefined
8388
8381
  const cloudBaseOptions = server.cloudBaseOptions;
8389
8382
  // 创建闭包函数来获取 CloudBase Manager
8390
8383
  const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
8391
- // uploadFile - 上传文件到云存储 (cloud-incompatible)
8392
- server.registerTool("uploadFile", {
8393
- title: "上传文件到云存储",
8394
- description: "上传文件到云存储(区别于静态网站托管,云存储更适合存储业务数据文件)",
8395
- inputSchema: {
8396
- localPath: zod_1.z.string().describe("本地文件路径,建议传入绝对路径,例如 /tmp/files/data.txt"),
8397
- cloudPath: zod_1.z.string().describe("云端文件路径,例如 files/data.txt")
8398
- },
8384
+ // Tool 1: queryStorage - 查询存储信息(只读操作)
8385
+ server.registerTool("queryStorage", {
8386
+ title: "查询存储信息",
8387
+ description: "查询云存储信息,支持列出目录文件、获取文件信息、获取临时下载链接等只读操作。返回的文件信息包括文件名、大小、修改时间、下载链接等。",
8388
+ inputSchema: queryStorageInputSchema,
8389
+ annotations: {
8390
+ readOnlyHint: true,
8391
+ openWorldHint: true,
8392
+ category: "storage"
8393
+ }
8394
+ }, async (args) => {
8395
+ try {
8396
+ const input = args;
8397
+ const manager = await getManager();
8398
+ if (!manager) {
8399
+ throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
8400
+ }
8401
+ const storageService = manager.storage;
8402
+ switch (input.action) {
8403
+ case 'list': {
8404
+ const result = await storageService.listDirectoryFiles(input.cloudPath);
8405
+ return {
8406
+ content: [
8407
+ {
8408
+ type: "text",
8409
+ text: JSON.stringify({
8410
+ success: true,
8411
+ data: {
8412
+ action: 'list',
8413
+ cloudPath: input.cloudPath,
8414
+ files: result || [],
8415
+ totalCount: result?.length || 0
8416
+ },
8417
+ message: `Successfully listed ${result?.length || 0} files in directory '${input.cloudPath}'`
8418
+ }, null, 2)
8419
+ }
8420
+ ]
8421
+ };
8422
+ }
8423
+ case 'info': {
8424
+ const result = await storageService.getFileInfo(input.cloudPath);
8425
+ return {
8426
+ content: [
8427
+ {
8428
+ type: "text",
8429
+ text: JSON.stringify({
8430
+ success: true,
8431
+ data: {
8432
+ action: 'info',
8433
+ cloudPath: input.cloudPath,
8434
+ fileInfo: result
8435
+ },
8436
+ message: `Successfully retrieved file info for '${input.cloudPath}'`
8437
+ }, null, 2)
8438
+ }
8439
+ ]
8440
+ };
8441
+ }
8442
+ case 'url': {
8443
+ const result = await storageService.getTemporaryUrl([{
8444
+ cloudPath: input.cloudPath,
8445
+ maxAge: input.maxAge || 3600
8446
+ }]);
8447
+ return {
8448
+ content: [
8449
+ {
8450
+ type: "text",
8451
+ text: JSON.stringify({
8452
+ success: true,
8453
+ data: {
8454
+ action: 'url',
8455
+ cloudPath: input.cloudPath,
8456
+ temporaryUrl: result[0]?.url || "",
8457
+ expireTime: `${input.maxAge || 3600}秒`,
8458
+ fileId: result[0]?.fileId || ""
8459
+ },
8460
+ message: `Successfully generated temporary URL for '${input.cloudPath}'`
8461
+ }, null, 2)
8462
+ }
8463
+ ]
8464
+ };
8465
+ }
8466
+ default:
8467
+ throw new Error(`Unsupported action: ${input.action}`);
8468
+ }
8469
+ }
8470
+ catch (error) {
8471
+ return {
8472
+ content: [
8473
+ {
8474
+ type: "text",
8475
+ text: JSON.stringify({
8476
+ success: false,
8477
+ error: error.message || 'Unknown error occurred',
8478
+ message: `Failed to query storage information. Please check your permissions and parameters.`
8479
+ }, null, 2)
8480
+ }
8481
+ ]
8482
+ };
8483
+ }
8484
+ });
8485
+ // Tool 2: manageStorage - 管理存储文件(写操作)
8486
+ server.registerTool("manageStorage", {
8487
+ title: "管理存储文件",
8488
+ description: "管理云存储文件,支持上传文件/目录、下载文件/目录、删除文件/目录等操作。删除操作需要设置force=true进行确认,防止误删除重要文件。",
8489
+ inputSchema: manageStorageInputSchema,
8399
8490
  annotations: {
8400
8491
  readOnlyHint: false,
8401
- destructiveHint: false,
8492
+ destructiveHint: true,
8402
8493
  idempotentHint: false,
8403
8494
  openWorldHint: true,
8404
8495
  category: "storage"
8405
8496
  }
8406
- }, async ({ localPath, cloudPath }) => {
8407
- const cloudbase = await getManager();
8408
- // 上传文件
8409
- await cloudbase.storage.uploadFile({
8410
- localPath,
8411
- cloudPath,
8412
- onProgress: (progressData) => {
8413
- console.log("Upload progress:", progressData);
8497
+ }, async (args) => {
8498
+ try {
8499
+ const input = args;
8500
+ const manager = await getManager();
8501
+ if (!manager) {
8502
+ throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
8414
8503
  }
8415
- });
8416
- // 获取文件临时下载地址
8417
- const fileUrls = await cloudbase.storage.getTemporaryUrl([{
8418
- cloudPath: cloudPath,
8419
- maxAge: 3600 // 临时链接有效期1小时
8420
- }]);
8421
- return {
8422
- content: [
8423
- {
8424
- type: "text",
8425
- text: JSON.stringify({
8426
- message: "文件上传成功",
8427
- cloudPath: cloudPath,
8428
- temporaryUrl: fileUrls[0]?.url || "",
8429
- expireTime: "1小时"
8430
- }, null, 2)
8504
+ const storageService = manager.storage;
8505
+ switch (input.action) {
8506
+ case 'upload': {
8507
+ if (input.isDirectory) {
8508
+ // 上传目录
8509
+ await storageService.uploadDirectory({
8510
+ localPath: input.localPath,
8511
+ cloudPath: input.cloudPath,
8512
+ onProgress: (progressData) => {
8513
+ console.log("Upload directory progress:", progressData);
8514
+ }
8515
+ });
8516
+ }
8517
+ else {
8518
+ // 上传文件
8519
+ await storageService.uploadFile({
8520
+ localPath: input.localPath,
8521
+ cloudPath: input.cloudPath,
8522
+ onProgress: (progressData) => {
8523
+ console.log("Upload file progress:", progressData);
8524
+ }
8525
+ });
8526
+ }
8527
+ // 获取文件临时下载地址
8528
+ const fileUrls = await storageService.getTemporaryUrl([{
8529
+ cloudPath: input.cloudPath,
8530
+ maxAge: 3600 // 临时链接有效期1小时
8531
+ }]);
8532
+ return {
8533
+ content: [
8534
+ {
8535
+ type: "text",
8536
+ text: JSON.stringify({
8537
+ success: true,
8538
+ data: {
8539
+ action: 'upload',
8540
+ localPath: input.localPath,
8541
+ cloudPath: input.cloudPath,
8542
+ isDirectory: input.isDirectory,
8543
+ temporaryUrl: fileUrls[0]?.url || "",
8544
+ expireTime: "1小时"
8545
+ },
8546
+ message: `Successfully uploaded ${input.isDirectory ? 'directory' : 'file'} from '${input.localPath}' to '${input.cloudPath}'`
8547
+ }, null, 2)
8548
+ }
8549
+ ]
8550
+ };
8431
8551
  }
8432
- ]
8433
- };
8552
+ case 'download': {
8553
+ if (input.isDirectory) {
8554
+ // 下载目录
8555
+ await storageService.downloadDirectory({
8556
+ cloudPath: input.cloudPath,
8557
+ localPath: input.localPath
8558
+ });
8559
+ }
8560
+ else {
8561
+ // 下载文件
8562
+ await storageService.downloadFile({
8563
+ cloudPath: input.cloudPath,
8564
+ localPath: input.localPath
8565
+ });
8566
+ }
8567
+ return {
8568
+ content: [
8569
+ {
8570
+ type: "text",
8571
+ text: JSON.stringify({
8572
+ success: true,
8573
+ data: {
8574
+ action: 'download',
8575
+ cloudPath: input.cloudPath,
8576
+ localPath: input.localPath,
8577
+ isDirectory: input.isDirectory
8578
+ },
8579
+ message: `Successfully downloaded ${input.isDirectory ? 'directory' : 'file'} from '${input.cloudPath}' to '${input.localPath}'`
8580
+ }, null, 2)
8581
+ }
8582
+ ]
8583
+ };
8584
+ }
8585
+ case 'delete': {
8586
+ if (!input.force) {
8587
+ return {
8588
+ content: [
8589
+ {
8590
+ type: "text",
8591
+ text: JSON.stringify({
8592
+ success: false,
8593
+ error: "Delete operation requires confirmation",
8594
+ message: "Please set force: true to confirm deletion. This action cannot be undone."
8595
+ }, null, 2)
8596
+ }
8597
+ ]
8598
+ };
8599
+ }
8600
+ if (input.isDirectory) {
8601
+ // 删除目录
8602
+ await storageService.deleteDirectory(input.cloudPath);
8603
+ }
8604
+ else {
8605
+ // 删除文件
8606
+ await storageService.deleteFile([input.cloudPath]);
8607
+ }
8608
+ return {
8609
+ content: [
8610
+ {
8611
+ type: "text",
8612
+ text: JSON.stringify({
8613
+ success: true,
8614
+ data: {
8615
+ action: 'delete',
8616
+ cloudPath: input.cloudPath,
8617
+ isDirectory: input.isDirectory,
8618
+ deleted: true
8619
+ },
8620
+ message: `Successfully deleted ${input.isDirectory ? 'directory' : 'file'} '${input.cloudPath}'`
8621
+ }, null, 2)
8622
+ }
8623
+ ]
8624
+ };
8625
+ }
8626
+ default:
8627
+ throw new Error(`Unsupported action: ${input.action}`);
8628
+ }
8629
+ }
8630
+ catch (error) {
8631
+ return {
8632
+ content: [
8633
+ {
8634
+ type: "text",
8635
+ text: JSON.stringify({
8636
+ success: false,
8637
+ error: error.message || 'Unknown error occurred',
8638
+ message: `Failed to manage storage. Please check your permissions and parameters.`
8639
+ }, null, 2)
8640
+ }
8641
+ ]
8642
+ };
8643
+ }
8434
8644
  });
8435
8645
  }
8436
8646
 
@@ -8721,7 +8931,7 @@ class TelemetryReporter {
8721
8931
  const nodeVersion = process.version; // Node.js版本
8722
8932
  const arch = os_1.default.arch(); // 系统架构
8723
8933
  // 从构建时注入的版本号获取MCP版本信息
8724
- const mcpVersion = process.env.npm_package_version || "1.8.41" || 0;
8934
+ const mcpVersion = process.env.npm_package_version || "1.8.43" || 0;
8725
8935
  return {
8726
8936
  userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
8727
8937
  deviceId: this.deviceId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cloudbase-mcp",
3
- "version": "1.8.41",
3
+ "version": "1.8.43",
4
4
  "description": "腾讯云开发 MCP Server,通过AI提示词和MCP协议+云开发,让开发更智能、更高效,当你在Cursor/ VSCode GitHub Copilot/WinSurf/CodeBuddy/Augment Code/Claude Code等AI编程工具里写代码时,它能自动帮你生成可直接部署的前后端应用+小程序,并一键发布到腾讯云开发 CloudBase。",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",