Skip to content

feat: add pagination to list GHAS alerts tools#2451

Open
dvirarad wants to merge 9 commits into
github:mainfrom
dvirarad:feat/ghas-list-alerts-pagination
Open

feat: add pagination to list GHAS alerts tools#2451
dvirarad wants to merge 9 commits into
github:mainfrom
dvirarad:feat/ghas-list-alerts-pagination

Conversation

@dvirarad
Copy link
Copy Markdown

Fixes #2363.

Why

The three GHAS list-alerts tools — list_code_scanning_alerts, list_dependabot_alerts, list_secret_scanning_alerts — currently send GET with no page / per_page query parameters, so the API returns at most 30 alerts and there is no way to fetch the rest. As @rwjblue-glitch notes in the issue, this gives AI tooling a false sense of security: it sees 30 alerts and reports "these are the alerts," when the underlying repo may have hundreds.

The issue reproduces with prompts like "generate a CSV with ALL code scanning alerts" — the model uses list_code_scanning_alerts, gets 30 rows, writes them out, and never knows it was truncated.

Underlying go-github types (AlertListOptions, ListAlertsOptions, SecretScanningAlertListOptions) already embed ListOptions, so this is a small wiring change that matches what issue_read, list_issues, etc. already do via WithPagination / OptionalPaginationParams.

What

pkg/github/code_scanning.go, pkg/github/dependabot.go, pkg/github/secret_scanning.go — for each list tool:

  • Extract the input schema into a local schema variable and call WithPagination(schema) so the tool exposes page and perPage (matching the existing convention, e.g. issues.go line 235).
  • In the handler, call OptionalPaginationParams(args) and populate ListOptions{Page, PerPage} on the respective options struct.

No new helpers; no API changes beyond two new optional input fields per tool; secret_scanning.SecretScanningAlertListOptions also embeds ListCursorOptions but go-github documents that REST Enterprise Cloud and .com both honor page from ListOptions, which is the existing convention in this repo for paginated list tools.

Tests

  • pkg/github/code_scanning_test.go, pkg/github/dependabot_test.go, pkg/github/secret_scanning_test.go:
    • Updated existing expectQueryParams maps to include the new defaults ("page": "1", "per_page": "30").
    • Added a successful alerts listing with custom pagination case per tool that asserts page=2/page=3 and per_page=50/per_page=100 propagate to the upstream request.
    • Added assert.Contains(t, schema.Properties, "page") / "perPage" to the schema-shape assertions in the code-scanning test (matches existing style there).
  • pkg/github/__toolsnaps__/list_*.snap regenerated to include page and perPage (matches the format used by every other WithPagination tool, e.g. issue_read.snap).

Out of scope

  • list_*_alerts_for_org and list_*_alerts_for_enterprise (if/when added) would benefit from the same treatment; this PR keeps the change focused on the three repo-level list tools called out in Pagination on GHAS list_* endpoints #2363.

Checklist

  • Existing tests updated to reflect new default query params.
  • New pagination tests added.
  • Tool snapshots refreshed.
  • No new direct dependencies.
  • No tool schema-breaking changes (page and perPage are optional with documented defaults).

Copilot AI review requested due to automatic review settings May 11, 2026 12:33
@dvirarad dvirarad requested a review from a team as a code owner May 11, 2026 12:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds standard REST pagination support to the GHAS repository-level “list alerts” MCP tools so callers can retrieve more than the first 30 alerts returned by default from GitHub’s APIs (fixing the truncation problem described in #2363).

Changes:

  • Exposes page and perPage inputs for list_code_scanning_alerts, list_dependabot_alerts, and list_secret_scanning_alerts via WithPagination(...).
  • Wires OptionalPaginationParams(args) into each tool handler and forwards github.ListOptions{Page, PerPage} to go-github request options.
  • Updates unit tests and regenerates tool schema snapshots to reflect default and custom pagination behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/github/code_scanning.go Adds paginated input schema and forwards ListOptions to the Code Scanning list-alerts API call.
pkg/github/code_scanning_test.go Updates query-param expectations for default pagination and adds a custom pagination test; asserts schema now contains page/perPage.
pkg/github/dependabot.go Adds paginated input schema and forwards ListOptions to the Dependabot list-alerts API call.
pkg/github/dependabot_test.go Updates query-param expectations for default pagination and adds a custom pagination test.
pkg/github/secret_scanning.go Adds paginated input schema and forwards ListOptions to the Secret Scanning list-alerts API call.
pkg/github/secret_scanning_test.go Updates query-param expectations for default pagination and adds a custom pagination test.
pkg/github/toolsnaps/list_code_scanning_alerts.snap Snapshot updated to include page and perPage inputs.
pkg/github/toolsnaps/list_dependabot_alerts.snap Snapshot updated to include page and perPage inputs.
pkg/github/toolsnaps/list_secret_scanning_alerts.snap Snapshot updated to include page and perPage inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pagination on GHAS list_* endpoints

3 participants