Skip to content

Commit 567743d

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): MCP 云函数创建工具参数设计不清晰,错误提示过于笼统 (issue_mo8z7grh_mdahjm)
1 parent e2ca73f commit 567743d

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

doc/prompts/auth-web.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ If the current task has not retrieved a real Publishable Key, omit `accessKey` i
143143

144144
**1. Phone OTP (Recommended)**
145145
- Automatically use `auth-tool-cloudbase` to turn on `SMS Login` through `manageAppAuth`
146-
- Send the phone number to `auth.signInWithOtp({ phone, ... })`, then call the returned `verifyOtp({ token })`.
147-
- `signInWithOtp` can automatically create a new user if the user does not exist; control this via `shouldCreateUser` parameter (default `true`).
146+
- For phone registration, send the phone number to `auth.signUp({ phone, ... })` first, then call the returned `verifyOtp({ token })`. Do not swap the order.
148147
```js
149-
const { data, error } = await auth.signInWithOtp({ phone: '13800138000' })
148+
const { data, error } = await auth.signUp({ phone: '13800138000' })
150149
const { data: loginData, error: loginError } = await data.verifyOtp({ token:'123456' })
151150
```
152151

mcp/src/tools/functions.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ export function validateTimerCron(config: string): string {
213213
}
214214

215215
const TRIGGER_SCHEMA = z.object({
216-
name: z.string().describe("触发器名称"),
217-
type: z.enum(SUPPORTED_TRIGGER_TYPES).describe("触发器类型"),
216+
name: z.string().describe("触发器名称(必填)。如 'timerHelloTrigger'"),
217+
type: z.enum(SUPPORTED_TRIGGER_TYPES).describe("触发器类型(必填)。目前仅支持 'timer'"),
218218
config: z
219219
.string()
220220
.describe(
221-
"触发器配置。timer 必须使用 CloudBase 7 段 cron 格式:秒 分 时 日 月 星期 年。" +
221+
"触发器配置(必填)。timer 触发器必须使用 CloudBase 7 段 cron 格式:秒 分 时 日 月 星期 年。" +
222222
"⚠️ 不支持标准 5 段 cron(如 */5 * * * * 是错误的)。" +
223223
"正确示例:0 */5 * * * * *(每5分钟)、0 0 2 1 * * *(每月1号2点)、0 30 9 * * * *(每天9:30)",
224224
)
@@ -232,8 +232,8 @@ const TRIGGER_SCHEMA = z.object({
232232
});
233233

234234
const CREATE_FUNCTION_SCHEMA = z.object({
235-
name: z.string().describe("函数名称"),
236-
type: z.enum(["Event", "HTTP"]).optional().describe("函数类型"),
235+
name: z.string().describe("函数名称(必填)"),
236+
type: z.enum(["Event", "HTTP"]).optional().describe("函数类型:Event(事件函数,默认)或 HTTP(HTTP函数)"),
237237
protocolType: z.enum(["HTTP", "WS"]).optional().describe("HTTP 云函数协议类型"),
238238
protocolParams: z
239239
.object({
@@ -363,6 +363,18 @@ export function buildFunctionOperationErrorMessage(
363363
const suggestions: string[] = [];
364364
const expectedFunctionPath = getExpectedFunctionPath(functionRootPath, functionName);
365365

366+
// Handle generic "invalid parameter value" errors with more specific guidance
367+
if (/invalid parameter value||InvalidParameterValue/i.test(baseMessage)) {
368+
suggestions.push(
369+
`参数值无效。请检查以下常见原因:\n` +
370+
`1. func.name 是否提供且为有效字符串(当前函数名: "${functionName}")\n` +
371+
`2. func.type 是否为 "Event" 或 "HTTP"\n` +
372+
`3. func.runtime 是否为支持的运行时(如 "Nodejs18.15")\n` +
373+
`4. triggers 数组中的 trigger 对象是否包含 name、type、config 字段\n` +
374+
`5. timer 触发器的 cron 表达式是否为 7 段格式(秒 分 时 日 月 星期 年)`
375+
);
376+
}
377+
366378
if (/GetFunction.*Function|Function/i.test(baseMessage)) {
367379
suggestions.push(
368380
`请先确认环境中已存在函数 \`${functionName}\`;如果还未创建,请先执行 \`manageFunctions(action="createFunction")\`。`,
@@ -1444,12 +1456,13 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
14441456
{
14451457
title: "管理云函数域资源",
14461458
description:
1447-
"函数域统一写入口。通过 action 管理函数创建、代码更新、配置更新、调用函数、触发器和层绑定。危险操作需要显式 confirm=true。",
1459+
"函数域统一写入口。通过 action 管理函数创建、代码更新、配置更新、调用函数、触发器和层绑定。危险操作需要显式 confirm=true。" +
1460+
"【重要】action=createFunction 时,func 对象(含 name 字段)是必填的。示例: { action: 'createFunction', func: { name: 'myFunc', type: 'Event', runtime: 'Nodejs18.15' } }.",
14481461
inputSchema: {
14491462
action: z
14501463
.enum(MANAGE_FUNCTION_ACTIONS)
14511464
.describe("写操作类型,例如 createFunction、invokeFunction、attachLayer"),
1452-
func: CREATE_FUNCTION_SCHEMA.optional().describe("createFunction 操作的函数配置"),
1465+
func: CREATE_FUNCTION_SCHEMA.optional().describe("createFunction 操作的函数配置(action=createFunction 时必填)。必须包含 name 字段,可选 type、runtime、triggers 等"),
14531466
functionRootPath: z.string().optional().describe(
14541467
"创建或更新函数代码时默认推荐的本地目录方式。" +
14551468
"必须是直接包含函数文件夹的目录绝对路径(如 /abs/path/cloudfunctions 或 /abs/path/functions)," +
@@ -1468,7 +1481,7 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
14681481
envVariables: z.record(z.string()).optional().describe("配置更新时要合并的环境变量"),
14691482
vpc: VPC_SCHEMA.optional().describe("配置更新时的 VPC 信息"),
14701483
params: z.record(z.any()).optional().describe("invokeFunction 的调用参数"),
1471-
triggers: z.array(TRIGGER_SCHEMA).optional().describe("createFunctionTrigger 的触发器列表"),
1484+
triggers: z.array(TRIGGER_SCHEMA).optional().describe("createFunction 或 createFunctionTrigger 的触发器列表。每个触发器需包含 name、type(如 'timer')、config(如 '0 */5 * * * * *')"),
14721485
triggerName: z.string().optional().describe("deleteFunctionTrigger 的目标触发器名称"),
14731486
layerName: z.string().optional().describe("层名称"),
14741487
layerVersion: z.number().optional().describe("层版本号"),

0 commit comments

Comments
 (0)