Skip to content

Commit aebeed6

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): queryFunctions MCP 工具分页设计不完善,响应缺少分页元数据且跨页数据一致性无保障 (issue_mojj9me4_yo5uhf)
1 parent e2ca73f commit aebeed6

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

mcp/src/tools/functions.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -531,20 +531,28 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
531531
switch (input.action) {
532532
case "listFunctions": {
533533
const cloudbase = await getManager();
534+
const limit = input.limit ?? 20;
535+
const offset = input.offset ?? 0;
534536
const result = await cloudbase.functions.getFunctionList(
535-
input.limit,
536-
input.offset,
537+
limit,
538+
offset,
537539
);
538540
logCloudBaseResult(server.logger, result);
541+
const functions = result.Functions || [];
542+
const totalCount = result.TotalCount || 0;
543+
const hasMore = offset + functions.length < totalCount;
539544
return buildEnvelope(
540545
{
541546
action: input.action,
542-
functions: result.Functions || [],
543-
totalCount: result.TotalCount || 0,
547+
functions,
548+
totalCount,
549+
limit,
550+
offset,
551+
hasMore,
544552
requestId: result.RequestId,
545553
raw: result,
546554
},
547-
`已获取 ${result.Functions?.length || 0} 个云函数`,
555+
`已获取 ${functions.length} 个云函数,总计 ${totalCount}${hasMore ? ",还有更多数据" : ""}`,
548556
[
549557
{
550558
tool: "queryFunctions",
@@ -603,32 +611,40 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
603611
if (!input.functionName) {
604612
throw new Error("listFunctionLogs 操作时,functionName 参数是必需的");
605613
}
614+
const limit = input.limit ?? 20;
615+
const offset = input.offset ?? 0;
606616
validateLogRange(
607617
input.startTime,
608618
input.endTime,
609-
input.offset,
610-
input.limit,
619+
offset,
620+
limit,
611621
);
612622
const cloudbase = await getManager();
613623
const result = await cloudbase.functions.getFunctionLogsV2({
614624
name: input.functionName,
615-
offset: input.offset,
616-
limit: input.limit,
625+
offset,
626+
limit,
617627
startTime: input.startTime,
618628
endTime: input.endTime,
619629
requestId: input.requestId,
620630
qualifier: input.qualifier,
621631
});
622632
logCloudBaseResult(server.logger, result);
633+
const logs = result.LogList || [];
634+
// For logs, we infer hasMore based on whether we got a full page
635+
const hasMore = logs.length >= limit;
623636
return buildEnvelope(
624637
{
625638
action: input.action,
626639
functionName: input.functionName,
627-
logs: result.LogList || [],
640+
logs,
641+
limit,
642+
offset,
643+
hasMore,
628644
requestId: result.RequestId,
629645
raw: result,
630646
},
631-
`已获取函数 ${input.functionName} 的日志列表`,
647+
`已获取函数 ${input.functionName} ${logs.length} 条日志${hasMore ? ",可能还有更多数据" : ""}`,
632648
[
633649
{
634650
tool: "queryFunctions",
@@ -697,22 +713,30 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
697713
}
698714
case "listLayers": {
699715
const cloudbase = await getManager();
716+
const limit = input.limit ?? 20;
717+
const offset = input.offset ?? 0;
700718
const result = await cloudbase.functions.listLayers({
701-
offset: input.offset,
702-
limit: input.limit,
719+
offset,
720+
limit,
703721
runtime: input.runtime,
704722
searchKey: input.searchKey,
705723
});
706724
logCloudBaseResult(server.logger, result);
725+
const layers = result.Layers || [];
726+
const totalCount = result.TotalCount || 0;
727+
const hasMore = offset + layers.length < totalCount;
707728
return buildEnvelope(
708729
{
709730
action: input.action,
710-
layers: result.Layers || [],
711-
totalCount: result.TotalCount || 0,
731+
layers,
732+
totalCount,
733+
limit,
734+
offset,
735+
hasMore,
712736
requestId: result.RequestId,
713737
raw: result,
714738
},
715-
`已获取 ${result.Layers?.length || 0} 条层记录`,
739+
`已获取 ${layers.length} 条层记录,总计 ${totalCount}${hasMore ? ",还有更多数据" : ""}`,
716740
[
717741
{
718742
tool: "queryFunctions",

0 commit comments

Comments
 (0)