Skip to content

Commit 7e35a5b

Browse files
committed
feat(dependabot): add pagination to list_dependabot_alerts (github#2363)
1 parent 6ad3d2a commit 7e35a5b

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

‎pkg/github/dependabot.go‎

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ func GetDependabotAlert(t translations.TranslationHelperFunc) inventory.ServerTo
9595
}
9696

9797
func ListDependabotAlerts(t translations.TranslationHelperFunc) inventory.ServerTool {
98+
schema := &jsonschema.Schema{
99+
Type: "object",
100+
Properties: map[string]*jsonschema.Schema{
101+
"owner": {
102+
Type: "string",
103+
Description: "The owner of the repository.",
104+
},
105+
"repo": {
106+
Type: "string",
107+
Description: "The name of the repository.",
108+
},
109+
"state": {
110+
Type: "string",
111+
Description: "Filter dependabot alerts by state. Defaults to open",
112+
Enum: []any{"open", "fixed", "dismissed", "auto_dismissed"},
113+
Default: json.RawMessage(`"open"`),
114+
},
115+
"severity": {
116+
Type: "string",
117+
Description: "Filter dependabot alerts by severity",
118+
Enum: []any{"low", "medium", "high", "critical"},
119+
},
120+
},
121+
Required: []string{"owner", "repo"},
122+
}
123+
WithPagination(schema)
124+
98125
return NewTool(
99126
ToolsetMetadataDependabot,
100127
mcp.Tool{
@@ -104,31 +131,7 @@ func ListDependabotAlerts(t translations.TranslationHelperFunc) inventory.Server
104131
Title: t("TOOL_LIST_DEPENDABOT_ALERTS_USER_TITLE", "List dependabot alerts"),
105132
ReadOnlyHint: true,
106133
},
107-
InputSchema: &jsonschema.Schema{
108-
Type: "object",
109-
Properties: map[string]*jsonschema.Schema{
110-
"owner": {
111-
Type: "string",
112-
Description: "The owner of the repository.",
113-
},
114-
"repo": {
115-
Type: "string",
116-
Description: "The name of the repository.",
117-
},
118-
"state": {
119-
Type: "string",
120-
Description: "Filter dependabot alerts by state. Defaults to open",
121-
Enum: []any{"open", "fixed", "dismissed", "auto_dismissed"},
122-
Default: json.RawMessage(`"open"`),
123-
},
124-
"severity": {
125-
Type: "string",
126-
Description: "Filter dependabot alerts by severity",
127-
Enum: []any{"low", "medium", "high", "critical"},
128-
},
129-
},
130-
Required: []string{"owner", "repo"},
131-
},
134+
InputSchema: schema,
132135
},
133136
[]scopes.Scope{scopes.SecurityEvents},
134137
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
@@ -149,6 +152,11 @@ func ListDependabotAlerts(t translations.TranslationHelperFunc) inventory.Server
149152
return utils.NewToolResultError(err.Error()), nil, nil
150153
}
151154

155+
pagination, err := OptionalPaginationParams(args)
156+
if err != nil {
157+
return utils.NewToolResultError(err.Error()), nil, nil
158+
}
159+
152160
client, err := deps.GetClient(ctx)
153161
if err != nil {
154162
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, err
@@ -157,6 +165,10 @@ func ListDependabotAlerts(t translations.TranslationHelperFunc) inventory.Server
157165
alerts, resp, err := client.Dependabot.ListRepoAlerts(ctx, owner, repo, &github.ListAlertsOptions{
158166
State: ToStringPtr(state),
159167
Severity: ToStringPtr(severity),
168+
ListOptions: github.ListOptions{
169+
Page: pagination.Page,
170+
PerPage: pagination.PerPage,
171+
},
160172
})
161173
if err != nil {
162174
return ghErrors.NewGitHubAPIErrorResponse(ctx,

0 commit comments

Comments
 (0)