fix(mcp): apply default row cap in list_stored_queries markdown fallback
Summary
list_stored_queries's markdown fallback applies no default row cap, while the LanceDB path ten lines above defaults toMAX_ROW_LIMIT. Withlimitomitted, the fallback returns the entireknowledge/sqlcorpus.- 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 CImcp testsjob):test_list_stored_queries_fallback_applies_default_cap— forces the fallback via a raising store,MAX_ROW_LIMITmonkeypatched to 3, 10 pairs available.- Without the change:
assert 10 == 3— RED. With it: PASS.
- Without the change:
test_list_stored_queries_fallback_honours_explicit_limit— reverse anchor: an explicitlimit=2below the cap must still win.- Verified load-bearing: replacing the fix with a blanket
pairs[:MAX_ROW_LIMIT]reds it.
- Verified load-bearing: replacing the fix with a blanket
- Full
mcp testsjob vs cleanmain, 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.
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 243eec883e12657791bcf911f4c2f2de6638bfa8 and 84d34df9cc12ea3285e1d44dd67b7865ae360d08.
📒 Files selected for processing (2)
core/wren/src/wren/mcp_server.pycore/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.
Comment @coderabbitai help to get the list of available commands.