Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcp/src/tools/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
tool: "manageGateway",
action: "createAccess",
reason:
"如果需要通过 URL 访问 HTTP 函数,请按实际路径和鉴权需求显式创建访问入口,不要默认假设 /函数名 已存在",
`HTTP 函数需要显式创建网关访问入口,调用时必须传 type="HTTP"、targetType="function"、targetName="${functionName}",不可省略 type`,
});
nextActions.push({
tool: "queryGateway",
Expand Down
11 changes: 9 additions & 2 deletions mcp/src/tools/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,28 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
if (!input.targetName || !input.targetType) {
throw new Error("action=createAccess 时必须提供 targetType 和 targetName");
}
if (!input.type) {
throw new Error(
"action=createAccess 时必须提供 type 参数(Event 或 HTTP),不可省略。" +
"如果目标云函数是 HTTP 类型,type 必须传 HTTP;如果是 Event 类型,type 传 Event。" +
"省略 type 会导致网关默认使用 Event 模式,对 HTTP 函数将产生 FUNCTION_PARAM_INVALID 错误。",
);
}
const cloudbase = await getManager();
const accessPath = normalizeAccessPath(input.path || `/${input.targetName}`);
let result;
try {
result = await cloudbase.access.createAccess({
name: input.targetName,
path: accessPath,
type: ((input.type || "Event") === "HTTP" ? 6 : 1) as 1 | 2,
type: (input.type === "HTTP" ? 6 : 1) as 1 | 2,
auth: input.auth,
});
} catch (err: any) {
if (err.message && err.message.includes("An error has occurred")) {
let hint = "为目标资源配置访问路由失败(后端内部错误)。请确保:1) 目标云函数已成功创建并处于 Active 状态;2) 环境默认 HTTP 域名已完成初始化;3) 该访问路径未被占用。";
if (input.type === "HTTP") {
hint += "此外注意:如果目标函数最初是作为 Event 函数创建的,这里 type 必须依然传 Event(或省略),传 HTTP 会导致此错误。";
hint += "此外注意:如果目标函数最初是作为 Event 函数创建的,这里 type 必须传 Event,传 HTTP 会导致此错误。";
}
throw new Error(`${hint} 原始错误:${err.message}`);
}
Expand Down
Loading