@@ -337,45 +337,40 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
337
337
}
338
338
) ;
339
339
340
- // getFunctionLogs - 获取云函数日志
340
+ // getFunctionLogs - 获取云函数日志(新版,参数直接展开)
341
341
server . registerTool ?.(
342
342
"getFunctionLogs" ,
343
343
{
344
344
title : "获取云函数日志(新版)" ,
345
345
description : "获取云函数日志基础信息(LogList),如需日志详情请用 RequestId 调用 getFunctionLogDetail 工具。此接口基于 manger-node 4.4.0+ 的 getFunctionLogsV2 实现,不返回具体日志内容。参数 offset+limit 不得大于 10000,startTime/endTime 间隔不得超过一天。" ,
346
346
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" )
356
354
} ,
357
355
annotations : {
358
356
readOnlyHint : true ,
359
357
openWorldHint : true ,
360
358
category : "functions"
361
359
}
362
360
} ,
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 ) {
366
363
throw new Error ( "offset+limit 不能大于 10000" ) ;
367
364
}
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 ( ) ;
372
368
if ( end - start > 24 * 60 * 60 * 1000 ) {
373
369
throw new Error ( "startTime 和 endTime 间隔不能超过一天" ) ;
374
370
}
375
371
}
376
- // 使用闭包中的 cloudBaseOptions
377
372
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 } ) ;
379
374
return {
380
375
content : [
381
376
{
@@ -387,39 +382,36 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
387
382
}
388
383
) ;
389
384
390
- // getFunctionLogDetail - 查询日志详情
385
+ // getFunctionLogDetail - 查询日志详情(参数直接展开)
391
386
server . registerTool ?.(
392
387
"getFunctionLogDetail" ,
393
388
{
394
389
title : "获取云函数日志详情" ,
395
390
description : "根据 getFunctionLogs 返回的 RequestId 查询日志详情。参数 startTime、endTime、requestId,返回日志内容(LogJson 等)。仅支持 manger-node 4.4.0+。" ,
396
391
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" )
402
395
} ,
403
396
annotations : {
404
397
readOnlyHint : true ,
405
398
openWorldHint : true ,
406
399
category : "functions"
407
400
}
408
401
} ,
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 ( ) ;
414
406
if ( end - start > 24 * 60 * 60 * 1000 ) {
415
407
throw new Error ( "startTime 和 endTime 间隔不能超过一天" ) ;
416
408
}
417
409
}
418
410
const cloudbase = await getManager ( ) ;
419
411
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
423
415
} ) ;
424
416
return {
425
417
content : [
0 commit comments