@cloudbase/cloudbase-mcp 2.32.0 → 2.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +329 -47
- package/dist/index.d.ts +6 -0
- package/dist/index.js +297 -41
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -72571,6 +72571,8 @@ exports.QbaseError = exports.MSG_TYPES = exports.XPAY_EVENT_TYPES = void 0;
|
|
|
72571
72571
|
exports.mergeSubscribeList = mergeSubscribeList;
|
|
72572
72572
|
exports.mergeUnsubscribeList = mergeUnsubscribeList;
|
|
72573
72573
|
exports.mergeSetEnableList = mergeSetEnableList;
|
|
72574
|
+
exports.resolvePushMode = resolvePushMode;
|
|
72575
|
+
exports.pickContainerConfigPublic = pickContainerConfigPublic;
|
|
72574
72576
|
exports.registerMsgPushTools = registerMsgPushTools;
|
|
72575
72577
|
const zod_1 = __webpack_require__(7552);
|
|
72576
72578
|
const tool_result_js_1 = __webpack_require__(9835);
|
|
@@ -72857,6 +72859,25 @@ async function uploadCallbackConfig(server, appid, state) {
|
|
|
72857
72859
|
throw new QbaseError(ret, `uploadappconfig 失败(ret=${ret}): ${errmsg || "未知错误"}。请重新查询最新配置后重试。`);
|
|
72858
72860
|
}
|
|
72859
72861
|
}
|
|
72862
|
+
function resolvePushMode(container) {
|
|
72863
|
+
return container?.qbase_open === true ? "container" : "cloudfunction";
|
|
72864
|
+
}
|
|
72865
|
+
/** Public subset of container callback fields returned to agents */
|
|
72866
|
+
function pickContainerConfigPublic(container) {
|
|
72867
|
+
if (!container)
|
|
72868
|
+
return undefined;
|
|
72869
|
+
return {
|
|
72870
|
+
qbase_open: container.qbase_open === true,
|
|
72871
|
+
qbase_container_path: typeof container.qbase_container_path === "string"
|
|
72872
|
+
? container.qbase_container_path
|
|
72873
|
+
: undefined,
|
|
72874
|
+
qbase_env: typeof container.qbase_env === "string" ? container.qbase_env : undefined,
|
|
72875
|
+
text_mode: typeof container.text_mode === "number" ? container.text_mode : undefined,
|
|
72876
|
+
};
|
|
72877
|
+
}
|
|
72878
|
+
const CONTAINER_MODE_BLOCK_NOTE = "当前为云托管模式(整包接收),云函数 callbacks 存在但不生效;如需云函数模式请调 ensureCloudFunctionMode 切换";
|
|
72879
|
+
const CONTAINER_MODE_WRITE_ERROR = "当前 pushMode=container(云托管整包接收),云函数回调配置存在但不生效。" +
|
|
72880
|
+
"如需云函数模式请调 action=ensureCloudFunctionMode 切换。";
|
|
72860
72881
|
/** 读取云托管消息推送配置;无配置(云函数模式)返回 null */
|
|
72861
72882
|
async function readContainerConfig(server, appid) {
|
|
72862
72883
|
const resp = await callQbase(server, appid, "getContainerCallbackConfig", {});
|
|
@@ -72877,6 +72898,55 @@ async function setContainerConfig(server, appid, cfg) {
|
|
|
72877
72898
|
throw new QbaseError(ret, `setcontainercallbackconfig 失败(ret=${ret}): ${resp.base_resp?.errmsg ?? "未知错误"}`);
|
|
72878
72899
|
}
|
|
72879
72900
|
}
|
|
72901
|
+
function buildContainerModeBlockedPayload(action) {
|
|
72902
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
72903
|
+
ok: false,
|
|
72904
|
+
code: "CONTAINER_MODE_ACTIVE",
|
|
72905
|
+
pushMode: "container",
|
|
72906
|
+
message: CONTAINER_MODE_WRITE_ERROR,
|
|
72907
|
+
next_step: {
|
|
72908
|
+
tool: "manageMessagePush",
|
|
72909
|
+
action: "ensureCloudFunctionMode",
|
|
72910
|
+
required_params: ["appid", "env_id", "function_name", "confirm"],
|
|
72911
|
+
hint: `先切换到云函数模式后再执行 ${action}`,
|
|
72912
|
+
},
|
|
72913
|
+
});
|
|
72914
|
+
}
|
|
72915
|
+
/**
|
|
72916
|
+
* Verify function_name exists in envId via optional host hook or CloudBase Manager list.
|
|
72917
|
+
* Returns an error tool result when missing / unreadable; null when OK.
|
|
72918
|
+
*/
|
|
72919
|
+
async function assertCloudFunctionExists(server, envId, functionName) {
|
|
72920
|
+
const override = server.pluginOptions?.msgPush?.listCloudFunctions;
|
|
72921
|
+
// 兼容性降级:host 未提供 listCloudFunctions hook(如微信 IDE 无腾讯云凭据)时
|
|
72922
|
+
// 跳过存在性校验,保持原有 subscribe 行为(写配置不阻断);仅 host 显式启用时校验。
|
|
72923
|
+
if (!override) {
|
|
72924
|
+
return null;
|
|
72925
|
+
}
|
|
72926
|
+
let names;
|
|
72927
|
+
try {
|
|
72928
|
+
names = await override(envId);
|
|
72929
|
+
}
|
|
72930
|
+
catch (e) {
|
|
72931
|
+
// hook 本身失败(如网络/权限)时降级放行,不阻断订阅
|
|
72932
|
+
return null;
|
|
72933
|
+
}
|
|
72934
|
+
if (!names.includes(functionName)) {
|
|
72935
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
72936
|
+
ok: false,
|
|
72937
|
+
code: "FUNCTION_NOT_FOUND",
|
|
72938
|
+
message: `云函数 ${functionName} 不存在于环境 ${envId},请先创建或修正参数`,
|
|
72939
|
+
envId,
|
|
72940
|
+
function_name: functionName,
|
|
72941
|
+
next_step: {
|
|
72942
|
+
tool: "manageFunctions",
|
|
72943
|
+
action: "createFunction",
|
|
72944
|
+
required_params: ["functionName"],
|
|
72945
|
+
},
|
|
72946
|
+
});
|
|
72947
|
+
}
|
|
72948
|
+
return null;
|
|
72949
|
+
}
|
|
72880
72950
|
function buildTransportUnavailablePayload(toolName, action) {
|
|
72881
72951
|
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
72882
72952
|
ok: false,
|
|
@@ -72945,11 +73015,11 @@ function registerMsgPushTools(server) {
|
|
|
72945
73015
|
server.registerTool?.("queryMessagePush", {
|
|
72946
73016
|
title: "查询小程序消息推送配置",
|
|
72947
73017
|
description: "查询小程序云开发消息推送配置(qbase getappconfig)或全部合法消息推送事件约束(getcallbacksupportlist)。" +
|
|
72948
|
-
"
|
|
72949
|
-
"action=list
|
|
72950
|
-
"
|
|
72951
|
-
"
|
|
72952
|
-
"需要微信 IDE 登录态通道(宿主注入 cloudBaseOptions.requestFn
|
|
73018
|
+
"推送模式有两种:云函数(默认,按 (msgType,event) 逐条回调)与云托管(qbase_open=true,整包接收所有消息到容器 path)。" +
|
|
73019
|
+
"action=list 同时返回 pushMode(cloudfunction|container)、containerConfig、callbacks 与 version;" +
|
|
73020
|
+
"云托管模式下 callbacks 可能仍存在但不生效(见 note),需 ensureCloudFunctionMode 切回云函数模式后才会按回调推送。" +
|
|
73021
|
+
"action=listSupportedEvents 返回全部合法约束(按消息类型分组)。" +
|
|
73022
|
+
"需要微信 IDE 登录态通道(宿主注入 cloudBaseOptions.requestFn)。",
|
|
72953
73023
|
inputSchema: {
|
|
72954
73024
|
appid: zod_1.z
|
|
72955
73025
|
.string()
|
|
@@ -72957,7 +73027,7 @@ function registerMsgPushTools(server) {
|
|
|
72957
73027
|
env: zod_1.z.string().optional().describe("可选:环境 ID;传入时 list 仅返回该环境的订阅条目"),
|
|
72958
73028
|
action: zod_1.z
|
|
72959
73029
|
.enum(["list", "listSupportedEvents"])
|
|
72960
|
-
.describe("list:
|
|
73030
|
+
.describe("list: 查询当前消息推送配置列表(含 pushMode/containerConfig)\nlistSupportedEvents: 查询全部合法消息推送事件约束(按 msgType 分组)"),
|
|
72961
73031
|
},
|
|
72962
73032
|
annotations: {
|
|
72963
73033
|
readOnlyHint: true,
|
|
@@ -72969,7 +73039,17 @@ function registerMsgPushTools(server) {
|
|
|
72969
73039
|
return buildTransportUnavailablePayload("queryMessagePush", action);
|
|
72970
73040
|
}
|
|
72971
73041
|
if (action === "list") {
|
|
72972
|
-
const state = await
|
|
73042
|
+
const [state, containerRaw] = await Promise.all([
|
|
73043
|
+
readCallbackConfig(server, appid),
|
|
73044
|
+
// 兼容性降级:微信侧 apihttpagent 通道不支持 getcontainercallbackconfig
|
|
73045
|
+
// (ret=-9991)时,容器配置读取失败不阻断 list(pushMode 默认 cloudfunction)
|
|
73046
|
+
readContainerConfig(server, appid).catch((e) => {
|
|
73047
|
+
console.warn(`[msg-push] 读取云托管容器配置失败,降级为云函数模式推断: ${e instanceof Error ? e.message : String(e)}`);
|
|
73048
|
+
return null;
|
|
73049
|
+
}),
|
|
73050
|
+
]);
|
|
73051
|
+
const container = containerRaw;
|
|
73052
|
+
const pushMode = resolvePushMode(container);
|
|
72973
73053
|
const callbacks = env
|
|
72974
73054
|
? state.list.filter((c) => c.env === env)
|
|
72975
73055
|
: state.list;
|
|
@@ -72979,12 +73059,22 @@ function registerMsgPushTools(server) {
|
|
|
72979
73059
|
message: "查询消息推送配置成功",
|
|
72980
73060
|
version: state.version,
|
|
72981
73061
|
enable: state.enable,
|
|
73062
|
+
pushMode,
|
|
73063
|
+
containerConfig: pickContainerConfigPublic(container),
|
|
72982
73064
|
callbacks,
|
|
73065
|
+
note: pushMode === "container" ? CONTAINER_MODE_BLOCK_NOTE : undefined,
|
|
72983
73066
|
filteredByEnv: env ?? undefined,
|
|
72984
|
-
next_steps:
|
|
72985
|
-
|
|
72986
|
-
|
|
72987
|
-
|
|
73067
|
+
next_steps: pushMode === "container"
|
|
73068
|
+
? [
|
|
73069
|
+
"当前为云托管模式:云函数 subscribe/unsubscribe/setEnable 会被拒绝",
|
|
73070
|
+
"manageMessagePush(action=ensureCloudFunctionMode) 切回云函数模式",
|
|
73071
|
+
"manageMessagePush(action=setContainerCallback) 更新云托管 path/env/text_mode",
|
|
73072
|
+
]
|
|
73073
|
+
: [
|
|
73074
|
+
"manageMessagePush(action=subscribe) 订阅事件(缺省 event_types 时默认订阅虚拟支付 7 事件)",
|
|
73075
|
+
"manageMessagePush(action=ensureContainerMode) 切换到云托管整包接收",
|
|
73076
|
+
"queryMessagePush(action=listSupportedEvents) 查看全部合法事件",
|
|
73077
|
+
],
|
|
72988
73078
|
});
|
|
72989
73079
|
}
|
|
72990
73080
|
if (action === "listSupportedEvents") {
|
|
@@ -73029,29 +73119,38 @@ function registerMsgPushTools(server) {
|
|
|
73029
73119
|
server.registerTool?.("manageMessagePush", {
|
|
73030
73120
|
title: "管理小程序消息推送配置",
|
|
73031
73121
|
description: "管理小程序云开发消息推送配置(写操作,需 confirm=\"yes\" 确认)。" +
|
|
73032
|
-
"
|
|
73033
|
-
"
|
|
73034
|
-
"msg_type
|
|
73035
|
-
"
|
|
73036
|
-
"
|
|
73037
|
-
"action=
|
|
73038
|
-
"
|
|
73039
|
-
"action=setEnable 启用/停用匹配订阅(msg_type=event 时 event_types + enable 必填;消息类型时 msg_type + enable)。" +
|
|
73040
|
-
"action=ensureCloudFunctionMode 确保推送模式为云函数(若为云托管整包接收则切换 qbase_open=false,需确认)。" +
|
|
73041
|
-
"集合无变化时不发起写请求(幂等 no-op,无需确认)。" +
|
|
73042
|
-
"需要微信 IDE 登录态通道(宿主注入 cloudBaseOptions.requestFn)。",
|
|
73122
|
+
"推送模式:云函数(默认,按 (msgType,event) 回调)vs 云托管(整包接收;云托管模式下 subscribe/unsubscribe/setEnable 会被拒绝,先 ensureCloudFunctionMode)。" +
|
|
73123
|
+
"基于「读全量 → merge → 全量覆盖(带 version 乐观锁)」实现声明式幂等。" +
|
|
73124
|
+
"msg_type 缺省 \"event\";消息类型用 msg_type=text|image|voice|video|miniprogrampage。" +
|
|
73125
|
+
"action=subscribe 前会校验 function_name 在环境中真实存在。" +
|
|
73126
|
+
"action=ensureCloudFunctionMode 关闭云托管整包接收;action=ensureContainerMode 开启云托管(需 qbase_container_path/qbase_env/text_mode);" +
|
|
73127
|
+
"action=setContainerCallback 更新云托管 path/env/text_mode。" +
|
|
73128
|
+
"集合无变化时不发起写请求(幂等 no-op)。需要微信 IDE 登录态通道。",
|
|
73043
73129
|
inputSchema: {
|
|
73044
73130
|
appid: zod_1.z
|
|
73045
73131
|
.string()
|
|
73046
73132
|
.describe("小程序 AppID(必填,与微信开发者工具一致;用于选择微信登录态会话)"),
|
|
73047
|
-
env_id: zod_1.z
|
|
73048
|
-
|
|
73133
|
+
env_id: zod_1.z
|
|
73134
|
+
.string()
|
|
73135
|
+
.describe("环境 ID(云函数订阅绑定的云开发环境;ensureContainerMode/setContainerCallback 未传 qbase_env 时也可作为云托管环境默认值)"),
|
|
73136
|
+
function_name: zod_1.z
|
|
73137
|
+
.string()
|
|
73138
|
+
.describe("接收消息推送的云函数名(subscribe/unsubscribe/setEnable/ensureCloudFunctionMode 使用;云托管相关 action 可传占位)"),
|
|
73049
73139
|
action: zod_1.z
|
|
73050
|
-
.enum([
|
|
73051
|
-
|
|
73052
|
-
"unsubscribe
|
|
73053
|
-
"setEnable
|
|
73054
|
-
"ensureCloudFunctionMode
|
|
73140
|
+
.enum([
|
|
73141
|
+
"subscribe",
|
|
73142
|
+
"unsubscribe",
|
|
73143
|
+
"setEnable",
|
|
73144
|
+
"ensureCloudFunctionMode",
|
|
73145
|
+
"ensureContainerMode",
|
|
73146
|
+
"setContainerCallback",
|
|
73147
|
+
])
|
|
73148
|
+
.describe("subscribe: 订阅到指定云函数(云托管模式下拒绝)\n" +
|
|
73149
|
+
"unsubscribe: 移除匹配订阅(云托管模式下拒绝)\n" +
|
|
73150
|
+
"setEnable: 启用/停用匹配订阅(云托管模式下拒绝)\n" +
|
|
73151
|
+
"ensureCloudFunctionMode: 切到云函数推送模式(关闭 qbase_open)\n" +
|
|
73152
|
+
"ensureContainerMode: 切到云托管整包接收(需 qbase_container_path + text_mode)\n" +
|
|
73153
|
+
"setContainerCallback: 更新云托管回调 path/env/text_mode"),
|
|
73055
73154
|
msg_type: zod_1.z
|
|
73056
73155
|
.enum(exports.MSG_TYPES)
|
|
73057
73156
|
.optional()
|
|
@@ -73062,10 +73161,20 @@ function registerMsgPushTools(server) {
|
|
|
73062
73161
|
.array(zod_1.z.string())
|
|
73063
73162
|
.optional()
|
|
73064
73163
|
.describe("要操作的事件列表(仅 msg_type=\"event\" 时使用;可先 queryMessagePush(action=listSupportedEvents) 查询全量约束)。" +
|
|
73065
|
-
"subscribe 缺省时默认订阅虚拟支付 7
|
|
73066
|
-
"xpay_subscribe_signing_result_notify、xpay_subscribe_pay_fail_notify、xpay_subscribe_ios_refund_query_notify、xpay_refund_notify;" +
|
|
73067
|
-
"unsubscribe / setEnable 且 msg_type=event 时必填。消息类型操作请勿传本参数。"),
|
|
73164
|
+
"subscribe 缺省时默认订阅虚拟支付 7 个事件;unsubscribe / setEnable 且 msg_type=event 时必填。"),
|
|
73068
73165
|
enable: zod_1.z.boolean().optional().describe("setEnable 时必填:true 启用订阅 / false 停用订阅"),
|
|
73166
|
+
qbase_container_path: zod_1.z
|
|
73167
|
+
.string()
|
|
73168
|
+
.optional()
|
|
73169
|
+
.describe("云托管回调路径/URL(ensureContainerMode 必填;setContainerCallback 可选更新)"),
|
|
73170
|
+
qbase_env: zod_1.z
|
|
73171
|
+
.string()
|
|
73172
|
+
.optional()
|
|
73173
|
+
.describe("云托管服务所在环境 ID(ensureContainerMode/setContainerCallback 可选;缺省用 env_id)"),
|
|
73174
|
+
text_mode: zod_1.z
|
|
73175
|
+
.union([zod_1.z.literal(1), zod_1.z.literal(2)])
|
|
73176
|
+
.optional()
|
|
73177
|
+
.describe("云托管消息正文编码:1=json,2=xml(ensureContainerMode 必填;setContainerCallback 可选更新)"),
|
|
73069
73178
|
confirm: zod_1.z
|
|
73070
73179
|
.string()
|
|
73071
73180
|
.optional()
|
|
@@ -73078,7 +73187,7 @@ function registerMsgPushTools(server) {
|
|
|
73078
73187
|
openWorldHint: true,
|
|
73079
73188
|
category: CATEGORY,
|
|
73080
73189
|
},
|
|
73081
|
-
}, async ({ appid, env_id, function_name, action, msg_type, event_types, enable, confirm, }) => {
|
|
73190
|
+
}, async ({ appid, env_id, function_name, action, msg_type, event_types, enable, qbase_container_path, qbase_env, text_mode, confirm, }) => {
|
|
73082
73191
|
if (!getTransport(server)) {
|
|
73083
73192
|
return buildTransportUnavailablePayload("manageMessagePush", action);
|
|
73084
73193
|
}
|
|
@@ -73093,16 +73202,16 @@ function registerMsgPushTools(server) {
|
|
|
73093
73202
|
success: true,
|
|
73094
73203
|
code: "NO_CHANGE",
|
|
73095
73204
|
message: "当前已是云函数推送模式(云托管整包接收未开启),无需变更",
|
|
73096
|
-
|
|
73205
|
+
pushMode: "cloudfunction",
|
|
73206
|
+
containerConfig: pickContainerConfigPublic(current),
|
|
73097
73207
|
});
|
|
73098
73208
|
}
|
|
73099
73209
|
if (!confirmed) {
|
|
73100
73210
|
return buildConfirmPayload({
|
|
73101
73211
|
toolName: "manageMessagePush",
|
|
73102
73212
|
action,
|
|
73103
|
-
message:
|
|
73104
|
-
|
|
73105
|
-
`使消息推送按事件进入云函数 ${env_id}/${function_name}。`,
|
|
73213
|
+
message: `切换后停止云托管整包接收(qbase_open=false),消息按云函数回调推送;若 callbacks 为空则收不到任何消息。\n` +
|
|
73214
|
+
`当前云托管配置:环境 ${current.qbase_env ?? "-"},路径 ${current.qbase_container_path ?? "-"},text_mode=${current.text_mode ?? "-"}。`,
|
|
73106
73215
|
requiredParams: ["appid", "env_id", "function_name", "confirm"],
|
|
73107
73216
|
});
|
|
73108
73217
|
}
|
|
@@ -73122,6 +73231,140 @@ function registerMsgPushTools(server) {
|
|
|
73122
73231
|
success: true,
|
|
73123
73232
|
message: "已切换到云函数推送模式(setcontainercallbackconfig qbase_open=false 成功)",
|
|
73124
73233
|
action,
|
|
73234
|
+
pushMode: "cloudfunction",
|
|
73235
|
+
});
|
|
73236
|
+
}
|
|
73237
|
+
if (action === "ensureContainerMode") {
|
|
73238
|
+
const path = qbase_container_path?.trim();
|
|
73239
|
+
const containerEnv = (qbase_env ?? env_id)?.trim();
|
|
73240
|
+
if (!path) {
|
|
73241
|
+
throw new Error('ensureContainerMode 必须提供 qbase_container_path(云托管回调路径/URL)');
|
|
73242
|
+
}
|
|
73243
|
+
if (text_mode !== 1 && text_mode !== 2) {
|
|
73244
|
+
throw new Error("ensureContainerMode 必须提供 text_mode(1=json / 2=xml)");
|
|
73245
|
+
}
|
|
73246
|
+
if (!containerEnv) {
|
|
73247
|
+
throw new Error("ensureContainerMode 必须提供 qbase_env 或 env_id(云托管服务所在环境)");
|
|
73248
|
+
}
|
|
73249
|
+
const current = await readContainerConfig(server, appid);
|
|
73250
|
+
const alreadySame = current?.qbase_open === true &&
|
|
73251
|
+
current.qbase_container_path === path &&
|
|
73252
|
+
current.qbase_env === containerEnv &&
|
|
73253
|
+
Number(current.text_mode) === text_mode;
|
|
73254
|
+
if (alreadySame) {
|
|
73255
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
73256
|
+
ok: true,
|
|
73257
|
+
success: true,
|
|
73258
|
+
code: "NO_CHANGE",
|
|
73259
|
+
message: "当前已是云托管推送模式且配置一致,无需变更",
|
|
73260
|
+
pushMode: "container",
|
|
73261
|
+
containerConfig: pickContainerConfigPublic(current),
|
|
73262
|
+
});
|
|
73263
|
+
}
|
|
73264
|
+
if (!confirmed) {
|
|
73265
|
+
return buildConfirmPayload({
|
|
73266
|
+
toolName: "manageMessagePush",
|
|
73267
|
+
action,
|
|
73268
|
+
message: `切换后所有消息类型整包推送到云托管服务(path=${path},env=${containerEnv},text_mode=${text_mode}),云函数回调失效。\n` +
|
|
73269
|
+
`当前:pushMode=${resolvePushMode(current)},` +
|
|
73270
|
+
`path=${current?.qbase_container_path ?? "-"},env=${current?.qbase_env ?? "-"},text_mode=${current?.text_mode ?? "-"}。`,
|
|
73271
|
+
requiredParams: [
|
|
73272
|
+
"appid",
|
|
73273
|
+
"env_id",
|
|
73274
|
+
"qbase_container_path",
|
|
73275
|
+
"text_mode",
|
|
73276
|
+
"confirm",
|
|
73277
|
+
],
|
|
73278
|
+
});
|
|
73279
|
+
}
|
|
73280
|
+
const nextCfg = {
|
|
73281
|
+
...(current ?? {}),
|
|
73282
|
+
qbase_open: true,
|
|
73283
|
+
qbase_container_path: path,
|
|
73284
|
+
qbase_env: containerEnv,
|
|
73285
|
+
text_mode,
|
|
73286
|
+
};
|
|
73287
|
+
await setContainerConfig(server, appid, nextCfg);
|
|
73288
|
+
logger?.({
|
|
73289
|
+
type: "toolInfo",
|
|
73290
|
+
toolName: "manageMessagePush",
|
|
73291
|
+
message: "已切换到云托管推送模式",
|
|
73292
|
+
appid,
|
|
73293
|
+
envId: containerEnv,
|
|
73294
|
+
});
|
|
73295
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
73296
|
+
ok: true,
|
|
73297
|
+
success: true,
|
|
73298
|
+
message: "已切换到云托管推送模式(qbase_open=true)",
|
|
73299
|
+
action,
|
|
73300
|
+
pushMode: "container",
|
|
73301
|
+
containerConfig: pickContainerConfigPublic(nextCfg),
|
|
73302
|
+
});
|
|
73303
|
+
}
|
|
73304
|
+
if (action === "setContainerCallback") {
|
|
73305
|
+
const current = await readContainerConfig(server, appid);
|
|
73306
|
+
const nextPath = qbase_container_path?.trim() ||
|
|
73307
|
+
(typeof current?.qbase_container_path === "string"
|
|
73308
|
+
? current.qbase_container_path
|
|
73309
|
+
: undefined);
|
|
73310
|
+
const nextEnv = (qbase_env ?? env_id)?.trim() ||
|
|
73311
|
+
(typeof current?.qbase_env === "string" ? current.qbase_env : undefined);
|
|
73312
|
+
const nextTextMode = text_mode === 1 || text_mode === 2
|
|
73313
|
+
? text_mode
|
|
73314
|
+
: typeof current?.text_mode === "number"
|
|
73315
|
+
? current.text_mode
|
|
73316
|
+
: undefined;
|
|
73317
|
+
if (!nextPath) {
|
|
73318
|
+
throw new Error("setContainerCallback 需要 qbase_container_path(或当前已有配置可沿用)");
|
|
73319
|
+
}
|
|
73320
|
+
if (!nextEnv) {
|
|
73321
|
+
throw new Error("setContainerCallback 需要 qbase_env 或 env_id(或当前已有配置可沿用)");
|
|
73322
|
+
}
|
|
73323
|
+
if (nextTextMode !== 1 && nextTextMode !== 2) {
|
|
73324
|
+
throw new Error("setContainerCallback 需要 text_mode(1=json / 2=xml,或当前已有配置可沿用)");
|
|
73325
|
+
}
|
|
73326
|
+
const nextCfg = {
|
|
73327
|
+
...(current ?? {}),
|
|
73328
|
+
qbase_open: current?.qbase_open === true,
|
|
73329
|
+
qbase_container_path: nextPath,
|
|
73330
|
+
qbase_env: nextEnv,
|
|
73331
|
+
text_mode: nextTextMode,
|
|
73332
|
+
};
|
|
73333
|
+
const same = current?.qbase_container_path === nextPath &&
|
|
73334
|
+
current?.qbase_env === nextEnv &&
|
|
73335
|
+
Number(current?.text_mode) === nextTextMode &&
|
|
73336
|
+
(current?.qbase_open === true) === (nextCfg.qbase_open === true);
|
|
73337
|
+
if (same) {
|
|
73338
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
73339
|
+
ok: true,
|
|
73340
|
+
success: true,
|
|
73341
|
+
code: "NO_CHANGE",
|
|
73342
|
+
message: "云托管回调配置无变化(幂等)",
|
|
73343
|
+
pushMode: resolvePushMode(current),
|
|
73344
|
+
containerConfig: pickContainerConfigPublic(current),
|
|
73345
|
+
});
|
|
73346
|
+
}
|
|
73347
|
+
if (!confirmed) {
|
|
73348
|
+
const before = pickContainerConfigPublic(current) ?? {};
|
|
73349
|
+
const after = pickContainerConfigPublic(nextCfg) ?? {};
|
|
73350
|
+
return buildConfirmPayload({
|
|
73351
|
+
toolName: "manageMessagePush",
|
|
73352
|
+
action,
|
|
73353
|
+
message: `即将更新云托管回调配置:\n` +
|
|
73354
|
+
`- 旧: path=${before.qbase_container_path ?? "-"}, env=${before.qbase_env ?? "-"}, text_mode=${before.text_mode ?? "-"}, qbase_open=${before.qbase_open ?? false}\n` +
|
|
73355
|
+
`- 新: path=${after.qbase_container_path ?? "-"}, env=${after.qbase_env ?? "-"}, text_mode=${after.text_mode ?? "-"}, qbase_open=${after.qbase_open ?? false}`,
|
|
73356
|
+
requiredParams: ["appid", "confirm"],
|
|
73357
|
+
});
|
|
73358
|
+
}
|
|
73359
|
+
await setContainerConfig(server, appid, nextCfg);
|
|
73360
|
+
return (0, tool_result_js_1.buildJsonToolResult)({
|
|
73361
|
+
ok: true,
|
|
73362
|
+
success: true,
|
|
73363
|
+
message: "已更新云托管回调配置",
|
|
73364
|
+
action,
|
|
73365
|
+
pushMode: resolvePushMode(nextCfg),
|
|
73366
|
+
before: pickContainerConfigPublic(current),
|
|
73367
|
+
after: pickContainerConfigPublic(nextCfg),
|
|
73125
73368
|
});
|
|
73126
73369
|
}
|
|
73127
73370
|
// Message-type entries use a fixed empty event; event_types must not be supplied
|
|
@@ -73129,6 +73372,13 @@ function registerMsgPushTools(server) {
|
|
|
73129
73372
|
throw new Error(`msg_type="${resolvedMsgType}" 时不应传 event_types(消息类型条目的 event 固定为空串 "");` +
|
|
73130
73373
|
`请去掉 event_types,仅传 msg_type / function_name / enable(setEnable 时)`);
|
|
73131
73374
|
}
|
|
73375
|
+
// Reject cloud-function callback writes while container mode is active (silent-failure guard)
|
|
73376
|
+
{
|
|
73377
|
+
const container = await readContainerConfig(server, appid);
|
|
73378
|
+
if (resolvePushMode(container) === "container") {
|
|
73379
|
+
return buildContainerModeBlockedPayload(action);
|
|
73380
|
+
}
|
|
73381
|
+
}
|
|
73132
73382
|
// subscribe / unsubscribe / setEnable 共用流程:读 → 校验 → merge → 确认 → 覆盖写
|
|
73133
73383
|
let eventList;
|
|
73134
73384
|
if (!isEventMsgType) {
|
|
@@ -73224,6 +73474,12 @@ function registerMsgPushTools(server) {
|
|
|
73224
73474
|
warnings: warnings.length ? warnings : undefined,
|
|
73225
73475
|
});
|
|
73226
73476
|
}
|
|
73477
|
+
// 4b. subscribe:校验云函数真实存在(仅有变更时)
|
|
73478
|
+
if (action === "subscribe") {
|
|
73479
|
+
const missing = await assertCloudFunctionExists(server, env_id, function_name);
|
|
73480
|
+
if (missing)
|
|
73481
|
+
return missing;
|
|
73482
|
+
}
|
|
73227
73483
|
// 5. 有变更 → 需确认
|
|
73228
73484
|
const diffText = buildMergeDiffText(action, result, env_id, function_name);
|
|
73229
73485
|
if (!confirmed) {
|
|
@@ -149159,7 +149415,7 @@ class TelemetryReporter {
|
|
|
149159
149415
|
const arch = os_1.default.arch(); // 系统架构
|
|
149160
149416
|
// Build-time injected version; guard for vitest / non-webpack runtimes.
|
|
149161
149417
|
const mcpVersion = process.env.npm_package_version ||
|
|
149162
|
-
( true ? "2.32.
|
|
149418
|
+
( true ? "2.32.2" : 0);
|
|
149163
149419
|
return {
|
|
149164
149420
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
149165
149421
|
deviceId: this.deviceId,
|
|
@@ -222437,7 +222693,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
222437
222693
|
exports.CloudBaseContext = void 0;
|
|
222438
222694
|
const constant_1 = __webpack_require__(40762);
|
|
222439
222695
|
class CloudBaseContext {
|
|
222440
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined, internalEndpointRegion = undefined }) {
|
|
222696
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined, internalEndpointRegion = undefined, requestFn = undefined }) {
|
|
222441
222697
|
this.secretId = secretId;
|
|
222442
222698
|
this.secretKey = secretKey;
|
|
222443
222699
|
this.token = token;
|
|
@@ -222446,6 +222702,7 @@ class CloudBaseContext {
|
|
|
222446
222702
|
this.envType = envType;
|
|
222447
222703
|
this.useInternalEndpoint = useInternalEndpoint;
|
|
222448
222704
|
this.internalEndpointRegion = internalEndpointRegion;
|
|
222705
|
+
this.requestFn = requestFn;
|
|
222449
222706
|
}
|
|
222450
222707
|
isInternalEndpoint() {
|
|
222451
222708
|
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
@@ -232930,7 +233187,7 @@ ${envIdSection}
|
|
|
232930
233187
|
## 环境信息
|
|
232931
233188
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
232932
233189
|
- Node.js版本: ${process.version}
|
|
232933
|
-
- MCP 版本:${process.env.npm_package_version || ( true ? "2.32.
|
|
233190
|
+
- MCP 版本:${process.env.npm_package_version || ( true ? "2.32.2" : 0)}
|
|
232934
233191
|
- 系统架构: ${os_1.default.arch()}
|
|
232935
233192
|
- 时间: ${new Date().toISOString()}
|
|
232936
233193
|
- 请求ID: ${requestId}
|
|
@@ -233011,7 +233268,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
233011
233268
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
233012
233269
|
ide: server.ide || process.env.INTEGRATION_IDE || ''
|
|
233013
233270
|
});
|
|
233014
|
-
const mcpVersion = true ? "2.32.
|
|
233271
|
+
const mcpVersion = true ? "2.32.2" : 0;
|
|
233015
233272
|
const requestIdSuffix = requestId ? `\n🆔 RequestId: ${requestId}` : '';
|
|
233016
233273
|
const enhancedErrorMessage = `${errorMessage}${requestIdSuffix}\n\n📦 CloudBase MCP v${mcpVersion}\n🔗 遇到问题?请复制以下链接到浏览器打开\n即可自动携带错误详情快速创建 GitHub Issue:\n${issueLink}`;
|
|
233017
233274
|
// 创建新的错误对象,保持原有的错误类型但更新消息
|
|
@@ -252400,7 +252657,7 @@ function registerSetupTools(server) {
|
|
|
252400
252657
|
server.registerTool("downloadTemplate", {
|
|
252401
252658
|
title: "下载项目模板",
|
|
252402
252659
|
description: `自动下载并部署CloudBase项目模板。
|
|
252403
|
-
**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.32.
|
|
252660
|
+
**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.32.2" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
252404
252661
|
inputSchema: {
|
|
252405
252662
|
template: zod_1.z
|
|
252406
252663
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -270263,12 +270520,13 @@ function getDate(timestamp) {
|
|
|
270263
270520
|
}
|
|
270264
270521
|
class CloudService {
|
|
270265
270522
|
/* eslint-disable-next-line */
|
|
270266
|
-
constructor(context, service, version, baseParams) {
|
|
270523
|
+
constructor(context, service, version, baseParams, requestFn) {
|
|
270267
270524
|
this.service = service;
|
|
270268
270525
|
this.version = version;
|
|
270269
270526
|
this.timeout = 60000;
|
|
270270
270527
|
this.baseParams = baseParams || {};
|
|
270271
270528
|
this.cloudBaseContext = context;
|
|
270529
|
+
this.requestFn = requestFn !== null && requestFn !== void 0 ? requestFn : context === null || context === void 0 ? void 0 : context.requestFn;
|
|
270272
270530
|
}
|
|
270273
270531
|
get baseUrl() {
|
|
270274
270532
|
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
@@ -270300,9 +270558,32 @@ class CloudService {
|
|
|
270300
270558
|
}
|
|
270301
270559
|
}
|
|
270302
270560
|
async request(action, data = {}, method = 'POST') {
|
|
270561
|
+
var _a;
|
|
270303
270562
|
this.action = action;
|
|
270304
|
-
this.data = deepRemoveVoid(Object.assign(Object.assign({}, data), this.baseParams));
|
|
270305
270563
|
this.method = method;
|
|
270564
|
+
this.data = deepRemoveVoid(Object.assign(Object.assign({}, data), this.baseParams));
|
|
270565
|
+
// 如果注入了 requestFn,直接委托,跳过 TC3 签名逻辑
|
|
270566
|
+
if (this.requestFn) {
|
|
270567
|
+
try {
|
|
270568
|
+
const result = await this.requestFn({
|
|
270569
|
+
service: this.service,
|
|
270570
|
+
action,
|
|
270571
|
+
version: this.version,
|
|
270572
|
+
region: (_a = this.cloudBaseContext.region) !== null && _a !== void 0 ? _a : '',
|
|
270573
|
+
payload: this.data,
|
|
270574
|
+
});
|
|
270575
|
+
return result;
|
|
270576
|
+
}
|
|
270577
|
+
catch (e) {
|
|
270578
|
+
if (e.name === 'CloudBaseError') {
|
|
270579
|
+
throw e;
|
|
270580
|
+
}
|
|
270581
|
+
throw new error_1.CloudBaseError(e.message, {
|
|
270582
|
+
action,
|
|
270583
|
+
code: e.code
|
|
270584
|
+
});
|
|
270585
|
+
}
|
|
270586
|
+
}
|
|
270306
270587
|
this.url = this.baseUrl;
|
|
270307
270588
|
let { secretId, secretKey, token } = this.cloudBaseContext;
|
|
270308
270589
|
// 当在云函数环境下执行时,可init时不传入密钥,取环境变量中密钥使用
|
|
@@ -315517,9 +315798,9 @@ class CloudBase {
|
|
|
315517
315798
|
}
|
|
315518
315799
|
constructor(config = {}) {
|
|
315519
315800
|
this.cloudBaseConfig = {};
|
|
315520
|
-
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint, internalEndpointRegion } = config;
|
|
315521
|
-
// config 中传入的 secretId secretkey
|
|
315522
|
-
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
315801
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint, internalEndpointRegion, requestFn } = config;
|
|
315802
|
+
// config 中传入的 secretId secretkey 必须同时存在(有 requestFn 时可以不传)
|
|
315803
|
+
if (!requestFn && ((secretId && !secretKey) || (!secretId && secretKey))) {
|
|
315523
315804
|
throw new Error('secretId and secretKey must be a pair');
|
|
315524
315805
|
}
|
|
315525
315806
|
this.cloudBaseConfig = {
|
|
@@ -315532,6 +315813,7 @@ class CloudBase {
|
|
|
315532
315813
|
region,
|
|
315533
315814
|
useInternalEndpoint,
|
|
315534
315815
|
internalEndpointRegion,
|
|
315816
|
+
requestFn,
|
|
315535
315817
|
};
|
|
315536
315818
|
// 初始化 context
|
|
315537
315819
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -391,6 +391,12 @@ export declare type MsgPushAction = "getAppConfig" | "uploadAppConfig" | "getCal
|
|
|
391
391
|
export declare interface MsgPushOverrides {
|
|
392
392
|
/** 消息推送 qbase CGI 对应的 Cloud API service 名(默认 "qbase");宿主可按后端契约覆盖 */
|
|
393
393
|
service?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Optional readonly hook to list cloud function names in an env.
|
|
396
|
+
* Used by manageMessagePush(action=subscribe) to reject unknown function_name.
|
|
397
|
+
* Hosts may inject this; when omitted the tool falls back to CloudBase Manager getFunctionList.
|
|
398
|
+
*/
|
|
399
|
+
listCloudFunctions?: (envId: string) => Promise<string[]>;
|
|
394
400
|
}
|
|
395
401
|
|
|
396
402
|
/** 消息推送 qbase 响应(业务码 ret === 0 为成功;由宿主 requestFn 解包后返回) */
|