Skip to content

fix(mcp): default-limit and paginate item(list) - #358

Merged
getappz merged 4 commits into
masterfrom
tmp/free-179
Jul 28, 2026
Merged

fix(mcp): default-limit and paginate item(list)#358
getappz merged 4 commits into
masterfrom
tmp/free-179

Conversation

@getappz

@getappz getappz commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • item(list) had no cap on results when limit was omitted, unlike search/groom — a bare call on a large project (155 items) overflowed the MCP response token limit (52,194 chars).
  • Default limit to 50 (capped at 500), matching the existing unwrap_or+clamp pattern used by search/groom.
  • list now returns a pagination envelope {items, total, offset, limit, next_offset, prev_offset} instead of a bare array, so callers can page forward/backward by passing next_offset/prev_offset straight back as offset — no manual math.
  • Updated the limit/offset field schema descriptions accordingly.

Test plan

  • cargo test -p agentflare item_tests — 35 passed (including new assertions on total/next_offset/prev_offset)
  • cargo build -p agentflare --bins
  • cargo clippy -p agentflare --bins -- -D warnings

Summary by CodeRabbit

  • New Features

    • Added bounded pagination for item lists.
    • Item list responses now return a paginated page object including items, total, offset, limit, and navigation metadata for next/previous pages.
    • Documented more precise pagination semantics for list, search, and grooming actions.
  • Bug Fixes

    • Prevented unbounded list responses by applying default limit and maximum cap.
    • Correctly computes totals from the fully filtered and sorted result set before paging.
    • Updated validation and edge-case behavior for out-of-range offsets and zero-limit requests.

item(list) had no cap when limit was omitted, unlike search/groom,
so a bare call on a large project could overflow the MCP response
token limit (155 items / 52k chars observed). Default it to 50
(capped at 500) and return a pagination envelope
(total/offset/limit/next_offset/prev_offset) so callers can page
forward/backward without re-deriving offsets by hand.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

item(list) now applies default and maximum page limits, slices filtered and sorted results, and returns an ItemListPage containing items, counts, offsets, and navigation metadata. Tests and request schema descriptions were updated for the new response shape.

Changes

Item list pagination

Layer / File(s) Summary
Pagination response contract
src/mcp_server/types.rs
ItemListPage defines the paginated response envelope, while request schema descriptions document limit defaults, caps, and offset navigation.
Pagination handler and validation
src/mcp_server/item.rs, src/mcp_server/tests/item_tests.rs
item_list computes totals, clamps limits, slices pages, and returns next/previous offsets; tests validate the envelope, metadata, filters, projections, and edge cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant item_list
  participant ItemListPage
  Caller->>item_list: Send list request with limit and offset
  item_list->>ItemListPage: Build page with items and navigation metadata
  ItemListPage-->>Caller: Return serialized paginated response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed It clearly summarizes the main change: adding default-limit pagination to item(list).
Description check ✅ Passed It covers the required Summary and Test plan sections, but omits the Notes for reviewers details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tmp/free-179

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/mcp_server/tests/item_tests.rs (1)

1250-1261: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover omitted and capped limits.

This test validates explicit limit = 1, but not the core new behaviors: omitted limit defaults to 50 and values above 500 are capped. Add cases with more than 50 and more than 500 matching items.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp_server/tests/item_tests.rs` around lines 1250 - 1261, Add test cases
alongside the existing item-listing assertions to cover omitted limit behavior
with more than 50 matching items and an explicit limit above 500 with more than
500 matches. Verify the omitted limit returns at most 50 items and the oversized
limit returns at most 500, while preserving the existing pagination assertions
for explicit limit = 1.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mcp_server/item.rs`:
- Around line 294-295: Update prev_offset in the pagination logic to derive the
previous page from min(offset, total), ensuring out-of-range offsets navigate
back toward the valid range. Also suppress prev_offset when limit == 0, while
preserving the existing saturating subtraction behavior for valid positive
limits.

---

Nitpick comments:
In `@src/mcp_server/tests/item_tests.rs`:
- Around line 1250-1261: Add test cases alongside the existing item-listing
assertions to cover omitted limit behavior with more than 50 matching items and
an explicit limit above 500 with more than 500 matches. Verify the omitted limit
returns at most 50 items and the oversized limit returns at most 500, while
preserving the existing pagination assertions for explicit limit = 1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a2c7fc3c-2b75-456c-a61e-bd9e67678117

📥 Commits

Reviewing files that changed from the base of the PR and between 5dab94b and f247401.

📒 Files selected for processing (3)
  • src/mcp_server/item.rs
  • src/mcp_server/tests/item_tests.rs
  • src/mcp_server/types.rs

Comment thread src/mcp_server/item.rs Outdated
getappz added 3 commits July 28, 2026 18:29
…inding

- cargo fmt wrap on the next_offset line (CI fmt check was failing)
- prev_offset now clamps via offset.min(total) so an out-of-range offset
  navigates back into range instead of repeating an empty page, and both
  next_offset/prev_offset suppress when limit == 0
@getappz
getappz enabled auto-merge (squash) July 28, 2026 13:22
@getappz
getappz merged commit 4497044 into master Jul 28, 2026
15 checks passed
@getappz
getappz deleted the tmp/free-179 branch July 28, 2026 13:27
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.

1 participant