Skip to content

Commit 08a49b0

Browse files
authored
use WithPagination tool option (#632)
1 parent 23f6f3a commit 08a49b0

File tree

6 files changed

+40
-82
lines changed

6 files changed

+40
-82
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,15 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
478478
- **list_workflow_jobs** - List workflow jobs
479479
- `filter`: Filters jobs by their completed_at timestamp (string, optional)
480480
- `owner`: Repository owner (string, required)
481-
- `page`: The page number of the results to fetch (number, optional)
482-
- `per_page`: The number of results per page (max 100) (number, optional)
481+
- `page`: Page number for pagination (min 1) (number, optional)
482+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
483483
- `repo`: Repository name (string, required)
484484
- `run_id`: The unique identifier of the workflow run (number, required)
485485

486486
- **list_workflow_run_artifacts** - List workflow artifacts
487487
- `owner`: Repository owner (string, required)
488-
- `page`: The page number of the results to fetch (number, optional)
489-
- `per_page`: The number of results per page (max 100) (number, optional)
488+
- `page`: Page number for pagination (min 1) (number, optional)
489+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
490490
- `repo`: Repository name (string, required)
491491
- `run_id`: The unique identifier of the workflow run (number, required)
492492

@@ -495,16 +495,16 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
495495
- `branch`: Returns workflow runs associated with a branch. Use the name of the branch. (string, optional)
496496
- `event`: Returns workflow runs for a specific event type (string, optional)
497497
- `owner`: Repository owner (string, required)
498-
- `page`: The page number of the results to fetch (number, optional)
499-
- `per_page`: The number of results per page (max 100) (number, optional)
498+
- `page`: Page number for pagination (min 1) (number, optional)
499+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
500500
- `repo`: Repository name (string, required)
501501
- `status`: Returns workflow runs with the check run status (string, optional)
502502
- `workflow_id`: The workflow ID or workflow file name (string, required)
503503

504504
- **list_workflows** - List workflows
505505
- `owner`: Repository owner (string, required)
506-
- `page`: The page number of the results to fetch (number, optional)
507-
- `per_page`: The number of results per page (max 100) (number, optional)
506+
- `page`: Page number for pagination (min 1) (number, optional)
507+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
508508
- `repo`: Repository name (string, required)
509509

510510
- **rerun_failed_jobs** - Rerun failed jobs
@@ -632,8 +632,8 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
632632
- **get_issue_comments** - Get issue comments
633633
- `issue_number`: Issue number (number, required)
634634
- `owner`: Repository owner (string, required)
635-
- `page`: Page number (number, optional)
636-
- `per_page`: Number of records per page (number, optional)
635+
- `page`: Page number for pagination (min 1) (number, optional)
636+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
637637
- `repo`: Repository name (string, required)
638638

639639
- **list_issues** - List issues

pkg/github/__toolsnaps__/get_issue_comments.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
"type": "string"
1616
},
1717
"page": {
18-
"description": "Page number",
18+
"description": "Page number for pagination (min 1)",
19+
"minimum": 1,
1920
"type": "number"
2021
},
21-
"per_page": {
22-
"description": "Number of records per page",
22+
"perPage": {
23+
"description": "Results per page for pagination (min 1, max 100)",
24+
"maximum": 100,
25+
"minimum": 1,
2326
"type": "number"
2427
},
2528
"repo": {

pkg/github/actions.go

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
3737
mcp.Required(),
3838
mcp.Description(DescriptionRepositoryName),
3939
),
40-
mcp.WithNumber("per_page",
41-
mcp.Description("The number of results per page (max 100)"),
42-
),
43-
mcp.WithNumber("page",
44-
mcp.Description("The page number of the results to fetch"),
45-
),
40+
WithPagination(),
4641
),
4742
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
4843
owner, err := RequiredParam[string](request, "owner")
@@ -55,11 +50,7 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
5550
}
5651

5752
// Get optional pagination parameters
58-
perPage, err := OptionalIntParam(request, "per_page")
59-
if err != nil {
60-
return mcp.NewToolResultError(err.Error()), nil
61-
}
62-
page, err := OptionalIntParam(request, "page")
53+
pagination, err := OptionalPaginationParams(request)
6354
if err != nil {
6455
return mcp.NewToolResultError(err.Error()), nil
6556
}
@@ -71,8 +62,8 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
7162

7263
// Set up list options
7364
opts := &github.ListOptions{
74-
PerPage: perPage,
75-
Page: page,
65+
PerPage: pagination.perPage,
66+
Page: pagination.page,
7667
}
7768

7869
workflows, resp, err := client.Actions.ListWorkflows(ctx, owner, repo, opts)
@@ -157,12 +148,7 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
157148
mcp.Description("Returns workflow runs with the check run status"),
158149
mcp.Enum("queued", "in_progress", "completed", "requested", "waiting"),
159150
),
160-
mcp.WithNumber("per_page",
161-
mcp.Description("The number of results per page (max 100)"),
162-
),
163-
mcp.WithNumber("page",
164-
mcp.Description("The page number of the results to fetch"),
165-
),
151+
WithPagination(),
166152
),
167153
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
168154
owner, err := RequiredParam[string](request, "owner")
@@ -197,11 +183,7 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
197183
}
198184

199185
// Get optional pagination parameters
200-
perPage, err := OptionalIntParam(request, "per_page")
201-
if err != nil {
202-
return mcp.NewToolResultError(err.Error()), nil
203-
}
204-
page, err := OptionalIntParam(request, "page")
186+
pagination, err := OptionalPaginationParams(request)
205187
if err != nil {
206188
return mcp.NewToolResultError(err.Error()), nil
207189
}
@@ -218,8 +200,8 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
218200
Event: event,
219201
Status: status,
220202
ListOptions: github.ListOptions{
221-
PerPage: perPage,
222-
Page: page,
203+
PerPage: pagination.perPage,
204+
Page: pagination.page,
223205
},
224206
}
225207

@@ -483,12 +465,7 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
483465
mcp.Description("Filters jobs by their completed_at timestamp"),
484466
mcp.Enum("latest", "all"),
485467
),
486-
mcp.WithNumber("per_page",
487-
mcp.Description("The number of results per page (max 100)"),
488-
),
489-
mcp.WithNumber("page",
490-
mcp.Description("The page number of the results to fetch"),
491-
),
468+
WithPagination(),
492469
),
493470
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
494471
owner, err := RequiredParam[string](request, "owner")
@@ -512,11 +489,7 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
512489
}
513490

514491
// Get optional pagination parameters
515-
perPage, err := OptionalIntParam(request, "per_page")
516-
if err != nil {
517-
return mcp.NewToolResultError(err.Error()), nil
518-
}
519-
page, err := OptionalIntParam(request, "page")
492+
pagination, err := OptionalPaginationParams(request)
520493
if err != nil {
521494
return mcp.NewToolResultError(err.Error()), nil
522495
}
@@ -530,8 +503,8 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
530503
opts := &github.ListWorkflowJobsOptions{
531504
Filter: filter,
532505
ListOptions: github.ListOptions{
533-
PerPage: perPage,
534-
Page: page,
506+
PerPage: pagination.perPage,
507+
Page: pagination.page,
535508
},
536509
}
537510

@@ -1022,12 +995,7 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
1022995
mcp.Required(),
1023996
mcp.Description("The unique identifier of the workflow run"),
1024997
),
1025-
mcp.WithNumber("per_page",
1026-
mcp.Description("The number of results per page (max 100)"),
1027-
),
1028-
mcp.WithNumber("page",
1029-
mcp.Description("The page number of the results to fetch"),
1030-
),
998+
WithPagination(),
1031999
),
10321000
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
10331001
owner, err := RequiredParam[string](request, "owner")
@@ -1045,11 +1013,7 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10451013
runID := int64(runIDInt)
10461014

10471015
// Get optional pagination parameters
1048-
perPage, err := OptionalIntParam(request, "per_page")
1049-
if err != nil {
1050-
return mcp.NewToolResultError(err.Error()), nil
1051-
}
1052-
page, err := OptionalIntParam(request, "page")
1016+
pagination, err := OptionalPaginationParams(request)
10531017
if err != nil {
10541018
return mcp.NewToolResultError(err.Error()), nil
10551019
}
@@ -1061,8 +1025,8 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10611025

10621026
// Set up list options
10631027
opts := &github.ListOptions{
1064-
PerPage: perPage,
1065-
Page: page,
1028+
PerPage: pagination.perPage,
1029+
Page: pagination.page,
10661030
}
10671031

10681032
artifacts, resp, err := client.Actions.ListWorkflowRunArtifacts(ctx, owner, repo, runID, opts)

pkg/github/actions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func Test_ListWorkflows(t *testing.T) {
2323
assert.NotEmpty(t, tool.Description)
2424
assert.Contains(t, tool.InputSchema.Properties, "owner")
2525
assert.Contains(t, tool.InputSchema.Properties, "repo")
26-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
26+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
2727
assert.Contains(t, tool.InputSchema.Properties, "page")
2828
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
2929

@@ -393,7 +393,7 @@ func Test_ListWorkflowRunArtifacts(t *testing.T) {
393393
assert.Contains(t, tool.InputSchema.Properties, "owner")
394394
assert.Contains(t, tool.InputSchema.Properties, "repo")
395395
assert.Contains(t, tool.InputSchema.Properties, "run_id")
396-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
396+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
397397
assert.Contains(t, tool.InputSchema.Properties, "page")
398398
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "run_id"})
399399

pkg/github/issues.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,7 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun
608608
mcp.Required(),
609609
mcp.Description("Issue number"),
610610
),
611-
mcp.WithNumber("page",
612-
mcp.Description("Page number"),
613-
),
614-
mcp.WithNumber("per_page",
615-
mcp.Description("Number of records per page"),
616-
),
611+
WithPagination(),
617612
),
618613
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
619614
owner, err := RequiredParam[string](request, "owner")
@@ -628,19 +623,15 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun
628623
if err != nil {
629624
return mcp.NewToolResultError(err.Error()), nil
630625
}
631-
page, err := OptionalIntParamWithDefault(request, "page", 1)
632-
if err != nil {
633-
return mcp.NewToolResultError(err.Error()), nil
634-
}
635-
perPage, err := OptionalIntParamWithDefault(request, "per_page", 30)
626+
pagination, err := OptionalPaginationParams(request)
636627
if err != nil {
637628
return mcp.NewToolResultError(err.Error()), nil
638629
}
639630

640631
opts := &github.IssueListCommentsOptions{
641632
ListOptions: github.ListOptions{
642-
Page: page,
643-
PerPage: perPage,
633+
Page: pagination.page,
634+
PerPage: pagination.perPage,
644635
},
645636
}
646637

pkg/github/issues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ func Test_GetIssueComments(t *testing.T) {
10871087
assert.Contains(t, tool.InputSchema.Properties, "repo")
10881088
assert.Contains(t, tool.InputSchema.Properties, "issue_number")
10891089
assert.Contains(t, tool.InputSchema.Properties, "page")
1090-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
1090+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
10911091
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "issue_number"})
10921092

10931093
// Setup mock comments for success case
@@ -1152,7 +1152,7 @@ func Test_GetIssueComments(t *testing.T) {
11521152
"repo": "repo",
11531153
"issue_number": float64(42),
11541154
"page": float64(2),
1155-
"per_page": float64(10),
1155+
"perPage": float64(10),
11561156
},
11571157
expectError: false,
11581158
expectedComments: mockComments,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy