@cloudbase/cloudbase-mcp 2.6.3 → 2.6.4

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.cjs CHANGED
@@ -1944,7 +1944,7 @@ function registerEnvTools(server) {
1944
1944
  content: [
1945
1945
  {
1946
1946
  type: "text",
1947
- text: JSON.stringify(result, null, 2),
1947
+ text: `${JSON.stringify(result, null, 2)}\n\n请注意安全域名需要10分钟才能生效,用户也应该了解这一点。`,
1948
1948
  },
1949
1949
  ],
1950
1950
  };
@@ -23634,14 +23634,59 @@ class EnvironmentManager {
23634
23634
  }
23635
23635
  // 2. 自动设置环境ID (pass mcpServer for IDE detection)
23636
23636
  (0, logger_js_1.debug)('未找到环境ID,尝试自动设置...');
23637
- const autoEnvId = await (0, interactive_js_1.autoSetupEnvironmentId)(mcpServer);
23637
+ let setupResult;
23638
+ try {
23639
+ setupResult = await (0, interactive_js_1._promptAndSetEnvironmentId)(true, { server: mcpServer });
23640
+ }
23641
+ catch (setupError) {
23642
+ // Preserve original error information
23643
+ const errorObj = setupError instanceof Error ? setupError : new Error(String(setupError));
23644
+ (0, logger_js_1.error)('自动设置环境ID时发生异常:', {
23645
+ error: errorObj.message,
23646
+ stack: errorObj.stack,
23647
+ name: errorObj.name,
23648
+ });
23649
+ // Re-throw with enhanced context
23650
+ const enhancedError = new Error(`自动设置环境ID失败: ${errorObj.message}`);
23651
+ enhancedError.originalError = errorObj;
23652
+ enhancedError.failureInfo = {
23653
+ reason: 'unknown_error',
23654
+ error: errorObj.message,
23655
+ errorCode: 'SETUP_EXCEPTION',
23656
+ };
23657
+ throw enhancedError;
23658
+ }
23659
+ const autoEnvId = setupResult.selectedEnvId;
23638
23660
  if (!autoEnvId) {
23639
- throw new Error("CloudBase Environment ID not found after auto setup. Please set CLOUDBASE_ENV_ID or run setupEnvironmentId tool.");
23661
+ // Build detailed error message from failure info
23662
+ const errorMessage = this._buildDetailedErrorMessage(setupResult.failureInfo);
23663
+ (0, logger_js_1.error)('自动设置环境ID失败:', {
23664
+ reason: setupResult.failureInfo?.reason,
23665
+ errorCode: setupResult.failureInfo?.errorCode,
23666
+ error: setupResult.failureInfo?.error,
23667
+ details: setupResult.failureInfo?.details,
23668
+ });
23669
+ // Create error with detailed information
23670
+ const detailedError = new Error(errorMessage);
23671
+ detailedError.failureInfo = setupResult.failureInfo;
23672
+ throw detailedError;
23640
23673
  }
23641
23674
  (0, logger_js_1.debug)('自动设置环境ID成功:', { envId: autoEnvId });
23642
23675
  this._setCachedEnvId(autoEnvId);
23643
23676
  return autoEnvId;
23644
23677
  }
23678
+ catch (err) {
23679
+ // Log the error with full context before re-throwing
23680
+ const errorObj = err instanceof Error ? err : new Error(String(err));
23681
+ (0, logger_js_1.error)('获取环境ID失败:', {
23682
+ message: errorObj.message,
23683
+ stack: errorObj.stack,
23684
+ name: errorObj.name,
23685
+ failureInfo: errorObj.failureInfo,
23686
+ originalError: errorObj.originalError,
23687
+ });
23688
+ throw errorObj;
23689
+ }
23645
23690
  finally {
23646
23691
  this.envIdPromise = null;
23647
23692
  }
@@ -23652,6 +23697,65 @@ class EnvironmentManager {
23652
23697
  process.env.CLOUDBASE_ENV_ID = envId;
23653
23698
  (0, logger_js_1.debug)('已更新环境ID缓存:', { envId });
23654
23699
  }
23700
+ // Build detailed error message from failure info
23701
+ _buildDetailedErrorMessage(failureInfo) {
23702
+ if (!failureInfo) {
23703
+ return "CloudBase Environment ID not found after auto setup. Please set CLOUDBASE_ENV_ID or run setupEnvironmentId tool.";
23704
+ }
23705
+ const { reason, error: errorMsg, errorCode, helpUrl, details } = failureInfo;
23706
+ let message = "CloudBase Environment ID not found after auto setup.\n\n";
23707
+ message += `原因: ${this._getReasonDescription(reason)}\n`;
23708
+ if (errorMsg) {
23709
+ message += `错误: ${errorMsg}\n`;
23710
+ }
23711
+ if (errorCode) {
23712
+ message += `错误代码: ${errorCode}\n`;
23713
+ }
23714
+ // Add specific details based on failure reason
23715
+ if (reason === 'tcb_init_failed' && details?.initTcbError) {
23716
+ const initError = details.initTcbError;
23717
+ if (initError.needRealNameAuth) {
23718
+ message += "\n需要完成实名认证才能使用 CloudBase 服务。\n";
23719
+ }
23720
+ if (initError.needCamAuth) {
23721
+ message += "\n需要 CAM 权限才能使用 CloudBase 服务。\n";
23722
+ }
23723
+ }
23724
+ if (reason === 'env_creation_failed' && details?.createEnvError) {
23725
+ const createError = details.createEnvError;
23726
+ message += `\n环境创建失败: ${createError.message || '未知错误'}\n`;
23727
+ }
23728
+ if (reason === 'env_query_failed' && details?.queryEnvError) {
23729
+ message += `\n环境查询失败: ${details.queryEnvError}\n`;
23730
+ }
23731
+ if (reason === 'timeout' && details?.timeoutDuration) {
23732
+ message += `\n超时时间: ${details.timeoutDuration / 1000} 秒\n`;
23733
+ message += "提示: 请确保浏览器窗口已打开,并在规定时间内完成环境选择。\n";
23734
+ }
23735
+ message += "\n解决方案:\n";
23736
+ message += "1. 手动设置环境ID: 设置环境变量 CLOUDBASE_ENV_ID\n";
23737
+ message += "2. 使用工具设置: 运行 setupEnvironmentId 工具\n";
23738
+ if (helpUrl) {
23739
+ message += `3. 查看帮助文档: ${helpUrl}\n`;
23740
+ }
23741
+ else {
23742
+ message += "3. 查看帮助文档: https://docs.cloudbase.net/cli-v1/env\n";
23743
+ }
23744
+ return message;
23745
+ }
23746
+ _getReasonDescription(reason) {
23747
+ const descriptions = {
23748
+ 'timeout': '环境选择超时',
23749
+ 'cancelled': '用户取消了环境选择',
23750
+ 'no_environments': '没有可用环境',
23751
+ 'login_failed': '登录失败',
23752
+ 'tcb_init_failed': 'CloudBase 服务初始化失败',
23753
+ 'env_query_failed': '环境列表查询失败',
23754
+ 'env_creation_failed': '环境创建失败',
23755
+ 'unknown_error': '未知错误',
23756
+ };
23757
+ return descriptions[reason] || '未知原因';
23758
+ }
23655
23759
  // 手动设置环境ID(用于外部调用)
23656
23760
  async setEnvId(envId) {
23657
23761
  this._setCachedEnvId(envId);
@@ -23966,6 +24070,11 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
23966
24070
  selectedEnvId: null,
23967
24071
  cancelled: false,
23968
24072
  error: "请先登录云开发账户",
24073
+ failureInfo: {
24074
+ reason: 'login_failed',
24075
+ error: "请先登录云开发账户",
24076
+ errorCode: "LOGIN_REQUIRED",
24077
+ },
23969
24078
  };
23970
24079
  }
23971
24080
  // Get UIN for telemetry
@@ -24096,13 +24205,15 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24096
24205
  (0, logger_js_1.debug)("降级到 listEnvs() 也失败:", fallbackError instanceof Error ? fallbackError : new Error(String(fallbackError)));
24097
24206
  }
24098
24207
  }
24099
- // Report query_env_list event
24208
+ // Report query_env_list event with detailed information
24100
24209
  await telemetry_js_1.telemetryReporter.report('toolkit_env_setup', {
24101
24210
  step: 'query_env_list',
24102
24211
  success: queryEnvSuccess ? 'true' : 'false',
24103
24212
  uin: setupContext.uin || 'unknown',
24104
24213
  error: queryEnvError ? queryEnvError.substring(0, 200) : undefined,
24105
- envCount: (envResult?.EnvList || []).length
24214
+ envCount: (envResult?.EnvList || []).length,
24215
+ hasInitTcbError: !!setupContext.initTcbError,
24216
+ tcbServiceInitialized: setupContext.tcbServiceInitialized,
24106
24217
  });
24107
24218
  (0, logger_js_1.debug)("[interactive] Environment query result:", {
24108
24219
  hasResult: !!envResult,
@@ -24110,6 +24221,24 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24110
24221
  querySuccess: queryEnvSuccess,
24111
24222
  queryError: queryEnvError
24112
24223
  });
24224
+ // If query failed completely, return error
24225
+ if (!queryEnvSuccess && queryEnvError) {
24226
+ (0, logger_js_1.debug)("[interactive] Environment query failed completely, returning error");
24227
+ return {
24228
+ selectedEnvId: null,
24229
+ cancelled: false,
24230
+ error: `无法获取环境列表: ${queryEnvError}`,
24231
+ failureInfo: {
24232
+ reason: 'env_query_failed',
24233
+ error: `无法获取环境列表: ${queryEnvError}`,
24234
+ errorCode: "ENV_QUERY_FAILED",
24235
+ helpUrl: "https://docs.cloudbase.net/cli-v1/env",
24236
+ details: {
24237
+ queryEnvError,
24238
+ },
24239
+ },
24240
+ };
24241
+ }
24113
24242
  const { EnvList } = envResult || {};
24114
24243
  let selectedEnvId = null;
24115
24244
  // 4. 如果没有环境,尝试自动创建免费环境
@@ -24120,11 +24249,15 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24120
24249
  });
24121
24250
  if (!EnvList || EnvList.length === 0) {
24122
24251
  (0, logger_js_1.debug)("[interactive] No environments found");
24123
- // Report no_envs event
24252
+ // Report no_envs event with context
24124
24253
  await telemetry_js_1.telemetryReporter.report('toolkit_env_setup', {
24125
24254
  step: 'no_envs',
24126
24255
  success: 'true',
24127
- uin: setupContext.uin || 'unknown'
24256
+ uin: setupContext.uin || 'unknown',
24257
+ hasInitTcbError: !!setupContext.initTcbError,
24258
+ tcbServiceInitialized: setupContext.tcbServiceInitialized,
24259
+ initTcbErrorCode: setupContext.initTcbError?.code,
24260
+ inCloudMode,
24128
24261
  });
24129
24262
  // Only try to create free environment if TCB service is initialized successfully
24130
24263
  // If InitTcb failed, skip environment creation
@@ -24276,11 +24409,19 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24276
24409
  if (inCloudMode) {
24277
24410
  (0, logger_js_1.debug)("[interactive] CloudMode: Returning error message");
24278
24411
  let errorMsg = "未找到可用环境";
24412
+ let failureReason = 'no_environments';
24413
+ let errorCode = "NO_ENVIRONMENTS";
24279
24414
  if (setupContext.initTcbError) {
24280
24415
  errorMsg += `\nCloudBase 初始化失败: ${setupContext.initTcbError.message}`;
24416
+ failureReason = 'tcb_init_failed';
24417
+ errorCode = setupContext.initTcbError.code || "TCB_INIT_FAILED";
24281
24418
  }
24282
24419
  if (setupContext.createEnvError) {
24283
24420
  errorMsg += `\n环境创建失败: ${setupContext.createEnvError.message}`;
24421
+ if (failureReason === 'no_environments') {
24422
+ failureReason = 'env_creation_failed';
24423
+ }
24424
+ errorCode = setupContext.createEnvError.code || "ENV_CREATION_FAILED";
24284
24425
  }
24285
24426
  const helpUrl = setupContext.createEnvError?.helpUrl || setupContext.initTcbError?.helpUrl;
24286
24427
  if (helpUrl) {
@@ -24290,7 +24431,17 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24290
24431
  selectedEnvId: null,
24291
24432
  cancelled: false,
24292
24433
  error: errorMsg,
24293
- noEnvs: true
24434
+ noEnvs: true,
24435
+ failureInfo: {
24436
+ reason: failureReason,
24437
+ error: errorMsg,
24438
+ errorCode,
24439
+ helpUrl,
24440
+ details: {
24441
+ initTcbError: setupContext.initTcbError,
24442
+ createEnvError: setupContext.createEnvError,
24443
+ },
24444
+ },
24294
24445
  };
24295
24446
  }
24296
24447
  // In normal mode, show UI (even if creation failed or skipped)
@@ -24351,7 +24502,23 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24351
24502
  cloudbase, // Pass manager for refreshing env list
24352
24503
  resolvedServer);
24353
24504
  if (result.cancelled) {
24354
- return { selectedEnvId: null, cancelled: true };
24505
+ const isTimeout = result.timeout === true;
24506
+ const timeoutDuration = result.timeoutDuration;
24507
+ return {
24508
+ selectedEnvId: null,
24509
+ cancelled: true,
24510
+ failureInfo: {
24511
+ reason: isTimeout ? 'timeout' : 'cancelled',
24512
+ error: isTimeout
24513
+ ? `环境选择超时(${timeoutDuration ? timeoutDuration / 1000 : 120}秒),请重新尝试或手动设置环境ID`
24514
+ : "用户取消了环境选择",
24515
+ errorCode: isTimeout ? "ENV_SELECTION_TIMEOUT" : "USER_CANCELLED",
24516
+ helpUrl: isTimeout ? "https://docs.cloudbase.net/cli-v1/env" : undefined,
24517
+ details: isTimeout ? {
24518
+ timeoutDuration,
24519
+ } : undefined,
24520
+ },
24521
+ };
24355
24522
  }
24356
24523
  if (result.switch) {
24357
24524
  // Report switch_account event
@@ -24374,20 +24541,70 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, options) {
24374
24541
  // 自动设置环境ID(无需MCP工具调用)
24375
24542
  async function autoSetupEnvironmentId(mcpServer) {
24376
24543
  try {
24377
- const { selectedEnvId, cancelled, error, noEnvs } = await _promptAndSetEnvironmentId(true, { server: mcpServer });
24544
+ const { selectedEnvId, cancelled, error, noEnvs, failureInfo } = await _promptAndSetEnvironmentId(true, { server: mcpServer });
24378
24545
  if (error || noEnvs || cancelled) {
24379
- (0, logger_js_1.debug)("Auto setup environment ID interrupted or failed silently.", {
24546
+ (0, logger_js_1.debug)("Auto setup environment ID interrupted or failed.", {
24380
24547
  error,
24381
24548
  noEnvs,
24382
24549
  cancelled,
24550
+ failureInfo,
24383
24551
  });
24552
+ // Report failure to telemetry with detailed information
24553
+ if (failureInfo) {
24554
+ const telemetryData = {
24555
+ step: 'auto_setup_failed',
24556
+ success: 'false',
24557
+ reason: failureInfo.reason,
24558
+ errorCode: failureInfo.errorCode,
24559
+ error: failureInfo.error?.substring(0, 200),
24560
+ };
24561
+ // Add detailed context based on failure reason
24562
+ if (failureInfo.details) {
24563
+ if (failureInfo.details.initTcbError) {
24564
+ telemetryData.initTcbErrorCode = failureInfo.details.initTcbError.code;
24565
+ telemetryData.needRealNameAuth = failureInfo.details.initTcbError.needRealNameAuth;
24566
+ telemetryData.needCamAuth = failureInfo.details.initTcbError.needCamAuth;
24567
+ }
24568
+ if (failureInfo.details.createEnvError) {
24569
+ telemetryData.createEnvErrorCode = failureInfo.details.createEnvError.code;
24570
+ }
24571
+ if (failureInfo.details.queryEnvError) {
24572
+ telemetryData.queryEnvError = failureInfo.details.queryEnvError.substring(0, 200);
24573
+ }
24574
+ if (failureInfo.details.timeoutDuration) {
24575
+ telemetryData.timeoutDuration = failureInfo.details.timeoutDuration;
24576
+ }
24577
+ }
24578
+ if (failureInfo.helpUrl) {
24579
+ telemetryData.helpUrl = failureInfo.helpUrl;
24580
+ }
24581
+ await telemetry_js_1.telemetryReporter.report('toolkit_env_setup', telemetryData);
24582
+ }
24583
+ else {
24584
+ // Fallback: report without failureInfo
24585
+ await telemetry_js_1.telemetryReporter.report('toolkit_env_setup', {
24586
+ step: 'auto_setup_failed',
24587
+ success: 'false',
24588
+ reason: 'unknown',
24589
+ error: error || (noEnvs ? 'no_environments' : cancelled ? 'cancelled' : 'unknown'),
24590
+ });
24591
+ }
24384
24592
  return null;
24385
24593
  }
24386
24594
  (0, logger_js_1.debug)("Auto setup environment ID successful.", { selectedEnvId });
24387
24595
  return selectedEnvId;
24388
24596
  }
24389
24597
  catch (error) {
24390
- console.error("自动配置环境ID时出错:", error);
24598
+ const errorObj = error instanceof Error ? error : new Error(String(error));
24599
+ console.error("自动配置环境ID时出错:", errorObj);
24600
+ // Report unexpected error to telemetry
24601
+ await telemetry_js_1.telemetryReporter.report('toolkit_env_setup', {
24602
+ step: 'auto_setup_exception',
24603
+ success: 'false',
24604
+ reason: 'unknown_error',
24605
+ error: errorObj.message.substring(0, 200),
24606
+ stack: errorObj.stack?.substring(0, 500),
24607
+ });
24391
24608
  return null;
24392
24609
  }
24393
24610
  }
@@ -136788,7 +137005,7 @@ class TelemetryReporter {
136788
137005
  const nodeVersion = process.version; // Node.js版本
136789
137006
  const arch = os_1.default.arch(); // 系统架构
136790
137007
  // 从构建时注入的版本号获取MCP版本信息
136791
- const mcpVersion = process.env.npm_package_version || "2.6.3" || 0;
137008
+ const mcpVersion = process.env.npm_package_version || "2.6.4" || 0;
136792
137009
  return {
136793
137010
  userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
136794
137011
  deviceId: this.deviceId,
@@ -203352,7 +203569,7 @@ ${envIdSection}
203352
203569
  ## 环境信息
203353
203570
  - 操作系统: ${os_1.default.type()} ${os_1.default.release()}
203354
203571
  - Node.js版本: ${process.version}
203355
- - MCP 版本:${process.env.npm_package_version || "2.6.3" || 0}
203572
+ - MCP 版本:${process.env.npm_package_version || "2.6.4" || 0}
203356
203573
  - 系统架构: ${os_1.default.arch()}
203357
203574
  - 时间: ${new Date().toISOString()}
203358
203575
  - 请求ID: ${requestId}
@@ -218029,7 +218246,7 @@ function registerSetupTools(server) {
218029
218246
  title: "下载项目模板",
218030
218247
  description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
218031
218248
 
218032
- **CRITICAL**: This tool MUST be called FIRST when starting a new project.\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- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.6.3" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
218249
+ **CRITICAL**: This tool MUST be called FIRST when starting a new project.\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- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.6.4" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
218033
218250
  inputSchema: {
218034
218251
  template: zod_1.z
218035
218252
  .enum(["react", "vue", "miniprogram", "uniapp", "rules"])
@@ -256510,7 +256727,7 @@ class InteractiveServer {
256510
256727
  this.stop().catch((err) => {
256511
256728
  (0, logger_js_1.debug)("Error stopping server after timeout:", err);
256512
256729
  });
256513
- resolve({ type: "envId", data: null, cancelled: true });
256730
+ resolve({ type: "envId", data: null, cancelled: true, timeout: true, timeoutDuration });
256514
256731
  }
256515
256732
  }, timeoutDuration);
256516
256733
  // Store timeout ID so we can clear it if resolved early