@cloudbase/cloudbase-mcp 2.25.2 → 2.25.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/cli.cjs +3 -3
- package/dist/index.cjs +846 -64
- package/dist/index.js +846 -64
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -461,15 +461,20 @@ async function prepareAuthEnvironment(params) {
|
|
|
461
461
|
if (setupContext.createFreeEnvAttempted) {
|
|
462
462
|
envSetupActions.push("create_free_env");
|
|
463
463
|
}
|
|
464
|
+
// Surface the user-facing notice emitted at checkAndCreateFreeEnv entry.
|
|
465
|
+
// Informational only — no confirm required. Prepend to the final message so
|
|
466
|
+
// the user knows an automatic free-env creation was attempted.
|
|
467
|
+
const userNotice = createResult.userNotice?.trim() || "";
|
|
464
468
|
if (createResult.success && createResult.envId) {
|
|
465
469
|
await cloudbase_manager_js_1.envManager.setEnvId(createResult.envId);
|
|
470
|
+
const successMessage = `当前已登录,已自动创建并绑定环境: ${createResult.envId}`;
|
|
466
471
|
return {
|
|
467
472
|
currentEnvId: createResult.envId,
|
|
468
473
|
envStatus: "READY",
|
|
469
474
|
envCandidates: [],
|
|
470
475
|
envSetupStatus: "AUTO_CREATED",
|
|
471
476
|
envSetupActions: dedupeActions(envSetupActions),
|
|
472
|
-
message:
|
|
477
|
+
message: userNotice ? `${userNotice}\n${successMessage}` : successMessage,
|
|
473
478
|
nextStep: (0, tool_result_js_1.buildAuthNextStep)("status", {
|
|
474
479
|
suggestedArgs: { action: "status" },
|
|
475
480
|
}),
|
|
@@ -488,6 +493,9 @@ async function prepareAuthEnvironment(params) {
|
|
|
488
493
|
message: "环境创建失败,请稍后重试或手动创建环境。",
|
|
489
494
|
helpUrl: "https://buy.cloud.tencent.com/lowcode?buyType=tcb&channel=mcp",
|
|
490
495
|
});
|
|
496
|
+
const failureMessage = userNotice
|
|
497
|
+
? `${userNotice}\n${createFailure.message}`
|
|
498
|
+
: createFailure.message;
|
|
491
499
|
return {
|
|
492
500
|
currentEnvId: null,
|
|
493
501
|
envStatus: "NONE",
|
|
@@ -495,7 +503,7 @@ async function prepareAuthEnvironment(params) {
|
|
|
495
503
|
envSetupStatus: "ACTION_REQUIRED",
|
|
496
504
|
envSetupActions: dedupeActions(envSetupActions),
|
|
497
505
|
envSetupFailure: createFailure,
|
|
498
|
-
message:
|
|
506
|
+
message: failureMessage,
|
|
499
507
|
nextStep: (0, tool_result_js_1.buildAuthNextStep)("status", {
|
|
500
508
|
suggestedArgs: { action: "status" },
|
|
501
509
|
}),
|
|
@@ -817,6 +825,297 @@ function buildEnvQueryErrorMessage(error, action) {
|
|
|
817
825
|
function normalizeOptionalToolBoolean(value) {
|
|
818
826
|
return typeof value === "boolean" ? value : undefined;
|
|
819
827
|
}
|
|
828
|
+
/**
|
|
829
|
+
* 解析用于询价的 region。与 cloudbase-manager.ts 一致:
|
|
830
|
+
* cloudBaseOptions.region → TCB_REGION → 'ap-shanghai'。
|
|
831
|
+
*/
|
|
832
|
+
function resolvePricingRegion(cloudBaseOptions) {
|
|
833
|
+
return ((typeof cloudBaseOptions?.region === "string" && cloudBaseOptions.region) ||
|
|
834
|
+
process.env.TCB_REGION ||
|
|
835
|
+
"ap-shanghai");
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* 从 describeBaasPackageList 查询某个 packageId 的人类可读套餐名。
|
|
839
|
+
* 失败时返回 undefined,调用方降级为只显示 packageId。
|
|
840
|
+
*/
|
|
841
|
+
async function fetchPackageTitle(manager, packageId) {
|
|
842
|
+
try {
|
|
843
|
+
const result = await manager.env.describeBaasPackageList({
|
|
844
|
+
TargetAction: "new",
|
|
845
|
+
Source: "qcloud",
|
|
846
|
+
});
|
|
847
|
+
const packageList = result?.PackageList || [];
|
|
848
|
+
const matched = packageList.find((item) => item?.BillTags === packageId || item?.PackageName === packageId);
|
|
849
|
+
if (matched) {
|
|
850
|
+
return (matched.PackageTitle || matched.PackageName || matched.BillTags);
|
|
851
|
+
}
|
|
852
|
+
return undefined;
|
|
853
|
+
}
|
|
854
|
+
catch (error) {
|
|
855
|
+
(0, logger_js_1.debug)("fetchPackageTitle failed", { packageId, error });
|
|
856
|
+
return undefined;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* 查询环境的当前计费/套餐信息(PackageName、PackageId、Region、到期时间、PayMode)。
|
|
861
|
+
* 失败时返回 undefined。
|
|
862
|
+
*/
|
|
863
|
+
async function fetchEnvBillingSummary(manager, envId) {
|
|
864
|
+
try {
|
|
865
|
+
// describeBillingInfo 返回 EnvBillingInfoList;从中挑出 envId 对应项
|
|
866
|
+
const billingResult = await manager.env.describeBillingInfo({ EnvId: envId });
|
|
867
|
+
const billingList = billingResult?.EnvBillingInfoList ||
|
|
868
|
+
billingResult?.Response?.EnvBillingInfoList ||
|
|
869
|
+
billingResult?.Data?.EnvBillingInfoList ||
|
|
870
|
+
[];
|
|
871
|
+
const matched = Array.isArray(billingList)
|
|
872
|
+
? billingList.find((item) => item?.EnvId === envId) ?? billingList[0]
|
|
873
|
+
: undefined;
|
|
874
|
+
if (!matched) {
|
|
875
|
+
return undefined;
|
|
876
|
+
}
|
|
877
|
+
return {
|
|
878
|
+
packageName: matched.PackageName,
|
|
879
|
+
packageId: matched.PackageId,
|
|
880
|
+
region: matched.Region,
|
|
881
|
+
expireTime: matched.ExpireTime,
|
|
882
|
+
payMode: matched.PayMode,
|
|
883
|
+
isAutoRenew: matched.IsAutoRenew,
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
(0, logger_js_1.debug)("fetchEnvBillingSummary failed", { envId, error });
|
|
888
|
+
return undefined;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* 询价新购价格。失败时返回 { error }。
|
|
893
|
+
*/
|
|
894
|
+
async function calculateCreatePrice(manager, params) {
|
|
895
|
+
try {
|
|
896
|
+
const priceResult = await manager.env.calculatePackageCreatePrice({
|
|
897
|
+
packageId: params.packageId,
|
|
898
|
+
region: params.region,
|
|
899
|
+
period: params.period,
|
|
900
|
+
});
|
|
901
|
+
return { priceResult };
|
|
902
|
+
}
|
|
903
|
+
catch (error) {
|
|
904
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
905
|
+
(0, logger_js_1.debug)("calculatePackageCreatePrice failed", { params, error });
|
|
906
|
+
return { error: message };
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* 询价续费价格。失败时返回 { error }。
|
|
911
|
+
*/
|
|
912
|
+
async function calculateRenewPrice(manager, envId, period) {
|
|
913
|
+
try {
|
|
914
|
+
const priceResult = await manager.env.calculatePackageRenewPrice({
|
|
915
|
+
envId,
|
|
916
|
+
period,
|
|
917
|
+
});
|
|
918
|
+
return { priceResult };
|
|
919
|
+
}
|
|
920
|
+
catch (error) {
|
|
921
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
922
|
+
(0, logger_js_1.debug)("calculatePackageRenewPrice failed", { envId, period, error });
|
|
923
|
+
return { error: message };
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* 询价变配价格(含退款)。失败时返回 { error }。
|
|
928
|
+
*/
|
|
929
|
+
async function calculateModifyPrice(manager, envId, newPackageId) {
|
|
930
|
+
try {
|
|
931
|
+
const priceResult = await manager.env.calculatePackageModifyPrice({
|
|
932
|
+
envId,
|
|
933
|
+
newPackageId,
|
|
934
|
+
});
|
|
935
|
+
return { priceResult };
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
939
|
+
(0, logger_js_1.debug)("calculatePackageModifyPrice failed", { envId, newPackageId, error });
|
|
940
|
+
return { error: message };
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* 把 PriceResult 格式化为人类可读的价格摘要。
|
|
945
|
+
* 返回 { summary, detail }:summary 是一行短语,detail 是多行明细。
|
|
946
|
+
*/
|
|
947
|
+
function formatPriceSection(priceResult) {
|
|
948
|
+
if (!priceResult || typeof priceResult !== "object") {
|
|
949
|
+
return { summary: "询价返回为空", detail: "" };
|
|
950
|
+
}
|
|
951
|
+
const currency = priceResult.Currency === "USD" ? "$" : "¥";
|
|
952
|
+
const realTotalCost = Number(priceResult.RealTotalCost);
|
|
953
|
+
const totalCost = Number(priceResult.TotalCost);
|
|
954
|
+
const unitPrice = Number(priceResult.Price);
|
|
955
|
+
const timeSpan = priceResult.TimeSpan;
|
|
956
|
+
const TimeUnit = priceResult.TimeUnit || "";
|
|
957
|
+
const refund = priceResult.Refund ? Number(priceResult.Refund) : undefined;
|
|
958
|
+
const lines = [];
|
|
959
|
+
let summary = "";
|
|
960
|
+
if (Number.isFinite(realTotalCost) && realTotalCost > 0) {
|
|
961
|
+
summary = `预计实付 ${currency}${realTotalCost}`;
|
|
962
|
+
lines.push(`- 实付总价: ${currency}${realTotalCost}`);
|
|
963
|
+
}
|
|
964
|
+
else if (Number.isFinite(totalCost) && totalCost > 0) {
|
|
965
|
+
summary = `预计费用 ${currency}${totalCost}`;
|
|
966
|
+
lines.push(`- 总价: ${currency}${totalCost}`);
|
|
967
|
+
}
|
|
968
|
+
if (Number.isFinite(totalCost) && totalCost > 0 && totalCost !== realTotalCost) {
|
|
969
|
+
lines.push(`- 原价: ${currency}${totalCost}`);
|
|
970
|
+
}
|
|
971
|
+
if (Number.isFinite(unitPrice) && unitPrice > 0) {
|
|
972
|
+
lines.push(`- 单价: ${currency}${unitPrice}`);
|
|
973
|
+
}
|
|
974
|
+
if (timeSpan !== undefined && TimeUnit) {
|
|
975
|
+
lines.push(`- 时长: ${timeSpan} ${TimeUnit}`);
|
|
976
|
+
}
|
|
977
|
+
if (refund !== undefined && Number.isFinite(refund) && refund > 0) {
|
|
978
|
+
lines.push(`- 退款: ${currency}${refund}(变配降级时退回差价)`);
|
|
979
|
+
if (summary) {
|
|
980
|
+
summary += `,退款 ${currency}${refund}`;
|
|
981
|
+
}
|
|
982
|
+
else {
|
|
983
|
+
summary = `退款 ${currency}${refund}`;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (priceResult.Formula && typeof priceResult.Formula === "string") {
|
|
987
|
+
lines.push(`- 计价公式: ${priceResult.Formula}`);
|
|
988
|
+
}
|
|
989
|
+
return {
|
|
990
|
+
summary: summary || "询价返回缺少总价字段",
|
|
991
|
+
detail: lines.join("\n"),
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* 构建释放方式说明。manageEnv 当前未提供 destroy action,
|
|
996
|
+
* 指向控制台让用户手动销毁。
|
|
997
|
+
*/
|
|
998
|
+
function buildReleaseMethodHint() {
|
|
999
|
+
return {
|
|
1000
|
+
method: "手动销毁",
|
|
1001
|
+
consoleUrl: "https://console.cloud.tencent.com/tcb",
|
|
1002
|
+
note: '环境创建后可随时销毁以停止计费。当前 manageEnv 未提供 destroy action,请前往控制台手动销毁,或调用 manageEnv(action="listPackages") 查看其他套餐。',
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* manageEnv 涉及计费的官方文档链接。来源:腾讯云开发 CloudBase 公开文档。
|
|
1007
|
+
* 任何 confirm 消息展示这些链接前不需要再次校验 URL 真实性。
|
|
1008
|
+
*/
|
|
1009
|
+
const MANAGE_ENV_DOC_LINKS = {
|
|
1010
|
+
// 包年包月套餐说明(个人版 / 标准版 / 企业版 / 企业高级版)
|
|
1011
|
+
package: "https://cloud.tencent.com/document/product/876/39093",
|
|
1012
|
+
// 计费能力项说明
|
|
1013
|
+
billingItems: "https://cloud.tencent.com/document/product/876/120713",
|
|
1014
|
+
// 资源点价格文档
|
|
1015
|
+
resourcePointPrice: "https://cloud.tencent.com/document/product/876/127357",
|
|
1016
|
+
// 预付费计费与到期释放(费用中心通用)
|
|
1017
|
+
prepayExpiry: "https://cloud.tencent.com/document/product/555/9618",
|
|
1018
|
+
};
|
|
1019
|
+
/**
|
|
1020
|
+
* 把文档链接渲染为多行 markdown 列表文本。
|
|
1021
|
+
* filter 不传时全部展示。
|
|
1022
|
+
*/
|
|
1023
|
+
function renderDocLinksBlock(filter) {
|
|
1024
|
+
const labels = {
|
|
1025
|
+
package: "包年包月套餐说明",
|
|
1026
|
+
billingItems: "计费能力项说明",
|
|
1027
|
+
resourcePointPrice: "资源点价格文档",
|
|
1028
|
+
prepayExpiry: "预付费计费与到期释放(费用中心通用)",
|
|
1029
|
+
};
|
|
1030
|
+
const entries = (filter ?? Object.keys(MANAGE_ENV_DOC_LINKS))
|
|
1031
|
+
.map((k) => `- [${labels[k]}](${MANAGE_ENV_DOC_LINKS[k]})`)
|
|
1032
|
+
.join("\n");
|
|
1033
|
+
return `参考文档:\n${entries}`;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* 资源清单详细描述(对应控制台购买页"资源清单"段)。
|
|
1037
|
+
*/
|
|
1038
|
+
function buildResourceListText() {
|
|
1039
|
+
return "资源清单:\n- 云开发环境 ×1(含 云数据库 / 云函数 / 云存储 / 静态托管 / 身份认证 等基础资源)";
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* 计费项披露(对应控制台购买页"计费项"段)。
|
|
1043
|
+
* 此处为静态披露,调用方在 confirm 消息中拼接即可。
|
|
1044
|
+
*/
|
|
1045
|
+
function buildBillingItemsText() {
|
|
1046
|
+
return "计费项:\n- 数据库容量/调用 · 云函数调用/资源/流量 · 存储读写/CDN · 网关/认证/API 调用 · QPS 超限按量 · 日志";
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* 计费方式披露(对应控制台购买页"计费方式"段)。
|
|
1050
|
+
* 针对用户传入的 packageId 判断套餐类型:
|
|
1051
|
+
* - 含 free/activity/trial/试用 等关键字视为免费体验版
|
|
1052
|
+
* - 其余视为付费套餐
|
|
1053
|
+
*/
|
|
1054
|
+
function buildBillingModeText(packageId) {
|
|
1055
|
+
const id = (packageId || "").toLowerCase();
|
|
1056
|
+
const isFree = id.includes("free") ||
|
|
1057
|
+
id.includes("activity") ||
|
|
1058
|
+
id.includes("trial") ||
|
|
1059
|
+
id.includes("试用") ||
|
|
1060
|
+
id.includes("体验");
|
|
1061
|
+
if (isFree) {
|
|
1062
|
+
return ("计费方式:\n- 免费体验版(每月赠送约 3000 资源点 ≈ 3 元,0 元开通)\n" +
|
|
1063
|
+
"- 付费套餐:个人版 / 标准版 / 企业版 / 企业高级版");
|
|
1064
|
+
}
|
|
1065
|
+
return ("计费方式:\n- 付费套餐:个人版 / 标准版 / 企业版 / 企业高级版\n" +
|
|
1066
|
+
"- 免费体验版通过 auth 工具自动创建;本次 manageEnv(create) 不会创建免费版");
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* 资源释放方式详细说明(对应控制台购买页"资源释放方式"段)。
|
|
1070
|
+
* - 免费版:1 个月有效期 + 免费续期 + 停服(保留数据) + 1~7天回收站 + 释放(数据不可恢复)
|
|
1071
|
+
* - 付费版:到期未续费 → 停服(保留数据) + 1~7天可回收站找回 + 释放(数据不可恢复)
|
|
1072
|
+
* 任何时候都可在控制台主动销毁、关闭按量、退订加购资源。
|
|
1073
|
+
*/
|
|
1074
|
+
function buildReleaseMethodDetailText(packageId) {
|
|
1075
|
+
const id = (packageId || "").toLowerCase();
|
|
1076
|
+
const isFree = id.includes("free") ||
|
|
1077
|
+
id.includes("activity") ||
|
|
1078
|
+
id.includes("trial") ||
|
|
1079
|
+
id.includes("试用") ||
|
|
1080
|
+
id.includes("体验");
|
|
1081
|
+
const lines = ["资源释放方式:\n- 可随时在控制台销毁环境、关闭按量、退订加购资源"];
|
|
1082
|
+
if (isFree) {
|
|
1083
|
+
lines.push("- 免费体验版:有效期 1 个月,到期可免费续期 1 个月;未续期则停服(保留数据)→1~7天回收站→释放(数据不可恢复)");
|
|
1084
|
+
}
|
|
1085
|
+
else {
|
|
1086
|
+
lines.push("- 付费套餐到期未续费:停服(保留数据)→1~7天可回收站找回→释放(数据不可恢复)");
|
|
1087
|
+
lines.push("- 主动销毁:随时生效;销毁前请确保已迁移或备份数据");
|
|
1088
|
+
}
|
|
1089
|
+
return lines.join("\n");
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* 预计费用披露段:把询价结果 + 周期说明 + 超额按量说明组合成人类可读文本。
|
|
1093
|
+
*/
|
|
1094
|
+
function buildPricingDisclosureText(packageId, priceSection, priceError, period) {
|
|
1095
|
+
const id = (packageId || "").toLowerCase();
|
|
1096
|
+
const isFree = id.includes("free") ||
|
|
1097
|
+
id.includes("activity") ||
|
|
1098
|
+
id.includes("trial") ||
|
|
1099
|
+
id.includes("试用") ||
|
|
1100
|
+
id.includes("体验");
|
|
1101
|
+
const lines = ["预计费用:"];
|
|
1102
|
+
if (isFree) {
|
|
1103
|
+
lines.push(`- 免费体验版:本次开通 0 元;超免费额度后需升级为付费套餐(免费版不支持开按量)`);
|
|
1104
|
+
lines.push("- 实际单价以资源点价格文档为准(3000 资源点 ≈ 3 元)");
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
lines.push(`- 付费套餐:${priceSection?.summary ?? (priceError ? `⚠️ 询价失败(${priceError}),请前往控制台确认` : "询价返回为空")}`);
|
|
1108
|
+
if (priceSection?.detail) {
|
|
1109
|
+
lines.push(priceSection.detail);
|
|
1110
|
+
}
|
|
1111
|
+
if (priceError && priceSection) {
|
|
1112
|
+
lines.push(`- ⚠️ 部分明细缺失:${priceError}`);
|
|
1113
|
+
}
|
|
1114
|
+
lines.push(`- 计费周期:约 ${period} 个月(包年包月),到期可续费或变配`);
|
|
1115
|
+
lines.push("- 超额可另开按量(次日结算),详细计费项以官方文档为准");
|
|
1116
|
+
}
|
|
1117
|
+
return lines.join("\n");
|
|
1118
|
+
}
|
|
820
1119
|
function resolveToolAuthOptions(server, overrides) {
|
|
821
1120
|
return (0, auth_js_1.resolveAuthOptions)({
|
|
822
1121
|
...overrides,
|
|
@@ -1645,7 +1944,7 @@ function registerEnvTools(server) {
|
|
|
1645
1944
|
if (server.ide !== 'wxide') {
|
|
1646
1945
|
server.registerTool?.("envDomainManagement", {
|
|
1647
1946
|
title: "CloudBase 环境域名管理(安全域名 / CORS 白名单)",
|
|
1648
|
-
description: "管理 CloudBase 环境的安全域名(安全域名 / CORS 白名单),支持添加和删除操作。(原工具名:createEnvDomain/deleteEnvDomain,为兼容旧AI规则可继续使用这些名称)当浏览器 Web 应用需要从本地 Vite / dev server 直接访问 CloudBase 资源时,应先用 queryEnv(action=domains) 检查当前实际浏览器 origin 对应的 host:port 是否已在白名单中,再按该实际值添加。新增或删除后通常需要继续轮询 queryEnv(action=domains) 确认状态收敛;安全域名一般约 10 分钟生效。⚠️ 重要:此工具仅用于 CORS/请求来源验证,不涉及 SSL
|
|
1947
|
+
description: "管理 CloudBase 环境的安全域名(安全域名 / CORS 白名单),支持添加和删除操作。(原工具名:createEnvDomain/deleteEnvDomain,为兼容旧AI规则可继续使用这些名称)当浏览器 Web 应用需要从本地 Vite / dev server 直接访问 CloudBase 资源时,应先用 queryEnv(action=domains) 检查当前实际浏览器 origin 对应的 host:port 是否已在白名单中,再按该实际值添加。新增或删除后通常需要继续轮询 queryEnv(action=domains) 确认状态收敛;安全域名一般约 10 分钟生效。⚠️ 重要:此工具仅用于 CORS/请求来源验证,不涉及 SSL 证书。自定义域名公网 HTTPS:先 queryGateway(listCustomDomains);已有域名则 manageGateway(createRoute) 显式传 domain(无需证书);仅首次绑定新域名才用 bindCustomDomain(需 certificateId)。",
|
|
1649
1948
|
inputSchema: {
|
|
1650
1949
|
action: zod_1.z
|
|
1651
1950
|
.enum(["create", "delete"])
|
|
@@ -1769,10 +2068,92 @@ function registerEnvTools(server) {
|
|
|
1769
2068
|
// CreateEnv (Manager SDK / Cloud API) accepts Alias, PackageId, Resources, Period, etc.
|
|
1770
2069
|
// It does NOT accept Region — region is determined by account/package, not this call.
|
|
1771
2070
|
if (!confirmed) {
|
|
2071
|
+
// 查询套餐名和预计费用(失败降级,不阻塞 confirm 流程)
|
|
2072
|
+
const packageTitle = packageId
|
|
2073
|
+
? await fetchPackageTitle(cloudbase, packageId)
|
|
2074
|
+
: undefined;
|
|
2075
|
+
const pricingRegion = resolvePricingRegion(cloudBaseOptions);
|
|
2076
|
+
const priceProbe = packageId
|
|
2077
|
+
? await calculateCreatePrice(cloudbase, {
|
|
2078
|
+
packageId,
|
|
2079
|
+
region: pricingRegion,
|
|
2080
|
+
period: duration,
|
|
2081
|
+
})
|
|
2082
|
+
: { error: "缺少 packageId,无法询价" };
|
|
2083
|
+
const priceSection = priceProbe.priceResult
|
|
2084
|
+
? formatPriceSection(priceProbe.priceResult)
|
|
2085
|
+
: null;
|
|
2086
|
+
const releaseMethod = buildReleaseMethodHint();
|
|
2087
|
+
// 组合多段披露文案(对照控制台购买页确认对话框)
|
|
2088
|
+
const messageLines = [];
|
|
2089
|
+
messageLines.push("即将为你开通云开发环境");
|
|
2090
|
+
messageLines.push("本操作会创建腾讯云开发环境资源。");
|
|
2091
|
+
messageLines.push("为付费套餐后才会产生费用;免费体验版不会立即扣费(每月赠送约 3000 资源点 ≈ 3 元)。");
|
|
2092
|
+
messageLines.push("请核对以下配置信息后传入 confirm=\"yes\":");
|
|
2093
|
+
messageLines.push(`- 别名: ${alias ?? "(未提供)"}`);
|
|
2094
|
+
messageLines.push(`- 套餐: ${packageId ?? "(未提供)"}` +
|
|
2095
|
+
(packageTitle ? `(${packageTitle})` : ""));
|
|
2096
|
+
messageLines.push(`- 资源类型: ${resolvedResources.join(", ")}`);
|
|
2097
|
+
messageLines.push(`- 时长: ${duration} 个月`);
|
|
2098
|
+
messageLines.push("- 说明: CreateEnv 不接受 Region 入参,环境地域由账号与套餐侧决定。");
|
|
2099
|
+
messageLines.push("");
|
|
2100
|
+
// 资源清单 / 计费项 / 计费方式
|
|
2101
|
+
messageLines.push(buildResourceListText());
|
|
2102
|
+
messageLines.push(buildBillingItemsText());
|
|
2103
|
+
messageLines.push(buildBillingModeText(packageId));
|
|
2104
|
+
messageLines.push("");
|
|
2105
|
+
// 预计费用
|
|
2106
|
+
messageLines.push(buildPricingDisclosureText(packageId, priceSection, priceProbe.error, duration));
|
|
2107
|
+
messageLines.push("");
|
|
2108
|
+
// 资源释放方式
|
|
2109
|
+
messageLines.push(buildReleaseMethodDetailText(packageId));
|
|
2110
|
+
messageLines.push("");
|
|
2111
|
+
// 文档链接
|
|
2112
|
+
messageLines.push(renderDocLinksBlock([
|
|
2113
|
+
"package",
|
|
2114
|
+
"billingItems",
|
|
2115
|
+
"resourcePointPrice",
|
|
2116
|
+
"prepayExpiry",
|
|
2117
|
+
]));
|
|
2118
|
+
messageLines.push("");
|
|
2119
|
+
// 已知晓声明
|
|
2120
|
+
messageLines.push("☐ 我已知晓将创建付费资源及计费规则,确认按上述配置开通。");
|
|
2121
|
+
messageLines.push(`(如需取消或修改,请勿传 confirm="yes",改传其他参数重试)`);
|
|
1772
2122
|
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
1773
2123
|
ok: false,
|
|
1774
2124
|
code: "CONFIRM_REQUIRED",
|
|
1775
|
-
message:
|
|
2125
|
+
message: messageLines.join("\n"),
|
|
2126
|
+
package_info: packageTitle
|
|
2127
|
+
? { packageId, packageTitle }
|
|
2128
|
+
: packageId
|
|
2129
|
+
? { packageId, packageTitle: null }
|
|
2130
|
+
: undefined,
|
|
2131
|
+
pricing: priceSection
|
|
2132
|
+
? {
|
|
2133
|
+
summary: priceSection.summary,
|
|
2134
|
+
currency: priceProbe.priceResult?.Currency,
|
|
2135
|
+
realTotalCost: priceProbe.priceResult?.RealTotalCost,
|
|
2136
|
+
totalCost: priceProbe.priceResult?.TotalCost,
|
|
2137
|
+
timeSpan: priceProbe.priceResult?.TimeSpan,
|
|
2138
|
+
timeUnit: priceProbe.priceResult?.TimeUnit,
|
|
2139
|
+
inquiryRegion: pricingRegion,
|
|
2140
|
+
}
|
|
2141
|
+
: priceProbe.error
|
|
2142
|
+
? { inquiryFailed: true, error: priceProbe.error }
|
|
2143
|
+
: undefined,
|
|
2144
|
+
release_method: {
|
|
2145
|
+
...releaseMethod,
|
|
2146
|
+
detail: buildReleaseMethodDetailText(packageId),
|
|
2147
|
+
docLinks: [
|
|
2148
|
+
MANAGE_ENV_DOC_LINKS.package,
|
|
2149
|
+
MANAGE_ENV_DOC_LINKS.prepayExpiry,
|
|
2150
|
+
],
|
|
2151
|
+
},
|
|
2152
|
+
doc_links: MANAGE_ENV_DOC_LINKS,
|
|
2153
|
+
confirmation_acknowledgement: {
|
|
2154
|
+
text: "我已知晓将创建付费资源及计费规则",
|
|
2155
|
+
required: true,
|
|
2156
|
+
},
|
|
1776
2157
|
next_step: {
|
|
1777
2158
|
tool: "manageEnv",
|
|
1778
2159
|
action: "create",
|
|
@@ -1808,10 +2189,91 @@ function registerEnvTools(server) {
|
|
|
1808
2189
|
if (!envId || !packageId) {
|
|
1809
2190
|
throw new Error("变更套餐时 envId 和 packageId 为必填参数");
|
|
1810
2191
|
}
|
|
2192
|
+
// 查询当前套餐名 + 新套餐名 + 询价(失败降级)
|
|
2193
|
+
const [currentBilling, newPackageTitle] = await Promise.all([
|
|
2194
|
+
fetchEnvBillingSummary(cloudbase, envId),
|
|
2195
|
+
fetchPackageTitle(cloudbase, packageId),
|
|
2196
|
+
]);
|
|
2197
|
+
const priceProbe = await calculateModifyPrice(cloudbase, envId, packageId);
|
|
2198
|
+
const priceSection = priceProbe.priceResult
|
|
2199
|
+
? formatPriceSection(priceProbe.priceResult)
|
|
2200
|
+
: null;
|
|
2201
|
+
const releaseMethod = buildReleaseMethodHint();
|
|
2202
|
+
const messageLines = [];
|
|
2203
|
+
messageLines.push(`变更环境 ${envId} 的套餐需要您确认。变配后不会立即重新计费,但会触发差价结算或退款。`);
|
|
2204
|
+
messageLines.push("请核对后传入 confirm=\"yes\":");
|
|
2205
|
+
messageLines.push(`- 当前套餐: ${currentBilling?.packageName ?? currentBilling?.packageId ?? "(未知)"}` +
|
|
2206
|
+
(currentBilling?.packageId && currentBilling.packageName
|
|
2207
|
+
? `(${currentBilling.packageId})`
|
|
2208
|
+
: ""));
|
|
2209
|
+
if (currentBilling?.expireTime) {
|
|
2210
|
+
messageLines.push(`- 当前到期时间: ${currentBilling.expireTime}`);
|
|
2211
|
+
}
|
|
2212
|
+
messageLines.push(`- 新套餐: ${packageId}` +
|
|
2213
|
+
(newPackageTitle ? `(${newPackageTitle})` : ""));
|
|
2214
|
+
messageLines.push("");
|
|
2215
|
+
if (priceSection) {
|
|
2216
|
+
messageLines.push(`预计费用变化:${priceSection.summary}(差价/退款以账单为准)`);
|
|
2217
|
+
if (priceSection.detail) {
|
|
2218
|
+
messageLines.push(priceSection.detail);
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
else if (priceProbe.error) {
|
|
2222
|
+
messageLines.push(`预计费用变化:⚠️ 询价失败(${priceProbe.error}),请前往控制台确认价格`);
|
|
2223
|
+
}
|
|
2224
|
+
else {
|
|
2225
|
+
messageLines.push("预计费用变化:询价返回为空,请前往控制台确认价格");
|
|
2226
|
+
}
|
|
2227
|
+
messageLines.push("");
|
|
2228
|
+
// 资源释放方式(变配不影响存续,但与到期/销毁规则相同)
|
|
2229
|
+
messageLines.push(buildReleaseMethodDetailText(packageId));
|
|
2230
|
+
messageLines.push("");
|
|
2231
|
+
// 文档链接(变配与套餐/计费/到期都相关)
|
|
2232
|
+
messageLines.push(renderDocLinksBlock(["package", "prepayExpiry"]));
|
|
2233
|
+
messageLines.push("");
|
|
2234
|
+
messageLines.push("☐ 我已知晓变配将触发差价结算或退款,确认按上述配置变更。");
|
|
2235
|
+
messageLines.push(`(如需取消或修改,请勿传 confirm="yes")`);
|
|
1811
2236
|
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
1812
2237
|
ok: false,
|
|
1813
2238
|
code: "CONFIRM_REQUIRED",
|
|
1814
|
-
message:
|
|
2239
|
+
message: messageLines.join("\n"),
|
|
2240
|
+
env_id: envId,
|
|
2241
|
+
current_package: currentBilling
|
|
2242
|
+
? {
|
|
2243
|
+
packageId: currentBilling.packageId,
|
|
2244
|
+
packageName: currentBilling.packageName,
|
|
2245
|
+
expireTime: currentBilling.expireTime,
|
|
2246
|
+
payMode: currentBilling.payMode,
|
|
2247
|
+
}
|
|
2248
|
+
: undefined,
|
|
2249
|
+
new_package: {
|
|
2250
|
+
packageId,
|
|
2251
|
+
packageTitle: newPackageTitle ?? null,
|
|
2252
|
+
},
|
|
2253
|
+
pricing: priceSection
|
|
2254
|
+
? {
|
|
2255
|
+
summary: priceSection.summary,
|
|
2256
|
+
currency: priceProbe.priceResult?.Currency,
|
|
2257
|
+
realTotalCost: priceProbe.priceResult?.RealTotalCost,
|
|
2258
|
+
totalCost: priceProbe.priceResult?.TotalCost,
|
|
2259
|
+
refund: priceProbe.priceResult?.Refund,
|
|
2260
|
+
}
|
|
2261
|
+
: priceProbe.error
|
|
2262
|
+
? { inquiryFailed: true, error: priceProbe.error }
|
|
2263
|
+
: undefined,
|
|
2264
|
+
release_method: {
|
|
2265
|
+
...releaseMethod,
|
|
2266
|
+
detail: buildReleaseMethodDetailText(packageId),
|
|
2267
|
+
docLinks: [MANAGE_ENV_DOC_LINKS.prepayExpiry],
|
|
2268
|
+
},
|
|
2269
|
+
doc_links: {
|
|
2270
|
+
package: MANAGE_ENV_DOC_LINKS.package,
|
|
2271
|
+
prepayExpiry: MANAGE_ENV_DOC_LINKS.prepayExpiry,
|
|
2272
|
+
},
|
|
2273
|
+
confirmation_acknowledgement: {
|
|
2274
|
+
text: "我已知晓变配将触发差价结算或退款",
|
|
2275
|
+
required: true,
|
|
2276
|
+
},
|
|
1815
2277
|
next_step: {
|
|
1816
2278
|
tool: "manageEnv",
|
|
1817
2279
|
action: "modifyPlan",
|
|
@@ -1841,10 +2303,87 @@ function registerEnvTools(server) {
|
|
|
1841
2303
|
if (!envId) {
|
|
1842
2304
|
throw new Error("续费环境时 envId 为必填参数");
|
|
1843
2305
|
}
|
|
2306
|
+
// 查询当前套餐名 + 到期时间 + 询价(失败降级)
|
|
2307
|
+
const [currentBilling, priceProbe] = await Promise.all([
|
|
2308
|
+
fetchEnvBillingSummary(cloudbase, envId),
|
|
2309
|
+
calculateRenewPrice(cloudbase, envId, duration),
|
|
2310
|
+
]);
|
|
2311
|
+
const priceSection = priceProbe.priceResult
|
|
2312
|
+
? formatPriceSection(priceProbe.priceResult)
|
|
2313
|
+
: null;
|
|
2314
|
+
const releaseMethod = buildReleaseMethodHint();
|
|
2315
|
+
const currentPackageId = currentBilling?.packageId;
|
|
2316
|
+
const messageLines = [];
|
|
2317
|
+
messageLines.push(`续费环境 ${envId} 需要您确认。续费按当前套餐类型计算,延长到期时间。`);
|
|
2318
|
+
messageLines.push("请核对后传入 confirm=\"yes\":");
|
|
2319
|
+
messageLines.push(`- 当前套餐: ${currentBilling?.packageName ?? currentBilling?.packageId ?? "(未知)"}` +
|
|
2320
|
+
(currentBilling?.packageId && currentBilling.packageName
|
|
2321
|
+
? `(${currentBilling.packageId})`
|
|
2322
|
+
: ""));
|
|
2323
|
+
if (currentBilling?.expireTime) {
|
|
2324
|
+
messageLines.push(`- 当前到期时间: ${currentBilling.expireTime}`);
|
|
2325
|
+
}
|
|
2326
|
+
messageLines.push(`- 续费时长: ${duration} 个月`);
|
|
2327
|
+
messageLines.push("");
|
|
2328
|
+
if (priceSection) {
|
|
2329
|
+
messageLines.push(`预计费用:${priceSection.summary}`);
|
|
2330
|
+
if (priceSection.detail) {
|
|
2331
|
+
messageLines.push(priceSection.detail);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
else if (priceProbe.error) {
|
|
2335
|
+
messageLines.push(`预计费用:⚠️ 询价失败(${priceProbe.error}),请前往控制台确认价格`);
|
|
2336
|
+
}
|
|
2337
|
+
else {
|
|
2338
|
+
messageLines.push("预计费用:询价返回为空,请前往控制台确认价格");
|
|
2339
|
+
}
|
|
2340
|
+
messageLines.push("");
|
|
2341
|
+
// 资源释放方式
|
|
2342
|
+
messageLines.push(buildReleaseMethodDetailText(currentPackageId));
|
|
2343
|
+
messageLines.push("");
|
|
2344
|
+
// 文档链接(续费主要看预付费与到期释放)
|
|
2345
|
+
messageLines.push(renderDocLinksBlock(["prepayExpiry"]));
|
|
2346
|
+
messageLines.push("");
|
|
2347
|
+
messageLines.push("☐ 我已知晓续费将延长当前套餐的到期时间,确认按上述配置续费。");
|
|
2348
|
+
messageLines.push(`(如需取消或修改,请勿传 confirm="yes")`);
|
|
1844
2349
|
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
1845
2350
|
ok: false,
|
|
1846
2351
|
code: "CONFIRM_REQUIRED",
|
|
1847
|
-
message:
|
|
2352
|
+
message: messageLines.join("\n"),
|
|
2353
|
+
env_id: envId,
|
|
2354
|
+
current_package: currentBilling
|
|
2355
|
+
? {
|
|
2356
|
+
packageId: currentBilling.packageId,
|
|
2357
|
+
packageName: currentBilling.packageName,
|
|
2358
|
+
expireTime: currentBilling.expireTime,
|
|
2359
|
+
payMode: currentBilling.payMode,
|
|
2360
|
+
isAutoRenew: currentBilling.isAutoRenew,
|
|
2361
|
+
}
|
|
2362
|
+
: undefined,
|
|
2363
|
+
pricing: priceSection
|
|
2364
|
+
? {
|
|
2365
|
+
summary: priceSection.summary,
|
|
2366
|
+
currency: priceProbe.priceResult?.Currency,
|
|
2367
|
+
realTotalCost: priceProbe.priceResult?.RealTotalCost,
|
|
2368
|
+
totalCost: priceProbe.priceResult?.TotalCost,
|
|
2369
|
+
timeSpan: priceProbe.priceResult?.TimeSpan,
|
|
2370
|
+
timeUnit: priceProbe.priceResult?.TimeUnit,
|
|
2371
|
+
}
|
|
2372
|
+
: priceProbe.error
|
|
2373
|
+
? { inquiryFailed: true, error: priceProbe.error }
|
|
2374
|
+
: undefined,
|
|
2375
|
+
release_method: {
|
|
2376
|
+
...releaseMethod,
|
|
2377
|
+
detail: buildReleaseMethodDetailText(currentPackageId),
|
|
2378
|
+
docLinks: [MANAGE_ENV_DOC_LINKS.prepayExpiry],
|
|
2379
|
+
},
|
|
2380
|
+
doc_links: {
|
|
2381
|
+
prepayExpiry: MANAGE_ENV_DOC_LINKS.prepayExpiry,
|
|
2382
|
+
},
|
|
2383
|
+
confirmation_acknowledgement: {
|
|
2384
|
+
text: "我已知晓续费将延长当前套餐的到期时间",
|
|
2385
|
+
required: true,
|
|
2386
|
+
},
|
|
1848
2387
|
next_step: {
|
|
1849
2388
|
tool: "manageEnv",
|
|
1850
2389
|
action: "renew",
|
|
@@ -2233,7 +2772,7 @@ ${envIdSection}
|
|
|
2233
2772
|
## 环境信息
|
|
2234
2773
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
2235
2774
|
- Node.js版本: ${process.version}
|
|
2236
|
-
- MCP 版本:${process.env.npm_package_version || "2.25.
|
|
2775
|
+
- MCP 版本:${process.env.npm_package_version || "2.25.3" || 0}
|
|
2237
2776
|
- 系统架构: ${os_1.default.arch()}
|
|
2238
2777
|
- 时间: ${new Date().toISOString()}
|
|
2239
2778
|
- 请求ID: ${requestId}
|
|
@@ -2314,7 +2853,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
2314
2853
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
2315
2854
|
ide: server.ide || process.env.INTEGRATION_IDE || ''
|
|
2316
2855
|
});
|
|
2317
|
-
const mcpVersion = true ? "2.25.
|
|
2856
|
+
const mcpVersion = true ? "2.25.3" : 0;
|
|
2318
2857
|
const requestIdSuffix = requestId ? `\n🆔 RequestId: ${requestId}` : '';
|
|
2319
2858
|
const enhancedErrorMessage = `${errorMessage}${requestIdSuffix}\n\n📦 CloudBase MCP v${mcpVersion}\n🔗 遇到问题?请复制以下链接到浏览器打开\n即可自动携带错误详情快速创建 GitHub Issue:\n${issueLink}`;
|
|
2320
2859
|
// 创建新的错误对象,保持原有的错误类型但更新消息
|
|
@@ -7309,6 +7848,8 @@ const MANAGE_GATEWAY_ACTIONS = [
|
|
|
7309
7848
|
"bindCustomDomain",
|
|
7310
7849
|
"deleteCustomDomain",
|
|
7311
7850
|
];
|
|
7851
|
+
/** DomainType of the environment default HTTP service (gateway) domain. */
|
|
7852
|
+
const HTTP_SERVICE_DOMAIN_TYPE = "HTTPSERVICE";
|
|
7312
7853
|
const UPSTREAM_RESOURCE_TYPES = [
|
|
7313
7854
|
"SCF",
|
|
7314
7855
|
"WEB_SCF",
|
|
@@ -7345,21 +7886,19 @@ function registerGatewayTools(server) {
|
|
|
7345
7886
|
return (0, json_content_js_1.jsonContent)(buildErrorEnvelope(error));
|
|
7346
7887
|
}
|
|
7347
7888
|
};
|
|
7348
|
-
const listHttpServiceRoutes = async (
|
|
7889
|
+
const listHttpServiceRoutes = async (options) => {
|
|
7890
|
+
const filters = [];
|
|
7891
|
+
if (options?.domain) {
|
|
7892
|
+
filters.push({ Name: "Domain", Values: [options.domain] });
|
|
7893
|
+
}
|
|
7894
|
+
if (options?.domainType) {
|
|
7895
|
+
filters.push({ Name: "DomainType", Values: [options.domainType] });
|
|
7896
|
+
}
|
|
7349
7897
|
const cloudbase = await getManager();
|
|
7350
7898
|
const result = await cloudbase.env.describeHttpServiceRoute({
|
|
7351
7899
|
EnvId: await resolveEnvId(),
|
|
7352
7900
|
Limit: 1000,
|
|
7353
|
-
...(
|
|
7354
|
-
? {
|
|
7355
|
-
Filters: [
|
|
7356
|
-
{
|
|
7357
|
-
Name: "Domain",
|
|
7358
|
-
Values: [domain],
|
|
7359
|
-
},
|
|
7360
|
-
],
|
|
7361
|
-
}
|
|
7362
|
-
: {}),
|
|
7901
|
+
...(filters.length ? { Filters: filters } : {}),
|
|
7363
7902
|
});
|
|
7364
7903
|
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
7365
7904
|
return result;
|
|
@@ -7398,15 +7937,27 @@ function registerGatewayTools(server) {
|
|
|
7398
7937
|
: {}),
|
|
7399
7938
|
};
|
|
7400
7939
|
};
|
|
7940
|
+
const pickUsableDefaultDomain = (domains) => {
|
|
7941
|
+
const candidates = domains.filter((item) => item.IsDefault === true && item.Domain);
|
|
7942
|
+
return (candidates.find((item) => item.Enable !== false && item.Status === "SUCCESS") ??
|
|
7943
|
+
candidates.find((item) => item.Enable !== false) ??
|
|
7944
|
+
candidates[0]);
|
|
7945
|
+
};
|
|
7401
7946
|
const resolveDefaultHttpDomain = async () => {
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
const
|
|
7406
|
-
|
|
7407
|
-
|
|
7947
|
+
// Match console DescribeHTTPServiceRoute usage: filter DomainType=HTTPSERVICE.
|
|
7948
|
+
// Envs often also expose an IsDefault STATIC_STORE domain (*.tcloudbaseapp.com);
|
|
7949
|
+
// that is NOT the default HTTP access entry (*.{region}.app.tcloudbase.com).
|
|
7950
|
+
const httpServiceRoutes = await listHttpServiceRoutes({
|
|
7951
|
+
domainType: HTTP_SERVICE_DOMAIN_TYPE,
|
|
7952
|
+
});
|
|
7953
|
+
// Always re-filter client-side: some SDKs/mocks may ignore Filters.
|
|
7954
|
+
let preferred = pickUsableDefaultDomain((httpServiceRoutes.Domains ?? []).filter((item) => item.DomainType === HTTP_SERVICE_DOMAIN_TYPE));
|
|
7955
|
+
if (!preferred?.Domain) {
|
|
7956
|
+
const allRoutes = await listHttpServiceRoutes();
|
|
7957
|
+
preferred = pickUsableDefaultDomain((allRoutes.Domains ?? []).filter((item) => item.DomainType === HTTP_SERVICE_DOMAIN_TYPE));
|
|
7958
|
+
}
|
|
7408
7959
|
if (!preferred?.Domain) {
|
|
7409
|
-
throw new Error("环境默认 HTTP 访问域名未就绪或未开通。请先在控制台开通 HTTP 访问服务,或用 queryGateway(action=\"listRoutes\") 确认 Domains 中是否存在 IsDefault=true
|
|
7960
|
+
throw new Error("环境默认 HTTP 访问域名未就绪或未开通。请先在控制台开通 HTTP 访问服务,或用 queryGateway(action=\"listRoutes\") 确认 Domains 中是否存在 DomainType=HTTPSERVICE 且 IsDefault=true 的域名(形如 *.{region}.app.tcloudbase.com);不要使用静态托管域名(*.tcloudbaseapp.com)。也可以显式传入 domain 后重试 createRoute/updateRoute/deleteRoute。");
|
|
7410
7961
|
}
|
|
7411
7962
|
return preferred.Domain;
|
|
7412
7963
|
};
|
|
@@ -7502,7 +8053,7 @@ function registerGatewayTools(server) {
|
|
|
7502
8053
|
}, `已获取 ${customDomains.length} 个自定义域名`);
|
|
7503
8054
|
}
|
|
7504
8055
|
case "listRoutes": {
|
|
7505
|
-
const result = await listHttpServiceRoutes(input.domain);
|
|
8056
|
+
const result = await listHttpServiceRoutes({ domain: input.domain });
|
|
7506
8057
|
const routes = flattenRoutes(result);
|
|
7507
8058
|
return buildEnvelope({
|
|
7508
8059
|
action: input.action,
|
|
@@ -7517,7 +8068,7 @@ function registerGatewayTools(server) {
|
|
|
7517
8068
|
if (!input.routeId && !input.targetName && !input.path) {
|
|
7518
8069
|
throw new Error("action=getRoute 时至少需要提供 routeId、targetName 或 path");
|
|
7519
8070
|
}
|
|
7520
|
-
const result = await listHttpServiceRoutes(input.domain);
|
|
8071
|
+
const result = await listHttpServiceRoutes({ domain: input.domain });
|
|
7521
8072
|
const normalizedPath = input.path
|
|
7522
8073
|
? normalizeAccessPath(input.path)
|
|
7523
8074
|
: undefined;
|
|
@@ -7715,11 +8266,13 @@ function registerGatewayTools(server) {
|
|
|
7715
8266
|
title: "查询 CloudBase 网关",
|
|
7716
8267
|
description: "CloudBase HTTP 网关统一只读入口(Domain/Route)。查询域名下路径路由及其上游:" +
|
|
7717
8268
|
"WEB_SCF/SCF=云函数,CBR=云托管,STATIC_STORE=静态托管,LH=轻量应用服务器。" +
|
|
7718
|
-
"主键为 Domain + Path;listRoutes / getRoute / listCustomDomains。"
|
|
8269
|
+
"主键为 Domain + Path;listRoutes / getRoute / listCustomDomains。" +
|
|
8270
|
+
"实现自定义域名访问前,先 listCustomDomains:若已有自定义域名,优先 createRoute 挂路由(无需证书 ID);仅在没有可用自定义域名时才 bindCustomDomain。",
|
|
7719
8271
|
inputSchema: {
|
|
7720
8272
|
action: zod_1.z
|
|
7721
8273
|
.enum(QUERY_GATEWAY_ACTIONS)
|
|
7722
|
-
.describe("只读操作类型:listRoutes、getRoute、listCustomDomains"
|
|
8274
|
+
.describe("只读操作类型:listRoutes、getRoute、listCustomDomains。" +
|
|
8275
|
+
"自定义域名访问场景先 listCustomDomains 确认是否已有域名可复用。"),
|
|
7723
8276
|
targetName: zod_1.z
|
|
7724
8277
|
.string()
|
|
7725
8278
|
.optional()
|
|
@@ -7742,18 +8295,23 @@ function registerGatewayTools(server) {
|
|
|
7742
8295
|
}, async (input) => withEnvelope(() => handleQueryGateway(input)));
|
|
7743
8296
|
server.registerTool?.("manageGateway", {
|
|
7744
8297
|
title: "管理 CloudBase 网关",
|
|
7745
|
-
description: "CloudBase HTTP 网关统一写入口(Domain/Route)。createRoute/updateRoute/deleteRoute 把域名下的 path 转到上游;未传 domain 时用 IsDefault
|
|
8298
|
+
description: "CloudBase HTTP 网关统一写入口(Domain/Route)。createRoute/updateRoute/deleteRoute 把域名下的 path 转到上游;未传 domain 时用 DomainType=HTTPSERVICE 的 IsDefault 默认 HTTP 域名(形如 *.{region}.app.tcloudbase.com),不会使用静态托管 CDN 域名(*.tcloudbaseapp.com,DomainType=STATIC_STORE)。" +
|
|
8299
|
+
"这是网关默认域上的路径路由,不是 STATIC_STORE 上游绑定;STATIC_STORE 上游必须显式传 upstreamResourceType=STATIC_STORE。" +
|
|
8300
|
+
"创建后可用 queryGateway(action=\"listRoutes\") 核对 Domain / DomainType / Path / UpstreamResourceType。" +
|
|
7746
8301
|
"上游类型只用一个参数 upstreamResourceType(也可写在 route.upstreamResourceType,route 优先):" +
|
|
7747
8302
|
"WEB_SCF=HTTP云函数,SCF=Event云函数,CBR=云托管,STATIC_STORE=静态托管,LH=轻量应用服务器;" +
|
|
7748
8303
|
"配合 targetName 或 route.serviceName(云函数名/云托管服务名/静态托管实例名,常见 staticstore)。" +
|
|
7749
8304
|
"createRoute 只建网关入口,不改上游权限。" +
|
|
7750
8305
|
"enablePathTransmission:默认 false 剥触发路径前缀;true 透传完整路径(CBR 多路由、WEB_SCF 自管子路径常需 true;STATIC_STORE 自定义触发路径映射站点根通常 false)。" +
|
|
7751
|
-
"⚠️
|
|
8306
|
+
"⚠️ 自定义域名访问:若环境已有自定义域名(先 queryGateway listCustomDomains),优先 createRoute 并显式传入该 domain,无需 certificateId;" +
|
|
8307
|
+
"仅首次绑定全新自定义域名时用 bindCustomDomain(需 certificateId)。CORS/安全域名用 envDomainManagement。",
|
|
7752
8308
|
inputSchema: {
|
|
7753
8309
|
action: zod_1.z
|
|
7754
8310
|
.enum(MANAGE_GATEWAY_ACTIONS)
|
|
7755
8311
|
.describe("写操作:createRoute/updateRoute/deleteRoute 管理路由;bindCustomDomain/deleteCustomDomain 管理自定义域名。" +
|
|
7756
|
-
"createRoute/updateRoute 必须提供 upstreamResourceType。"
|
|
8312
|
+
"createRoute/updateRoute 必须提供 upstreamResourceType。" +
|
|
8313
|
+
"已有自定义域名时优先 createRoute(domain=已有域名) 实现访问,不必再次 bindCustomDomain / 传入 certificateId;" +
|
|
8314
|
+
"bindCustomDomain 仅用于首次绑定新域名。"),
|
|
7757
8315
|
targetName: zod_1.z
|
|
7758
8316
|
.string()
|
|
7759
8317
|
.optional()
|
|
@@ -7807,11 +8365,15 @@ function registerGatewayTools(server) {
|
|
|
7807
8365
|
domain: zod_1.z
|
|
7808
8366
|
.string()
|
|
7809
8367
|
.optional()
|
|
7810
|
-
.describe("域名。省略时自动使用环境 IsDefault 默认 HTTP
|
|
8368
|
+
.describe("域名。省略时自动使用环境 DomainType=HTTPSERVICE 的 IsDefault 默认 HTTP 域名(*.{region}.app.tcloudbase.com),不会回退到静态托管 CDN 域名(*.tcloudbaseapp.com,DomainType=STATIC_STORE);也不是 STATIC_STORE 上游绑定。" +
|
|
8369
|
+
"可用 queryGateway(action=\"listRoutes\") 核对实际 Domain / DomainType。" +
|
|
8370
|
+
"已有自定义域名时请显式传入该域名并 createRoute/updateRoute/deleteRoute,即可实现自定义域名访问且无需证书 ID;" +
|
|
8371
|
+
"仅 bindCustomDomain 时表示要新绑定的域名。"),
|
|
7811
8372
|
certificateId: zod_1.z
|
|
7812
8373
|
.string()
|
|
7813
8374
|
.optional()
|
|
7814
|
-
.describe("证书 ID
|
|
8375
|
+
.describe("证书 ID。仅首次 bindCustomDomain 必填。" +
|
|
8376
|
+
"在已有自定义域名上 createRoute / updateRoute / deleteRoute 不需要 certificateId。"),
|
|
7815
8377
|
},
|
|
7816
8378
|
annotations: {
|
|
7817
8379
|
readOnlyHint: false,
|
|
@@ -9964,6 +10526,31 @@ function registerAppAuthTools(server) {
|
|
|
9964
10526
|
return (0, json_content_js_1.jsonContent)(buildErrorEnvelope(error));
|
|
9965
10527
|
}
|
|
9966
10528
|
};
|
|
10529
|
+
// Best-effort inventory read used to verify whether CreateApiKey really produced a new key.
|
|
10530
|
+
// A failure here must not block key creation, so it returns null to mark "unknown"
|
|
10531
|
+
// rather than an empty list, which would be indistinguishable from "no keys exist".
|
|
10532
|
+
const listApiKeyRecords = async (cloudbase, keyType) => {
|
|
10533
|
+
try {
|
|
10534
|
+
const result = await cloudbase.env.describeApiKeyList({
|
|
10535
|
+
KeyType: keyType,
|
|
10536
|
+
PageNumber: 1,
|
|
10537
|
+
PageSize: 50,
|
|
10538
|
+
});
|
|
10539
|
+
return extractApiKeyList(result);
|
|
10540
|
+
}
|
|
10541
|
+
catch {
|
|
10542
|
+
return null;
|
|
10543
|
+
}
|
|
10544
|
+
};
|
|
10545
|
+
const listApiKeyIds = async (cloudbase, keyType) => {
|
|
10546
|
+
const records = await listApiKeyRecords(cloudbase, keyType);
|
|
10547
|
+
if (records === null) {
|
|
10548
|
+
return null;
|
|
10549
|
+
}
|
|
10550
|
+
return new Set(records
|
|
10551
|
+
.map((item) => (typeof item.KeyId === "string" ? item.KeyId : null))
|
|
10552
|
+
.filter((item) => item !== null));
|
|
10553
|
+
};
|
|
9967
10554
|
const describePublishableKey = async (cloudbase, envId) => {
|
|
9968
10555
|
const result = await cloudbase.env.describeApiKeyList({ KeyType: "publish_key", PageNumber: 1, PageSize: 10 });
|
|
9969
10556
|
return {
|
|
@@ -10084,7 +10671,7 @@ function registerAppAuthTools(server) {
|
|
|
10084
10671
|
}));
|
|
10085
10672
|
server.registerTool?.("manageAppAuth", {
|
|
10086
10673
|
title: "管理 CloudBase 应用认证配置",
|
|
10087
|
-
description: "CloudBase 应用侧认证配置写入口。用于修改登录方式、provider、client 配置,确保 publishable key,以及创建或删除 API key、自定义登录密钥。⚠️ 本工具为管理端配置工具,不执行用户登录。当任务要求编写客户端登录代码时(例如「用 JS SDK 登录」),应先通过本工具完成配置(如启用 usernamePassword、获取 publishable key),再在项目代码中编写 @cloudbase/js-sdk 客户端登录代码(如 auth.signInWithPassword()),而非使用本工具完成登录。若前端要接受普通用户名样式标识符,应先执行 action=patchLoginStrategy 并传入 patch={ usernamePassword: true }
|
|
10674
|
+
description: "CloudBase 应用侧认证配置写入口。用于修改登录方式、provider、client 配置,确保 publishable key,以及创建或删除 API key、自定义登录密钥。⚠️ 本工具为管理端配置工具,不执行用户登录。当任务要求编写客户端登录代码时(例如「用 JS SDK 登录」),应先通过本工具完成配置(如启用 usernamePassword、获取 publishable key),再在项目代码中编写 @cloudbase/js-sdk 客户端登录代码(如 auth.signInWithPassword()),而非使用本工具完成登录。若前端要接受普通用户名样式标识符,应先执行 action=patchLoginStrategy 并传入 patch={ usernamePassword: true },再实现对应前端登录逻辑。⚠️ action=createApiKey 返回体中的 created 字段表示是否真正新建:created=false 说明复用了环境中已存在的 key,此时 keyName/expireIn 入参不会生效,返回的 keyName/expireAt 均为服务端真实值,并会附带 warnings,切勿把它当作临时凭证分发。",
|
|
10088
10675
|
inputSchema: {
|
|
10089
10676
|
action: zod_1.z.enum(MANAGE_APP_AUTH_ACTIONS),
|
|
10090
10677
|
patch: zod_1.z
|
|
@@ -10109,8 +10696,16 @@ function registerAppAuthTools(server) {
|
|
|
10109
10696
|
.enum(APP_AUTH_KEY_TYPES)
|
|
10110
10697
|
.optional()
|
|
10111
10698
|
.describe("createApiKey 时的 API key 类型,默认 publish_key"),
|
|
10112
|
-
keyName: zod_1.z
|
|
10113
|
-
|
|
10699
|
+
keyName: zod_1.z
|
|
10700
|
+
.string()
|
|
10701
|
+
.optional()
|
|
10702
|
+
.describe("createApiKey 时的 API key 名称;服务端可能忽略该值(如 publish_key 每环境唯一时),返回体中的 keyName 一律为服务端实际存储的名称"),
|
|
10703
|
+
expireIn: zod_1.z
|
|
10704
|
+
.number()
|
|
10705
|
+
.int()
|
|
10706
|
+
.min(0)
|
|
10707
|
+
.optional()
|
|
10708
|
+
.describe("createApiKey 时的有效期,单位秒;0 表示不过期。复用已有 key 时该值不生效,此时返回体会带 created=false 与 warnings"),
|
|
10114
10709
|
keyId: zod_1.z.string().optional().describe("deleteApiKey 时的 API key 唯一标识"),
|
|
10115
10710
|
},
|
|
10116
10711
|
annotations: {
|
|
@@ -10235,6 +10830,7 @@ function registerAppAuthTools(server) {
|
|
|
10235
10830
|
}
|
|
10236
10831
|
case "createApiKey": {
|
|
10237
10832
|
const effectiveKeyType = keyType ?? "publish_key";
|
|
10833
|
+
const before = await listApiKeyIds(cloudbase, effectiveKeyType);
|
|
10238
10834
|
const result = await cloudbase.env.createApiKey({
|
|
10239
10835
|
KeyType: effectiveKeyType,
|
|
10240
10836
|
...(keyName ? { KeyName: keyName } : {}),
|
|
@@ -10242,19 +10838,44 @@ function registerAppAuthTools(server) {
|
|
|
10242
10838
|
});
|
|
10243
10839
|
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
10244
10840
|
const createApiKeyResult = normalizePlainObject(result, "createApiKeyResult") ?? {};
|
|
10841
|
+
const resultKeyId = typeof createApiKeyResult.KeyId === "string" ? createApiKeyResult.KeyId : null;
|
|
10842
|
+
const created = before === null || resultKeyId === null ? null : !before.has(resultKeyId);
|
|
10843
|
+
// The backend is the only source of truth for the stored name / expiry:
|
|
10844
|
+
// re-read the key record instead of echoing back the request parameters.
|
|
10845
|
+
const serverRecord = resultKeyId
|
|
10846
|
+
? (await listApiKeyRecords(cloudbase, effectiveKeyType))?.find((item) => item.KeyId === resultKeyId) ?? null
|
|
10847
|
+
: null;
|
|
10848
|
+
const keyNameSource = serverRecord ?? createApiKeyResult;
|
|
10849
|
+
const resolvedKeyName = getNonEmptyString(keyNameSource.Name) ??
|
|
10850
|
+
getNonEmptyString(keyNameSource.KeyName) ??
|
|
10851
|
+
null;
|
|
10852
|
+
const resolvedExpireAt = getNonEmptyString(serverRecord?.ExpireAt) ??
|
|
10853
|
+
getNonEmptyString(createApiKeyResult.ExpireAt) ??
|
|
10854
|
+
null;
|
|
10855
|
+
const resolvedCreatedAt = getNonEmptyString(serverRecord?.CreateAt) ??
|
|
10856
|
+
getNonEmptyString(createApiKeyResult.CreateAt) ??
|
|
10857
|
+
null;
|
|
10858
|
+
const warnings = [];
|
|
10859
|
+
if (created === false) {
|
|
10860
|
+
warnings.push(`keyType=${effectiveKeyType} 未创建新的 key,返回的是环境中已存在的 key(keyId=${resultKeyId})。若该类型每个环境唯一,请改用 action=ensurePublishableKey 语义理解此结果。`);
|
|
10861
|
+
}
|
|
10862
|
+
if (keyName && resolvedKeyName !== null && resolvedKeyName !== keyName) {
|
|
10863
|
+
warnings.push(`请求的 keyName="${keyName}" 未生效,服务端实际存储的名称为 "${resolvedKeyName}"。`);
|
|
10864
|
+
}
|
|
10865
|
+
if (typeof expireIn === "number" && created === false) {
|
|
10866
|
+
warnings.push(`请求的 expireIn=${expireIn} 未生效,返回的 key 使用其原有过期时间 ${resolvedExpireAt ?? "unknown"}。请勿将其视为临时凭证。`);
|
|
10867
|
+
}
|
|
10245
10868
|
return {
|
|
10246
10869
|
success: true,
|
|
10247
10870
|
envId,
|
|
10248
10871
|
keyType: effectiveKeyType,
|
|
10249
|
-
keyId:
|
|
10250
|
-
keyName:
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
expireAt: typeof result.ExpireAt === "string" ? result.ExpireAt : null,
|
|
10257
|
-
createdAt: typeof result.CreateAt === "string" ? result.CreateAt : null,
|
|
10872
|
+
keyId: resultKeyId,
|
|
10873
|
+
keyName: resolvedKeyName,
|
|
10874
|
+
apiKey: typeof createApiKeyResult.ApiKey === "string" ? createApiKeyResult.ApiKey : null,
|
|
10875
|
+
expireAt: resolvedExpireAt,
|
|
10876
|
+
createdAt: resolvedCreatedAt,
|
|
10877
|
+
...(typeof created === "boolean" ? { created } : {}),
|
|
10878
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
10258
10879
|
};
|
|
10259
10880
|
}
|
|
10260
10881
|
case "deleteApiKey": {
|
|
@@ -10356,7 +10977,7 @@ class TelemetryReporter {
|
|
|
10356
10977
|
const nodeVersion = process.version; // Node.js版本
|
|
10357
10978
|
const arch = os_1.default.arch(); // 系统架构
|
|
10358
10979
|
// 从构建时注入的版本号获取MCP版本信息
|
|
10359
|
-
const mcpVersion = process.env.npm_package_version || "2.25.
|
|
10980
|
+
const mcpVersion = process.env.npm_package_version || "2.25.3" || 0;
|
|
10360
10981
|
return {
|
|
10361
10982
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
10362
10983
|
deviceId: this.deviceId,
|
|
@@ -12337,6 +12958,68 @@ function isSchemaDdlRisk(risk, sql) {
|
|
|
12337
12958
|
function buildLocalMigrationFileHint(version, name) {
|
|
12338
12959
|
return `migrations/${version}_${name}.sql`;
|
|
12339
12960
|
}
|
|
12961
|
+
/** How many recent migration records to scan when verifying a freshly pushed version. */
|
|
12962
|
+
const MIGRATION_VERIFY_LIMIT = 100;
|
|
12963
|
+
/**
|
|
12964
|
+
* Collect every migration version mentioned anywhere in a migration-list API response.
|
|
12965
|
+
* The response shape is not strongly typed, so walk it generically and pick up any
|
|
12966
|
+
* `Version` / `MigrationVersion` string field instead of guessing a single container key.
|
|
12967
|
+
*/
|
|
12968
|
+
function collectMigrationVersions(value, found = new Set()) {
|
|
12969
|
+
if (Array.isArray(value)) {
|
|
12970
|
+
for (const item of value) {
|
|
12971
|
+
collectMigrationVersions(item, found);
|
|
12972
|
+
}
|
|
12973
|
+
return found;
|
|
12974
|
+
}
|
|
12975
|
+
if (value && typeof value === "object") {
|
|
12976
|
+
for (const [key, child] of Object.entries(value)) {
|
|
12977
|
+
if ((key === "Version" || key === "MigrationVersion") && typeof child === "string" && child.trim()) {
|
|
12978
|
+
found.add(child.trim());
|
|
12979
|
+
}
|
|
12980
|
+
else {
|
|
12981
|
+
collectMigrationVersions(child, found);
|
|
12982
|
+
}
|
|
12983
|
+
}
|
|
12984
|
+
}
|
|
12985
|
+
return found;
|
|
12986
|
+
}
|
|
12987
|
+
/** Brief retries before concluding a pushed migration never landed (Push can be async). */
|
|
12988
|
+
const MIGRATION_VERIFY_ATTEMPTS = 4;
|
|
12989
|
+
const MIGRATION_VERIFY_DELAY_MS = 1500;
|
|
12990
|
+
/**
|
|
12991
|
+
* Confirm a pushed migration version is present in the remote migration history.
|
|
12992
|
+
*
|
|
12993
|
+
* `PushPGUserMigrations` can return a TaskId without the migration actually being
|
|
12994
|
+
* applied, so the raw API response is not sufficient evidence of success. Retries
|
|
12995
|
+
* briefly to tolerate async application, then returns `true`/`false` when the
|
|
12996
|
+
* history could be read, or `null` when verification itself failed (in which case
|
|
12997
|
+
* the caller must not claim the migration is applied).
|
|
12998
|
+
*/
|
|
12999
|
+
async function verifyMigrationApplied(context, version, cloudBaseOptions) {
|
|
13000
|
+
let lastError;
|
|
13001
|
+
let sawSuccessfulList = false;
|
|
13002
|
+
for (let attempt = 1; attempt <= MIGRATION_VERIFY_ATTEMPTS; attempt++) {
|
|
13003
|
+
try {
|
|
13004
|
+
const history = await callPgMigrationApi(context, "ListPGUserMigrations", { Limit: MIGRATION_VERIFY_LIMIT }, cloudBaseOptions);
|
|
13005
|
+
sawSuccessfulList = true;
|
|
13006
|
+
if (collectMigrationVersions(history).has(version)) {
|
|
13007
|
+
return { applied: true };
|
|
13008
|
+
}
|
|
13009
|
+
}
|
|
13010
|
+
catch (error) {
|
|
13011
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
13012
|
+
// Keep retrying: a transient list failure should not immediately fail verification.
|
|
13013
|
+
}
|
|
13014
|
+
if (attempt < MIGRATION_VERIFY_ATTEMPTS) {
|
|
13015
|
+
await sleep(MIGRATION_VERIFY_DELAY_MS);
|
|
13016
|
+
}
|
|
13017
|
+
}
|
|
13018
|
+
if (sawSuccessfulList) {
|
|
13019
|
+
return { applied: false };
|
|
13020
|
+
}
|
|
13021
|
+
return { applied: null, error: lastError };
|
|
13022
|
+
}
|
|
12340
13023
|
const MIGRATION_VERSION_REQUIRED_MESSAGE = "migrationVersion is required (14-digit UTC timestamp YYYYMMDDHHMMSS). " +
|
|
12341
13024
|
"Decide the version first, write local file migrations/<version>_<migrationName>.sql, " +
|
|
12342
13025
|
"then call planMigration/applyMigration with the same migrationVersion and migrationName.";
|
|
@@ -13209,6 +13892,49 @@ async function handleApplyMigration(args, context, deps, cloudBaseOptions) {
|
|
|
13209
13892
|
}
|
|
13210
13893
|
try {
|
|
13211
13894
|
const result = await callPgMigrationApi(context, "PushPGUserMigrations", params, cloudBaseOptions);
|
|
13895
|
+
// PushPGUserMigrations may return a TaskId without the migration having taken
|
|
13896
|
+
// effect. Confirm against the remote history before reporting success, so callers
|
|
13897
|
+
// never get a false-positive success for a silently dropped migration.
|
|
13898
|
+
const verification = await verifyMigrationApplied(context, version, cloudBaseOptions);
|
|
13899
|
+
if (verification.applied === false) {
|
|
13900
|
+
return buildPgToolResult({
|
|
13901
|
+
success: false,
|
|
13902
|
+
errorCode: "MIGRATION_NOT_APPLIED",
|
|
13903
|
+
data: {
|
|
13904
|
+
migrationVersion: version,
|
|
13905
|
+
migrationName: args.migrationName,
|
|
13906
|
+
localFileHint,
|
|
13907
|
+
apiResult: result,
|
|
13908
|
+
verified: false,
|
|
13909
|
+
},
|
|
13910
|
+
message: `PushPGUserMigrations returned without error, but migrationVersion=${version} is not present in the remote migration history, ` +
|
|
13911
|
+
"so the migration did NOT take effect. Do not assume the schema change is applied. " +
|
|
13912
|
+
"Re-check the SQL and migrationVersion, inspect the migration with action=migrationDetail, and retry action=applyMigration. " +
|
|
13913
|
+
"If the schema change is urgent you may fall back to action=execute with allowDdlViaExecute=true, but that bypasses migration history.",
|
|
13914
|
+
nextActions: [
|
|
13915
|
+
buildNextAction(MANAGE_PG_DATABASE, "listMigrations", "Inspect the remote migration history to confirm the migration is missing.", { action: "listMigrations", limit: 20 }),
|
|
13916
|
+
buildNextAction(MANAGE_PG_DATABASE, "migrationDetail", "Inspect the backend record for this migrationVersion to find why it was not applied.", { action: "migrationDetail", migrationVersion: version }),
|
|
13917
|
+
],
|
|
13918
|
+
});
|
|
13919
|
+
}
|
|
13920
|
+
if (verification.applied === null) {
|
|
13921
|
+
return buildPgToolResult({
|
|
13922
|
+
success: false,
|
|
13923
|
+
errorCode: "MIGRATION_VERIFICATION_FAILED",
|
|
13924
|
+
data: {
|
|
13925
|
+
migrationVersion: version,
|
|
13926
|
+
migrationName: args.migrationName,
|
|
13927
|
+
localFileHint,
|
|
13928
|
+
apiResult: result,
|
|
13929
|
+
verified: null,
|
|
13930
|
+
},
|
|
13931
|
+
message: `PushPGUserMigrations was submitted, but verifying migrationVersion=${version} against the remote history failed: ${verification.error}. ` +
|
|
13932
|
+
"The migration may or may not have been applied — verify with action=listMigrations before running any dependent SQL.",
|
|
13933
|
+
nextActions: [
|
|
13934
|
+
buildNextAction(MANAGE_PG_DATABASE, "listMigrations", "Manually verify whether the remote migration history records this migrationVersion.", { action: "listMigrations", limit: 20 }),
|
|
13935
|
+
],
|
|
13936
|
+
});
|
|
13937
|
+
}
|
|
13212
13938
|
return buildPgToolResult({
|
|
13213
13939
|
success: true,
|
|
13214
13940
|
data: {
|
|
@@ -13216,11 +13942,9 @@ async function handleApplyMigration(args, context, deps, cloudBaseOptions) {
|
|
|
13216
13942
|
migrationName: args.migrationName,
|
|
13217
13943
|
localFileHint,
|
|
13218
13944
|
apiResult: result,
|
|
13945
|
+
verified: true,
|
|
13219
13946
|
},
|
|
13220
|
-
message: `Migrations applied via PushPGUserMigrations. Ensure local file ${localFileHint} exists and matches.`,
|
|
13221
|
-
nextActions: [
|
|
13222
|
-
buildNextAction(MANAGE_PG_DATABASE, "listMigrations", "Verify the remote migration history records the same migrationVersion.", { action: "listMigrations", limit: 20 }),
|
|
13223
|
-
],
|
|
13947
|
+
message: `Migrations applied via PushPGUserMigrations and verified present in the remote migration history. Ensure local file ${localFileHint} exists and matches.`,
|
|
13224
13948
|
});
|
|
13225
13949
|
}
|
|
13226
13950
|
catch (error) {
|
|
@@ -13499,7 +14223,7 @@ function registerPGDatabaseTools(server, providedDeps) {
|
|
|
13499
14223
|
inputSchema: {
|
|
13500
14224
|
action: zod_1.z
|
|
13501
14225
|
.enum(MANAGE_ACTIONS)
|
|
13502
|
-
.describe("操作类型:execute=执行已确认的写入 SQL(DML/GRANT/RLS;schema DDL 默认拒绝,需 allowDdlViaExecute=true);dryRun=只分析 SQL 风险不执行;planMigration=预览迁移计划(需 migrationName + migrationVersion + sql);applyMigration=应用迁移,建表/改 schema 首选(需 migrationName + migrationVersion + sql + confirm=true);listMigrations=查询已应用的 Migration 列表(可传 limit/offset 分页);migrationDetail=查看单条 Migration 详情(需 migrationVersion);rollbackMigration=回滚最近 N 条 Migration(需 lastN + confirm=true);repairMigration=修复 Migration 历史记录(需 migrationVersion + migrationName + repairStatus + repairReason)"),
|
|
14226
|
+
.describe("操作类型:execute=执行已确认的写入 SQL(DML/GRANT/RLS;schema DDL 默认拒绝,需 allowDdlViaExecute=true);dryRun=只分析 SQL 风险不执行;planMigration=预览迁移计划(需 migrationName + migrationVersion + sql);applyMigration=应用迁移,建表/改 schema 首选(需 migrationName + migrationVersion + sql + confirm=true;成功返回前会自动校验该 migrationVersion 已落入远端迁移历史,未落库时返回 success=false 且 errorCode=MIGRATION_NOT_APPLIED);listMigrations=查询已应用的 Migration 列表(可传 limit/offset 分页);migrationDetail=查看单条 Migration 详情(需 migrationVersion);rollbackMigration=回滚最近 N 条 Migration(需 lastN + confirm=true);repairMigration=修复 Migration 历史记录(需 migrationVersion + migrationName + repairStatus + repairReason)"),
|
|
13503
14227
|
sql: zod_1.z
|
|
13504
14228
|
.string()
|
|
13505
14229
|
.optional()
|
|
@@ -14735,7 +15459,7 @@ function registerSetupTools(server) {
|
|
|
14735
15459
|
server.registerTool("downloadTemplate", {
|
|
14736
15460
|
title: "下载项目模板",
|
|
14737
15461
|
description: `自动下载并部署CloudBase项目模板。
|
|
14738
|
-
**Note**: Call this tool when the user requests to create a new project using a CloudBase template.\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- 其他IDE类型见下方列表\n\n注意:如果未传入 ide 参数且无法从环境变量检测到 IDE,将提示错误并要求传入 ide 参数\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- kiro: Kiro AI编辑器\n- aider: Aider AI编辑器\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.25.
|
|
15462
|
+
**Note**: Call this tool when the user requests to create a new project using a CloudBase template.\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- 其他IDE类型见下方列表\n\n注意:如果未传入 ide 参数且无法从环境变量检测到 IDE,将提示错误并要求传入 ide 参数\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- kiro: Kiro AI编辑器\n- aider: Aider AI编辑器\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.25.3" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
14739
15463
|
inputSchema: {
|
|
14740
15464
|
template: zod_1.z
|
|
14741
15465
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -15662,6 +16386,17 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15662
16386
|
hasInitTcbError: !!newContext.initTcbError,
|
|
15663
16387
|
initTcbError: newContext.initTcbError
|
|
15664
16388
|
});
|
|
16389
|
+
// User-facing notice emitted at the entry: inform the user that an automatic
|
|
16390
|
+
// free-env creation is being attempted. Informational only — no confirm.
|
|
16391
|
+
// Built once up-front so every return path can surface the same notice.
|
|
16392
|
+
const userNotice = [
|
|
16393
|
+
"系统检测到您当前没有可用的 CloudBase 环境,将自动尝试为您创建一个免费环境。",
|
|
16394
|
+
"创建依据:通过 NewUser / ReturningUser / BaasFree 等优惠活动资格检查;",
|
|
16395
|
+
"环境别名:ai-native(默认);",
|
|
16396
|
+
"费用说明:该环境为免费活动赠送,创建过程不会产生费用;如不符合免费条件,将引导您前往购买页;",
|
|
16397
|
+
"流程说明:此为自动流程,无需您确认;创建成功后将自动绑定到当前会话。"
|
|
16398
|
+
].join("\n");
|
|
16399
|
+
(0, logger_js_1.debug)('[env-setup] User notice prepared:', { userNotice });
|
|
15665
16400
|
try {
|
|
15666
16401
|
// Step 1: Query promotional activities
|
|
15667
16402
|
(0, logger_js_1.debug)('[env-setup] Checking promotional activity eligibility...');
|
|
@@ -15701,7 +16436,8 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15701
16436
|
};
|
|
15702
16437
|
return {
|
|
15703
16438
|
success: false,
|
|
15704
|
-
context: newContext
|
|
16439
|
+
context: newContext,
|
|
16440
|
+
userNotice
|
|
15705
16441
|
};
|
|
15706
16442
|
}
|
|
15707
16443
|
(0, logger_js_1.debug)('[env-setup] User is eligible for free environment, attempting to create...');
|
|
@@ -15766,7 +16502,8 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15766
16502
|
};
|
|
15767
16503
|
return {
|
|
15768
16504
|
success: false,
|
|
15769
|
-
context: newContext
|
|
16505
|
+
context: newContext,
|
|
16506
|
+
userNotice
|
|
15770
16507
|
};
|
|
15771
16508
|
}
|
|
15772
16509
|
// Report create success
|
|
@@ -15780,7 +16517,8 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15780
16517
|
return {
|
|
15781
16518
|
success: true,
|
|
15782
16519
|
envId: envId.trim(), // Ensure no whitespace
|
|
15783
|
-
context: newContext
|
|
16520
|
+
context: newContext,
|
|
16521
|
+
userNotice
|
|
15784
16522
|
};
|
|
15785
16523
|
}
|
|
15786
16524
|
catch (createErr) {
|
|
@@ -15839,7 +16577,8 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15839
16577
|
});
|
|
15840
16578
|
return {
|
|
15841
16579
|
success: false,
|
|
15842
|
-
context: newContext
|
|
16580
|
+
context: newContext,
|
|
16581
|
+
userNotice
|
|
15843
16582
|
};
|
|
15844
16583
|
}
|
|
15845
16584
|
}
|
|
@@ -15860,7 +16599,8 @@ async function checkAndCreateFreeEnv(cloudbase, context) {
|
|
|
15860
16599
|
});
|
|
15861
16600
|
return {
|
|
15862
16601
|
success: false,
|
|
15863
|
-
context: newContext
|
|
16602
|
+
context: newContext,
|
|
16603
|
+
userNotice
|
|
15864
16604
|
};
|
|
15865
16605
|
}
|
|
15866
16606
|
}
|
|
@@ -18601,6 +19341,7 @@ const QUERY_ACTIONS = [
|
|
|
18601
19341
|
"describeTaskStatus",
|
|
18602
19342
|
"getInstanceInfo",
|
|
18603
19343
|
"describeInstance",
|
|
19344
|
+
"getConnectionInfo",
|
|
18604
19345
|
];
|
|
18605
19346
|
const MANAGE_ACTIONS = [
|
|
18606
19347
|
"provisionMySQL",
|
|
@@ -18608,6 +19349,17 @@ const MANAGE_ACTIONS = [
|
|
|
18608
19349
|
"runStatement",
|
|
18609
19350
|
"initializeSchema",
|
|
18610
19351
|
];
|
|
19352
|
+
function sanitizeInstanceInfo(instanceInfo) {
|
|
19353
|
+
return {
|
|
19354
|
+
exists: instanceInfo.exists,
|
|
19355
|
+
envId: instanceInfo.envId,
|
|
19356
|
+
instanceId: instanceInfo.instanceId,
|
|
19357
|
+
schema: instanceInfo.schema,
|
|
19358
|
+
rawStatus: instanceInfo.rawStatus,
|
|
19359
|
+
status: instanceInfo.status,
|
|
19360
|
+
...(instanceInfo.clusterId ? { clusterId: instanceInfo.clusterId } : {}),
|
|
19361
|
+
};
|
|
19362
|
+
}
|
|
18611
19363
|
function buildNextAction(tool, action, reason, suggestedArgs) {
|
|
18612
19364
|
return {
|
|
18613
19365
|
tool,
|
|
@@ -19056,11 +19808,12 @@ async function handleDescribeTaskStatus(args, context) {
|
|
|
19056
19808
|
}
|
|
19057
19809
|
async function handleGetInstanceInfo(context) {
|
|
19058
19810
|
const instanceInfo = await getSqlInstanceInfo(context);
|
|
19811
|
+
const sanitized = sanitizeInstanceInfo(instanceInfo);
|
|
19059
19812
|
return buildSqlToolResult({
|
|
19060
19813
|
success: true,
|
|
19061
|
-
data:
|
|
19814
|
+
data: sanitized,
|
|
19062
19815
|
message: instanceInfo.exists
|
|
19063
|
-
? "Resolved current SQL database instance context."
|
|
19816
|
+
? "Resolved current SQL database instance context (lifecycle only; connection credentials are omitted). Prefer SDK or runQuery/runStatement for app data access. Use getConnectionInfo only for explicit TCP migration."
|
|
19064
19817
|
: "No SQL database instance is currently available for this environment.",
|
|
19065
19818
|
nextActions: instanceInfo.exists
|
|
19066
19819
|
? undefined
|
|
@@ -19069,6 +19822,33 @@ async function handleGetInstanceInfo(context) {
|
|
|
19069
19822
|
],
|
|
19070
19823
|
});
|
|
19071
19824
|
}
|
|
19825
|
+
async function handleGetConnectionInfo(context) {
|
|
19826
|
+
const instanceInfo = await getSqlInstanceInfo(context);
|
|
19827
|
+
if (!instanceInfo.exists) {
|
|
19828
|
+
return buildSqlToolResult({
|
|
19829
|
+
success: false,
|
|
19830
|
+
errorCode: "MYSQL_NOT_CREATED",
|
|
19831
|
+
data: sanitizeInstanceInfo(instanceInfo),
|
|
19832
|
+
message: "No MySQL instance exists for the current environment, so connection details cannot be returned.",
|
|
19833
|
+
nextActions: [
|
|
19834
|
+
buildNextAction(MANAGE_MYSQL_DATABASE, "provisionMySQL", "Provision MySQL before requesting connection details.", { action: "provisionMySQL", confirm: true }),
|
|
19835
|
+
],
|
|
19836
|
+
});
|
|
19837
|
+
}
|
|
19838
|
+
return buildSqlToolResult({
|
|
19839
|
+
success: true,
|
|
19840
|
+
data: {
|
|
19841
|
+
...sanitizeInstanceInfo(instanceInfo),
|
|
19842
|
+
// Full backend passthrough for explicit TCP migration only (may include credentials).
|
|
19843
|
+
clusterDetail: instanceInfo.clusterDetail,
|
|
19844
|
+
createResult: instanceInfo.createResult,
|
|
19845
|
+
},
|
|
19846
|
+
message: "Returned raw MySQL connection/cluster payload for explicit TCP migration only. Prefer CloudBase SDK or queryMysqlDatabase(runQuery)/manageMysqlDatabase(runStatement) for normal app CRUD — do not treat this as the default data path.",
|
|
19847
|
+
nextActions: [
|
|
19848
|
+
buildNextAction(QUERY_MYSQL_DATABASE, "runQuery", "Prefer platform-delegated read-only SQL instead of embedding TCP credentials in app code.", { action: "runQuery", sql: "SELECT 1" }),
|
|
19849
|
+
],
|
|
19850
|
+
});
|
|
19851
|
+
}
|
|
19072
19852
|
async function handleProvisionMySQL(args, context) {
|
|
19073
19853
|
if (args.confirm !== true) {
|
|
19074
19854
|
return buildSqlToolResult({
|
|
@@ -19086,7 +19866,7 @@ async function handleProvisionMySQL(args, context) {
|
|
|
19086
19866
|
existing.status === "RUNNING") {
|
|
19087
19867
|
return buildSqlToolResult({
|
|
19088
19868
|
success: true,
|
|
19089
|
-
data: existing,
|
|
19869
|
+
data: sanitizeInstanceInfo(existing),
|
|
19090
19870
|
message: "A SQL database instance already exists for the current environment.",
|
|
19091
19871
|
nextActions: existing.status === "READY"
|
|
19092
19872
|
? [
|
|
@@ -19419,11 +20199,11 @@ function registerSQLDatabaseTools(server) {
|
|
|
19419
20199
|
};
|
|
19420
20200
|
server.registerTool?.(QUERY_MYSQL_DATABASE, {
|
|
19421
20201
|
title: "查询 CloudBase MySQL 数据库状态或执行只读 SQL",
|
|
19422
|
-
description: "查询 CloudBase MySQL 数据库信息。支持执行只读 SQL、查询 MySQL 开通结果、查询 MySQL
|
|
20202
|
+
description: "查询 CloudBase MySQL 数据库信息。支持执行只读 SQL、查询 MySQL 开通结果、查询 MySQL 任务状态,以及获取当前实例生命周期上下文。标准 getInstanceInfo/describeInstance 不返回连接凭据;仅 getConnectionInfo 透传原始连接/集群载荷(含可能的凭据),且仅用于显式 TCP 迁移。业务 CRUD 优先使用 SDK 或 runQuery/runStatement。",
|
|
19423
20203
|
inputSchema: {
|
|
19424
20204
|
action: zod_1.z
|
|
19425
20205
|
.enum(QUERY_ACTIONS)
|
|
19426
|
-
.describe("runQuery=execute read-only SQL; describeCreateResult=query CreateMySQL result; describeTaskStatus=query MySQL task status; getInstanceInfo=get
|
|
20206
|
+
.describe("runQuery=execute read-only SQL; describeCreateResult=query CreateMySQL result; describeTaskStatus=query MySQL task status; getInstanceInfo=get lifecycle context without connection credentials; describeInstance=alias of getInstanceInfo; getConnectionInfo=passthrough raw connection/cluster payload including possible credentials (TCP migration exception only)"),
|
|
19427
20207
|
sql: zod_1.z
|
|
19428
20208
|
.string()
|
|
19429
20209
|
.optional()
|
|
@@ -19459,6 +20239,8 @@ function registerSQLDatabaseTools(server) {
|
|
|
19459
20239
|
case "getInstanceInfo":
|
|
19460
20240
|
case "describeInstance":
|
|
19461
20241
|
return handleGetInstanceInfo(context);
|
|
20242
|
+
case "getConnectionInfo":
|
|
20243
|
+
return handleGetConnectionInfo(context);
|
|
19462
20244
|
default:
|
|
19463
20245
|
throw new Error(`Unsupported SQL query action: ${args.action}`);
|
|
19464
20246
|
}
|