Skip to content

Commit 98871d2

Browse files
committed
docs(function-logs): 📝 update getFunctionLogs/getFunctionLogDetail to use flat params in docs
1 parent 426fbf9 commit 98871d2

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

mcp/src/tools/functions.ts

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -337,45 +337,40 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
337337
}
338338
);
339339

340-
// getFunctionLogs - 获取云函数日志
340+
// getFunctionLogs - 获取云函数日志(新版,参数直接展开)
341341
server.registerTool?.(
342342
"getFunctionLogs",
343343
{
344344
title: "获取云函数日志(新版)",
345345
description: "获取云函数日志基础信息(LogList),如需日志详情请用 RequestId 调用 getFunctionLogDetail 工具。此接口基于 manger-node 4.4.0+ 的 getFunctionLogsV2 实现,不返回具体日志内容。参数 offset+limit 不得大于 10000,startTime/endTime 间隔不得超过一天。",
346346
inputSchema: {
347-
options: z.object({
348-
name: z.string().describe("函数名称"),
349-
offset: z.number().optional().describe("数据的偏移量,Offset+Limit 不能大于 10000"),
350-
limit: z.number().optional().describe("返回数据的长度,Offset+Limit 不能大于 10000"),
351-
startTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:00:00,只能与 EndTime 相差一天之内"),
352-
endTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:59:59,只能与 StartTime 相差一天之内"),
353-
requestId: z.string().optional().describe("执行该函数对应的 requestId"),
354-
qualifier: z.string().optional().describe("函数版本,默认为 $LATEST")
355-
}).describe("日志查询选项")
347+
name: z.string().describe("函数名称"),
348+
offset: z.number().optional().describe("数据的偏移量,Offset+Limit 不能大于 10000"),
349+
limit: z.number().optional().describe("返回数据的长度,Offset+Limit 不能大于 10000"),
350+
startTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:00:00,只能与 EndTime 相差一天之内"),
351+
endTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:59:59,只能与 StartTime 相差一天之内"),
352+
requestId: z.string().optional().describe("执行该函数对应的 requestId"),
353+
qualifier: z.string().optional().describe("函数版本,默认为 $LATEST")
356354
},
357355
annotations: {
358356
readOnlyHint: true,
359357
openWorldHint: true,
360358
category: "functions"
361359
}
362360
},
363-
async ({ options }: { options: any }) => {
364-
// 参数校验
365-
if ((options.offset || 0) + (options.limit || 0) > 10000) {
361+
async ({ name, offset, limit, startTime, endTime, requestId, qualifier }) => {
362+
if ((offset || 0) + (limit || 0) > 10000) {
366363
throw new Error("offset+limit 不能大于 10000");
367364
}
368-
// 时间间隔校验(简单字符串长度判断,具体可根据实际需求增强)
369-
if (options.startTime && options.endTime) {
370-
const start = new Date(options.startTime).getTime();
371-
const end = new Date(options.endTime).getTime();
365+
if (startTime && endTime) {
366+
const start = new Date(startTime).getTime();
367+
const end = new Date(endTime).getTime();
372368
if (end - start > 24 * 60 * 60 * 1000) {
373369
throw new Error("startTime 和 endTime 间隔不能超过一天");
374370
}
375371
}
376-
// 使用闭包中的 cloudBaseOptions
377372
const cloudbase = await getManager();
378-
const result = await cloudbase.functions.getFunctionLogsV2(options);
373+
const result = await cloudbase.functions.getFunctionLogsV2({ name, offset, limit, startTime, endTime, requestId, qualifier });
379374
return {
380375
content: [
381376
{
@@ -387,39 +382,36 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
387382
}
388383
);
389384

390-
// getFunctionLogDetail - 查询日志详情
385+
// getFunctionLogDetail - 查询日志详情(参数直接展开)
391386
server.registerTool?.(
392387
"getFunctionLogDetail",
393388
{
394389
title: "获取云函数日志详情",
395390
description: "根据 getFunctionLogs 返回的 RequestId 查询日志详情。参数 startTime、endTime、requestId,返回日志内容(LogJson 等)。仅支持 manger-node 4.4.0+。",
396391
inputSchema: {
397-
options: z.object({
398-
startTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:00:00,只能与 EndTime 相差一天之内"),
399-
endTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:59:59,只能与 StartTime 相差一天之内"),
400-
requestId: z.string().describe("执行该函数对应的 requestId")
401-
}).describe("日志详情查询选项")
392+
startTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:00:00,只能与 EndTime 相差一天之内"),
393+
endTime: z.string().optional().describe("查询的具体日期,例如:2017-05-16 20:59:59,只能与 StartTime 相差一天之内"),
394+
requestId: z.string().describe("执行该函数对应的 requestId")
402395
},
403396
annotations: {
404397
readOnlyHint: true,
405398
openWorldHint: true,
406399
category: "functions"
407400
}
408401
},
409-
async ({ options }: { options: any }) => {
410-
// 参数校验
411-
if (options.startTime && options.endTime) {
412-
const start = new Date(options.startTime).getTime();
413-
const end = new Date(options.endTime).getTime();
402+
async ({ startTime, endTime, requestId }) => {
403+
if (startTime && endTime) {
404+
const start = new Date(startTime).getTime();
405+
const end = new Date(endTime).getTime();
414406
if (end - start > 24 * 60 * 60 * 1000) {
415407
throw new Error("startTime 和 endTime 间隔不能超过一天");
416408
}
417409
}
418410
const cloudbase = await getManager();
419411
const result = await cloudbase.functions.getFunctionLogDetail({
420-
startTime: options.startTime,
421-
endTime: options.endTime,
422-
logRequestId: options.requestId
412+
startTime,
413+
endTime,
414+
logRequestId: requestId
423415
});
424416
return {
425417
content: [

0 commit comments

Comments
 (0)