Skip to content

ref(mcp): Use @sentry/api pagination helpers in mcp-core - #2290

Merged
BYK merged 1 commit into
mainfrom
feat/mcp-sdk-pagination
Nov 16, 2026
Merged

BYK merged 1 commit into
mainfrom
feat/mcp-sdk-pagination

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

mcp-core parsed Link headers and walked pages by hand in several places. This PR moves it to the @sentry/api/client pagination helpers that the CLI already uses, deletes the hand-written walks, and turns on the CLI's lint rule so new ones don't slip back in.

find_dashboards now uses paginate() for both org-wide and project-scoped searches. In a project-constrained session each API page is filtered to the project before it counts toward limit. A walk that stops partway through a page returns the SDK's resumable cursor (the same limit:page:is_prev cursor Sentry's ChainPaginator uses, with the skip count encoded in it). That cursor replaces the custom base64 mcp-dashboard-project: cursor, and the per-page size is kept so resuming doesn't shift the page window. The output shape, the limit bounds and the "fill the page from later pages" behavior stay the same.

Full-list walks now go through a small fetchEveryPage() wrapper over fetchAllPages() in api-client/pagination.ts. That covers issue external links, issue integrations, Sentry App installations and components, dashboard title resolution, and the Alert source issue_stream monitor lookup. These walks used to loop without a bound, or quietly stop when a cursor repeated. They now throw when a cursor repeats or the walk passes MAX_LIST_PAGES, because a partial list could hide the record a lookup depends on.

Link parsing: getNextCursor() is deleted in favor of the SDK's nextPageCursor(response).

Lint: the CLI oxlint plugin's no-manual-pagination rule can now run outside packages/cli (the rule() helper takes the package dirs it applies to), and it's enabled for packages/mcp-core/src. Its message now names the helpers to use in each package.

Notes for review:

  • getAIConversation keeps its bounded loop and only switches to nextPageCursor(). It asks for 1000 spans per page across at most 10 pages and returns whatever it has at the cap. Neither SDK helper does that: paginate() would cap per_page at 100, and fetchAllPages() treats hitting the cap as a failure. The lint rule doesn't flag the loop because it isn't counting toward a limit.
  • Dashboard cursors issued before this change (mcp-dashboard-project:…) won't resume after it ships. They're opaque, short-lived values that clients get back from the previous call, so I didn't add a compatibility path. The org-wide guard that rejected project cursors is gone too: with plain SDK cursors, reusing one across scopes repeats rows instead of skipping them.
  • Docs: docs/contributing/api-patterns.md now points to these helpers instead of parseSentryLinkHeader.

Fixes #2287

via @BYK.

--

View Session [Sentry]

Replace mcp-core's hand-written Link-header parsing and page walks with the
SDK's pagination helpers, matching the CLI.

- find_dashboards uses paginate() for both org-wide and project-scoped
  searches. Project-scoped results are filtered per page, and a walk that stops
  inside a page returns the SDK's resumable cursor instead of the custom
  mcp-dashboard-project: cursor.
- Full-list walks (issue links and integrations, dashboard title resolution,
  Alert source detector lookup) go through a new fetchEveryPage() wrapper over
  fetchAllPages(). It throws on a repeated cursor or past MAX_LIST_PAGES
  instead of looping without a bound or returning a partial list.
- getNextCursor() is replaced by the SDK's nextPageCursor().
- Enable sentry-cli/no-manual-pagination for packages/mcp-core/src.

Fixes #2287

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 16, 2026 11:35
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 16, 2026 11:36am UTC

Request Review

@BYK
BYK merged commit 5103cec into main Nov 16, 2026
41 checks passed
@BYK
BYK deleted the feat/mcp-sdk-pagination branch November 16, 2026 13:20

This branch was successfully deployed

2 active deployments
Preview — cca2e8ae Deployed Nov 16, 2026 by vercel[bot]
Actions — cca2e8ae Deployed Nov 16, 2026 by sentry-junior[bot] via eval #1920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: use @sentry/api pagination for find_* tools

1 participant