Commit 848479a
authored
refactor(mcp): eliminate duplicate cursor cycle detection by delegating paginateAll to PaginateAll (#8049)
`paginateAll` and `PaginateAll` in `internal/mcp/pagination.go` each
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`** — `paginateAll` is now a thin adapter
over `PaginateAll`. A closure bridges the `paginatedPage[T]` fetch
signature to `PaginateAll`'s `([]T, string, error)` contract, adding
per-page logging. Errors are wrapped with `serverID`/`itemKind` context
to preserve richer diagnostics:
```go
func paginateAll[T any](serverID, itemKind string, fetch func(cursor
string) (paginatedPage[T], error)) ([]T, error) {
result, err := PaginateAll(paginateAllMaxPages, func(cursor string)
([]T, string, error) {
page, err := fetch(cursor)
if err != nil {
return nil, "", err
}
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(result), itemKind, serverID)
return result, nil
}
```
- **`internal/mcp/pagination_test.go`**,
**`internal/mcp/connection_test.go`** — Updated two test cases whose
error-message assertions referenced the old `paginateAll` wording
(`"more than"` / `"pages"`) to match the `PaginateAll` format
(`"exceeded"` / `"page limit"`).
The mid-pagination "total so far" log is intentionally dropped;
`PaginateAll` logs its own per-page progress, and the final total is
still emitted after all pages are collected.3 files changed
Lines changed: 20 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
990 | 990 | | |
991 | 991 | | |
992 | 992 | | |
993 | | - | |
994 | | - | |
| 993 | + | |
| 994 | + | |
995 | 995 | | |
996 | 996 | | |
997 | 997 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 72 | + | |
91 | 73 | | |
92 | 74 | | |
93 | | - | |
| 75 | + | |
94 | 76 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
98 | 82 | | |
99 | | - | |
100 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
101 | 88 | | |
102 | 89 | | |
103 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
381 | | - | |
| 381 | + | |
| 382 | + | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
| |||
0 commit comments