refactor(mcp): eliminate duplicate cursor cycle detection by delegating paginateAll to PaginateAll#8049
Merged
Merged
Conversation
paginateAll now delegates to PaginateAll for cursor cycle detection and
page-limit enforcement instead of reimplementing that logic independently.
An adapter closure bridges the paginatedPage[T] fetch signature to the
([]T, string, error) signature expected by PaginateAll, and errors are
wrapped with serverID/itemKind context to preserve richer diagnostics.
Per-page "total so far" logging is intentionally removed in favour of the
per-page log emitted inside the adapter and the final total log after
PaginateAll returns. PaginateAll itself also logs per-page progress.
Updated tests in pagination_test.go and connection_test.go to match the
new error-message format ("exceeded N-page limit" instead of
"more than N pages").
Copilot
AI
changed the title
[WIP] Fix duplicate cursor cycle detection logic in pagination
refactor(mcp): eliminate duplicate cursor cycle detection by delegating paginateAll to PaginateAll
Jun 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MCP pagination so the internal paginateAll helper delegates the core cursor pagination logic (cycle detection + page limit enforcement) to the shared PaginateAll implementation, reducing duplicated safety logic while keeping server-scoped logging and error context.
Changes:
- Refactor
paginateAllto callPaginateAllvia an adapter closure and wrap errors withserverID/itemKindcontext. - Update error-message assertions in tests to match the
PaginateAllerror wording.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/pagination.go | Refactors paginateAll to delegate pagination mechanics to PaginateAll while retaining list logging and contextual error wrapping. |
| internal/mcp/pagination_test.go | Updates assertions to match the new page-limit error message text. |
| internal/mcp/connection_test.go | Updates assertions to match the new page-limit error message text. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
+72
to
+84
| result, err := PaginateAll(paginateAllMaxPages, func(cursor string) ([]T, string, error) { | ||
| page, err := fetch(cursor) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| all = append(all, page.Items...) | ||
| logConn.Printf("list%s: received page of %d %s (total so far: %d) from serverID=%s", itemKind, len(page.Items), itemKind, len(all), serverID) | ||
| cursor = page.NextCursor | ||
| logConn.Printf("list%s: received page of %d %s from serverID=%s", itemKind, len(page.Items), itemKind, serverID) | ||
| return page.Items, page.NextCursor, nil | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("list%s: backend serverID=%s: %w", itemKind, serverID, err) | ||
| } | ||
| logConn.Printf("list%s: received %d %s total from serverID=%s", itemKind, len(all), itemKind, serverID) | ||
| return all, nil | ||
| logConn.Printf("list%s: received %d %s total from serverID=%s", itemKind, len(result), itemKind, serverID) | ||
| return result, nil |
Collaborator
|
@copilot address review feedback |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
paginateAllandPaginateAllininternal/mcp/pagination.goeach independently implemented cursor cycle detection and page-limit enforcement — identical safety logic duplicated across ~30 lines, with subtly divergent ordering and error messages.Changes
internal/mcp/pagination.go—paginateAllis now a thin adapter overPaginateAll. A closure bridges thepaginatedPage[T]fetch signature toPaginateAll's([]T, string, error)contract, adding per-page logging. Errors are wrapped withserverID/itemKindcontext to preserve richer diagnostics:internal/mcp/pagination_test.go,internal/mcp/connection_test.go— Updated two test cases whose error-message assertions referenced the oldpaginateAllwording ("more than"/"pages") to match thePaginateAllformat ("exceeded"/"page limit").The mid-pagination "total so far" log is intentionally dropped;
PaginateAlllogs its own per-page progress, and the final total is still emitted after all pages are collected.