@@ -50,8 +50,8 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
5050 return mcp .NewToolResultError (err .Error ()), nil
5151 }
5252
53- // Get optional pagination parameters
54- pagination , err := OptionalPaginationParams (request )
53+ // Get cursor-based pagination parameters
54+ cursorParams , err := GetCursorBasedParams (request )
5555 if err != nil {
5656 return mcp .NewToolResultError (err .Error ()), nil
5757 }
@@ -61,10 +61,10 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
6161 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
6262 }
6363
64- // Set up list options
64+ // Set up list options - request one extra to check for more results
6565 opts := & github.ListOptions {
66- PerPage : pagination .PerPage ,
67- Page : pagination .Page ,
66+ PerPage : cursorParams .PerPage + 1 ,
67+ Page : cursorParams .Page ,
6868 }
6969
7070 workflows , resp , err := client .Actions .ListWorkflows (ctx , owner , repo , opts )
@@ -73,12 +73,16 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
7373 }
7474 defer func () { _ = resp .Body .Close () }()
7575
76- r , err := json .Marshal (workflows )
77- if err != nil {
78- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
76+ // Check if there are more results
77+ hasMore := len (workflows .Workflows ) > cursorParams .PerPage
78+ if hasMore {
79+ // Remove the extra item
80+ workflows .Workflows = workflows .Workflows [:cursorParams .PerPage ]
7981 }
8082
81- return mcp .NewToolResultText (string (r )), nil
83+ // Create paginated response
84+ paginatedResp := NewPaginatedRESTResponse (workflows , cursorParams .Page , cursorParams .PerPage , hasMore )
85+ return MarshalPaginatedResponse (paginatedResp ), nil
8286 }
8387}
8488
@@ -183,8 +187,8 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
183187 return mcp .NewToolResultError (err .Error ()), nil
184188 }
185189
186- // Get optional pagination parameters
187- pagination , err := OptionalPaginationParams (request )
190+ // Get cursor-based pagination parameters
191+ cursorParams , err := GetCursorBasedParams (request )
188192 if err != nil {
189193 return mcp .NewToolResultError (err .Error ()), nil
190194 }
@@ -194,15 +198,15 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
194198 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
195199 }
196200
197- // Set up list options
201+ // Set up list options - request one extra to check for more results
198202 opts := & github.ListWorkflowRunsOptions {
199203 Actor : actor ,
200204 Branch : branch ,
201205 Event : event ,
202206 Status : status ,
203207 ListOptions : github.ListOptions {
204- PerPage : pagination .PerPage ,
205- Page : pagination .Page ,
208+ PerPage : cursorParams .PerPage + 1 ,
209+ Page : cursorParams .Page ,
206210 },
207211 }
208212
@@ -212,12 +216,16 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
212216 }
213217 defer func () { _ = resp .Body .Close () }()
214218
215- r , err := json .Marshal (workflowRuns )
216- if err != nil {
217- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
219+ // Check if there are more results
220+ hasMore := len (workflowRuns .WorkflowRuns ) > cursorParams .PerPage
221+ if hasMore {
222+ // Remove the extra item
223+ workflowRuns .WorkflowRuns = workflowRuns .WorkflowRuns [:cursorParams .PerPage ]
218224 }
219225
220- return mcp .NewToolResultText (string (r )), nil
226+ // Create paginated response
227+ paginatedResp := NewPaginatedRESTResponse (workflowRuns , cursorParams .Page , cursorParams .PerPage , hasMore )
228+ return MarshalPaginatedResponse (paginatedResp ), nil
221229 }
222230}
223231
@@ -489,8 +497,8 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
489497 return mcp .NewToolResultError (err .Error ()), nil
490498 }
491499
492- // Get optional pagination parameters
493- pagination , err := OptionalPaginationParams (request )
500+ // Get cursor-based pagination parameters
501+ cursorParams , err := GetCursorBasedParams (request )
494502 if err != nil {
495503 return mcp .NewToolResultError (err .Error ()), nil
496504 }
@@ -500,12 +508,12 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
500508 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
501509 }
502510
503- // Set up list options
511+ // Set up list options - request one extra to check for more results
504512 opts := & github.ListWorkflowJobsOptions {
505513 Filter : filter ,
506514 ListOptions : github.ListOptions {
507- PerPage : pagination .PerPage ,
508- Page : pagination .Page ,
515+ PerPage : cursorParams .PerPage + 1 ,
516+ Page : cursorParams .Page ,
509517 },
510518 }
511519
@@ -515,18 +523,22 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
515523 }
516524 defer func () { _ = resp .Body .Close () }()
517525
526+ // Check if there are more results
527+ hasMore := len (jobs .Jobs ) > cursorParams .PerPage
528+ if hasMore {
529+ // Remove the extra item
530+ jobs .Jobs = jobs .Jobs [:cursorParams .PerPage ]
531+ }
532+
518533 // Add optimization tip for failed job debugging
519534 response := map [string ]any {
520535 "jobs" : jobs ,
521536 "optimization_tip" : "For debugging failed jobs, consider using get_job_logs with failed_only=true and run_id=" + fmt .Sprintf ("%d" , runID ) + " to get logs directly without needing to list jobs first" ,
522537 }
523538
524- r , err := json .Marshal (response )
525- if err != nil {
526- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
527- }
528-
529- return mcp .NewToolResultText (string (r )), nil
539+ // Create paginated response
540+ paginatedResp := NewPaginatedRESTResponse (response , cursorParams .Page , cursorParams .PerPage , hasMore )
541+ return MarshalPaginatedResponse (paginatedResp ), nil
530542 }
531543}
532544
@@ -1006,8 +1018,8 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10061018 }
10071019 runID := int64 (runIDInt )
10081020
1009- // Get optional pagination parameters
1010- pagination , err := OptionalPaginationParams (request )
1021+ // Get cursor-based pagination parameters
1022+ cursorParams , err := GetCursorBasedParams (request )
10111023 if err != nil {
10121024 return mcp .NewToolResultError (err .Error ()), nil
10131025 }
@@ -1017,10 +1029,10 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10171029 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
10181030 }
10191031
1020- // Set up list options
1032+ // Set up list options - request one extra to check for more results
10211033 opts := & github.ListOptions {
1022- PerPage : pagination .PerPage ,
1023- Page : pagination .Page ,
1034+ PerPage : cursorParams .PerPage + 1 ,
1035+ Page : cursorParams .Page ,
10241036 }
10251037
10261038 artifacts , resp , err := client .Actions .ListWorkflowRunArtifacts (ctx , owner , repo , runID , opts )
@@ -1029,12 +1041,16 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10291041 }
10301042 defer func () { _ = resp .Body .Close () }()
10311043
1032- r , err := json .Marshal (artifacts )
1033- if err != nil {
1034- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
1044+ // Check if there are more results
1045+ hasMore := len (artifacts .Artifacts ) > cursorParams .PerPage
1046+ if hasMore {
1047+ // Remove the extra item
1048+ artifacts .Artifacts = artifacts .Artifacts [:cursorParams .PerPage ]
10351049 }
10361050
1037- return mcp .NewToolResultText (string (r )), nil
1051+ // Create paginated response
1052+ paginatedResp := NewPaginatedRESTResponse (artifacts , cursorParams .Page , cursorParams .PerPage , hasMore )
1053+ return MarshalPaginatedResponse (paginatedResp ), nil
10381054 }
10391055}
10401056
0 commit comments