Repository navigation
feat(mcp): name the next operation when a completed result overflows the response budget - #11015
Merged
Merged
Conversation
…the response budget
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
[Medium impact] The reviewed changes appear safe to merge. SummaryThe PR adds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Completed result"] --> B{"Fits response budget?"}
B -->|Yes| C["Return complete result"]
B -->|No| D["Choose recovery text and optional operation"]
D --> E{"MCP recovery available?"}
E -->|Yes| F["Return resource_constraint with next_operation"]
E -->|No| G["Return CLI guidance without next_operation"]
Reviews (2) · Last reviewed commit: "test(mcp): assert next_operation for eve..." · Reviewed by Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #10508 (Phase 6.1). When a completed MCP result does not fit the response budget,
ToolResultDeliverypicks a recovery sentence: export the bundle, page again with a smaller limit, follow a view continuation, or use CLI JSON. That choice existed only as prose. It is now alsodetails.reported_limits.next_operation, naming the MCP operation the recovery starts with. A one-rowlist_unknownspage no longer suggests a smaller limit, since one row cannot be split.Problem and expected behavior
serverUnknownsMcp.test.tscould check the route only by matching text:not.toContain("or page list_unknowns")for a committed-unknown receipt, and "same connection" / "smaller limit" / not "CLI JSON" for an overflowing list. test(mcp): assert snapshot-import and unknown-receipt facts instead of guidance prose #11004 left these as prose because no field existed.list_unknownscall withlimit: 1whose single head exceeds the budget got "use a smaller limit, then follow next_offset". That retry cannot succeed; only export recovers the head.export_evidence_bundlevslist_unknownsvsinspect_analysis_viewvsget_evidence_bundle, and no field when the only recovery is CLI JSON.Change and scope
src/server/ToolResultDelivery.ts: the nested ternary that chosenextStepbecomesoverflowNextStep(), which returns{ text, operation? }. Texts are unchanged except the new one-row branch.operationis added to the reported limits asnext_operation:evidence_reference, bundle summary:export_evidence_bundleinspect_analysis_viewlist_unknownswith more than one row:list_unknowns; with zero or one row:export_evidence_bundle(new text)get_evidence_bundleprojections andinspect_address_context:get_evidence_bundleserverUnknownsMcp.test.ts: the receipt helper, the one-row page and the overflowing list assertnext_operation; the four prose fragments are removed.docs/reference/mcp-contracts.md: documents the field next to the list-overflow recovery.Not included: the forwarded-content overflow (
toForwardedToolResult, a screenshot too large) keeps prose only; its recovery is "ask for a smaller image", not a different operation.reported_limitsis a free-form record in the error schema, so no catalog change.Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
ToolResultDelivery.successResultoverflow recovery (producer); consumers: every MCP tool whose completed result can overflowdetails.reported_limits.next_operationon transportresource_constraint; no schema or catalog change (reported_limitsis free-form)docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): noneExpected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
serverUnknownsMcp.test.tsbefore and after (assertions changed).toolResult.test.tsgoes from 18 to 24: a table drivesToolResultDeliverythrough every other branch (CLI fallback has no field; retained Evidence, view continuation, address context, bundle summary and record selection each name their operation).next_operationspread, 2 of 8 fail ("returns exact committed unknown receipts when creation and update replies overflow", "recovers an oversized list with same-session paging or export"). Before the one-row branch existed, the one-row page assertion failed withnext_operation: "list_unknowns", which is how the misleading recovery was found.toolResult.test.ts(18),contextEvidenceOverflow.test.ts(5),evidenceRecordSelectionMcp.test.ts(6),largeToolResult.test.ts(8) all pass.contextEvidenceOverflow7.4 s andevidenceRecordSelectionMcp6.7 s dominate, unchanged here).serverUnknownsMcp.test.tsalone: vitest 14.2 s, mostly transform.details.reported_limits.next_operation; a one-rowlist_unknownsoverflow gets an export-only remediation.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
For evidence-bearing changes:
Validation performed
npm run test:focused -- tests/boundary/mcp/serverUnknownsMcp.test.ts tests/boundary/mcp/toolResult.test.ts tests/boundary/mcp/contextEvidenceOverflow.test.ts tests/boundary/mcp/evidenceRecordSelectionMcp.test.ts tests/boundary/mcp/largeToolResult.test.ts: 45 passed after the one-row fix (first run: 1 failure, which led to that fix)npm run test:focused -- tests/boundary/mcp/serverUnknownsMcp.test.tswithnext_operationremoved: 2 failed (expected)npm run test:focused -- tests/boundary/mcp/toolResult.test.tsafter adding the route table: 24 passednpm run check:fast: passednpm run docs:check: passedCompatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.