Repository navigation
feat(mcp): bound agent response payloads - #2790
Conversation
Problem: MCP search and message reads could flood an agent context with\nrepeated affordance metadata or oversized message bodies, while session\nsummaries exposed only identifiers and counts.\n\nWhat changed: add a shared 25 KB response budget with metadata-only\nreplay descriptors; make search affordances opt-in; add per-message\ncharacter caps and excerpts; and enrich session summaries with bounded\ncontent orientation.\n\nCompatibility: normal responses preserve their existing typed envelope;\nonly oversized responses use the new bounded envelope.\n\nCo-Authored-By: Claude <[email protected]>
Correct the response-envelope helper annotations so the pre-push\nstrict mypy gate accepts the affordance and continuation contracts.\n\nCo-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 31 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Problem: malformed MCP query values previously surfaced without a machine-readable recovery set. What changed: map QuerySpec errors to a stable invalid_query envelope with field, tool, and valid_values metadata.
Problem: block-level search duplicated sessions in MCP list responses, and empty multi-term searches gave no indication of which term missed. What changed: list sessions now emits one row per session with an exact match_count; empty multi-term search responses include filtered per-term counts. Tests invoke registered MCP tools against archive data.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 780782be38
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Problem: query-tool schema drifted for a search-only option, exhausted search pages were misdiagnosed as misses, and text list pagination scanned the full raw result set. What changed: document the schema exception, gate diagnostics on total zero, and stop FTS coalescing once the requested distinct page is known. Focused MCP tests cover each production route.
Problem: oversized non-query session reads lacked replay arguments, bounded list coalescing could overstate match cardinality, and deeply nested fallback metadata could exceed the response budget. What changed: safe calls now carry session replay identifiers, match counts disclose exactness, fallback metadata has a depth bound, and the affordance catalog is available as an MCP resource. Focused tests cover each route.
Adversarial review — iteration 1Findings:
Fixes in
What survived scrutiny:
|
Problem: archive-session, correction-list, and message-resource budget fallbacks could either repeat the oversized request or offer no callable next action. What changed: archive sessions and message resources replay through capped message reads; corrections now use the shared serializer with pagination and per-item caps. Tests invoke every advertised continuation.
Adversarial review — iteration 2Findings:
Fixes in
What survived scrutiny:
|
Problem: Adversarial review found an unbounded tag-count map with a non-replayable fallback, excerpts that could omit the search evidence an agent needs, and unknown MCP origin filters silently normalized to unknown-export. What changed: Page tag maps deterministically with replay context, center bounded message excerpts on an optional match query, and reject unknown query-origin tokens with the existing valid-values error contract. Production-route MCP tests exercise all three behavior changes. Ref polylogue-rsad. Co-Authored-By: Claude <[email protected]>
Adversarial review — iteration 3Findings:
Fixes in
What survived scrutiny:
Ref polylogue-rsad. |
Problem: Several mutable list tools and the tags resource could exceed the shared MCP budget yet advertise an unchanged or absent continuation. What changed: Add limit/offset envelopes and bounded replay contexts to mutable list tools, compact oversized saved item payloads during a replay, and route the tags resource fallback through the paged list_tags tool. Ref polylogue-rsad. Co-Authored-By: Claude <[email protected]>
Problem: Closed-vocabulary typos inside the query DSL bypassed the MCP invalid-query envelope even though direct query filters returned valid recovery values. What changed: Route expression compilation errors through the shared query-error formatter, preserving field metadata and valid values for closed query vocabularies. Ref polylogue-rsad. Co-Authored-By: Claude <[email protected]>
Adversarial review — iteration 4Findings:
Fixes in
What survived scrutiny:
Ref polylogue-rsad. |
Adversarial review — iteration 5 (loop cap reached)Remaining real gaps:
No changes were made in this iteration. This is the fifth independent cold review, the adversarial-loop cap; I am stopping rather than claiming convergence. Remaining Ref polylogue-rsad. |
…807,2780,2790,2791,2795,2802,2806,2809 uwk3, jph5 (rigor-contracts #2783), bby.17 (web-cockpit #2793), dmp (terminal-note #2801), ra3w (basetemp-fix #2807), r4no/bkff/r2kb (extension-redesign #2780) fully satisfied — closed. nhjs (#2793), peo (daemon-forensics #2802), 4g3n (#2780), 67ac/212.11 (demo-corpus #2795), rsad (mcp-ergonomics #2790, real gaps remain per 5-iteration adversarial cap), 9e5.8.4/jnj.7 (provider-origin #2806), mrxt/37t.12/p5g/rxdo.4 (annotation-judgment #2791), s7ae.8/20d.2 (live-performance-2 #2809) partially satisfied — noted with disposition, left open. Also discovered and documented the actual root cause of this session's recurring bead-revert incidents: bd reimports the live database from .beads/issues.jsonl on every CLI invocation, so a write not immediately exported is lost the moment the next bd command runs. Every mutation in this commit was individually export-verified against that behavior. Co-Authored-By: Claude <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Bounds MCP responses for agent use, makes search affordances opt-in, adds message body caps/excerpts, turns get_session_summary into a bounded orientation payload, and completes the response-envelope/pagination ergonomics with actionable query errors, distinct list rows, and zero-hit diagnostics.
Problem
Live MCP searches and message reads could return response bodies far beyond an agent context budget. Search carried the full affordance catalog on every response, session summaries contained metadata only, invalid filters gave agents no recovery set, list search could repeat a session for each matching block, and an AND-style search miss could not explain its terms.
Solution
search(include_affordances=true)the explicit opt-in for its affordance catalog.max_chars_per_messageand head/tail excerpt handling toget_messages.get_session_summary.QuerySpecErrorinto aninvalid_queryenvelope with field, tool, and valid-values metadata.list_sessionsresults into distinct session rows withmatch_count, using the existing distinct-session count and only the raw hits needed for the requested page.searchhas zero total matches; exhausted result pages remain ordinary empty pages.Verification
nix develop --command devtools test tests/unit/mcp/test_tool_contracts.py -k 'multi_term or coalesces or invalid_sort'— 3 passed.nix develop --command devtools test tests/unit/mcp/test_query_tool_schema_derivation.py tests/unit/mcp/test_tool_contracts.py -k 'supported_request_fields or stops_after_requested or exhausted_page or multi_term or coalesces or invalid_sort'— 6 passed.nix develop --command devtools test tests/unit/mcp -k 'envelope or pagination or summary'— 178 passed, 473 deselected (1:55).Acceptance status
Ref polylogue-rsad.
match_count; and zero-hit per-term diagnostics.query_unitsmust use the shared valid-values error shape and preserve replay arguments;archive_search_sessionsmust preserve replay arguments. These are documented in adversarial iteration 5; the bead remains open.Test evidence
The tests invoke registered MCP handlers against real seeded archive rows, not test-only validators:
QuerySpecErrormapper or its valid-values mapping breaks the invalid-sort test.match_countprojection breaks the repeated-block session-list test.