Skip to content

fix(mcp): apply default row cap in list_stored_queries markdown fallback#2526

Merged
goldmedal merged 1 commit into
Canner:mainfrom
AnnaSuSu:fix/mcp-list-stored-queries-cap
Jul 21, 2026
Merged

fix(mcp): apply default row cap in list_stored_queries markdown fallback#2526
goldmedal merged 1 commit into
Canner:mainfrom
AnnaSuSu:fix/mcp-list-stored-queries-cap

Conversation

@AnnaSuSu

@AnnaSuSu AnnaSuSu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • list_stored_queries's markdown fallback applies no default row cap, while the LanceDB path ten lines above defaults to MAX_ROW_LIMIT. With limit omitted, the fallback returns the entire knowledge/sql corpus.
  • Fix: apply the same default in the fallback — a one-line change.

Motivation

Both paths live in the same handler and disagree:

try:
    rows, _total = store.list_queries(
        source=source,
        limit=limit if limit is not None else MAX_ROW_LIMIT,   # default cap
    )
except Exception:
    pairs = load_query_pairs(ctx.project)
    if limit is not None:
        pairs = pairs[:limit]                                  # no default cap

Every other MAX_ROW_LIMIT site guards:

site guard
_query_with_limit_probe min(effective_limit, MAX_ROW_LIMIT)
_query_cube_with_limit_probe min(effective_limit, MAX_ROW_LIMIT)
list_stored_queries (LanceDB) limit if limit is not None else MAX_ROW_LIMIT
list_stored_queries (fallback) — none

Three of four obey the cap; the fourth doesn't.

Reachability is wider than "user didn't install the memory extra": the except Exception catches any MemoryStore error, so an installed-and-working setup that hits one transient failure silently switches from capped to uncapped and returns the whole corpus to the MCP client.

Fix

pairs = pairs[: limit if limit is not None else MAX_ROW_LIMIT]

This mirrors the sibling path's semantics exactly (default when omitted, honour an explicit limit). I deliberately did not also align the other asymmetry — the probe helpers hard-cap with min(...) while list_stored_queries treats MAX_ROW_LIMIT as a default an explicit larger limit can exceed. Reconciling those two is a behaviour change to an existing API, not a bug fix, so it is out of scope here.

Verification

  • New regression tests in tests/unit/test_mcp_server.py (covered by the dedicated CI mcp tests job):
    • test_list_stored_queries_fallback_applies_default_cap — forces the fallback via a raising store, MAX_ROW_LIMIT monkeypatched to 3, 10 pairs available.
      • Without the change: assert 10 == 3RED. With it: PASS.
    • test_list_stored_queries_fallback_honours_explicit_limit — reverse anchor: an explicit limit=2 below the cap must still win.
      • Verified load-bearing: replacing the fix with a blanket pairs[:MAX_ROW_LIMIT] reds it.
  • Full mcp tests job vs clean main, verbatim: 14 → 16 passed (+2 = exactly the new tests; 0 new failures). Lint clean (just lint).

License

core/** is Apache-2.0 per the repo LICENSE path map — this contribution is within an Apache-2.0 path.

Summary by CodeRabbit

  • Bug Fixes

    • Limited stored query results to the default maximum when no limit is specified.
    • Ensured explicitly requested result limits are consistently honored, including fallback scenarios.
  • Tests

    • Added coverage for default and custom result limits when the primary query storage service is unavailable.

@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bbb24eb7-1741-4b16-b480-26f269bdb61a

📥 Commits

Reviewing files that changed from the base of the PR and between 243eec8 and 84d34df.

📒 Files selected for processing (2)
  • core/wren/src/wren/mcp_server.py
  • core/wren/tests/unit/test_mcp_server.py

Walkthrough

list_stored_queries now caps markdown fallback results by the default maximum when no limit is supplied and honors explicit limits. Unit tests cover both fallback behaviors.

Changes

Stored query fallback limits

Layer / File(s) Summary
Fallback limit enforcement and validation
core/wren/src/wren/mcp_server.py, core/wren/tests/unit/test_mcp_server.py
Fallback results are capped by MAX_ROW_LIMIT or the caller’s explicit limit, with tests covering both cases.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: ttw225

Poem

A rabbit found queries hopping wide,
So capped their trail with care and pride.
Three by default, or two on request,
The markdown burrow now works best.
“No endless hops!” the bunny cried.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: applying the default row cap in the markdown fallback for list_stored_queries.
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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @AnnaSuSu 👍

@goldmedal
goldmedal merged commit 86fac4f into Canner:main Jul 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants