Repository navigation
feat(mcp): bound inline response bytes and harden input parsing - #364
Merged
Merged
Conversation
Keep default MCP responses within an 8,800-byte UTF-8 inline budget so hosts do not spill results to disk. Add optional rendered JSON byte caps to paged session message reads while preserving lossless UTF-8 byte offsets and cursors. Fit event evidence chunks directly to UTF-8 code point boundaries with an 8,800-byte default instead of dividing by six. Strip ANSI control sequences and terminal carriage-return overwrites from lossy summaries, and allocate excerpt budgets with discrete water-filling. Trim default structured file-history pages to fit 8,800 bytes and emit continuation cursors. Accept dual string, array, and object forms across MCP parameters and return explicit stop-retry guidance when nested tool serialization corrupts inputs. Update url to 2.5.9 in Cargo.lock for RUSTSEC-2026-0592. Signed-off-by: samzong <samzong.lu@gmail.com>
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.
Changes
get_session,search_messages,search_sessions,list_recent_sessions, andfile_history, while keeping CLIprotocol_version = 2output unchanged.get_sessionresponses to 8,800 UTF-8 bytes with exact JSON-escaped character accounting, losslessfirst_message_byte_offsetandnext_cursorcontinuation, and boundedinclude_eventsoutput.get_sessionevent_refmax_bytesto 8,800 and fit evidence chunks directly to UTF-8 character boundaries instead of dividing remaining bytes by six.target_projectfile_historypages to fit 8,800 UTF-8 bytes and advancenext_cursorfrom the last retained event.call_mcp_toolserialization corrupts arguments.urlfrom2.5.8to2.5.9inCargo.lockforRUSTSEC-2026-0592.Why
event_refchunk budgets by six wasted most of each response page for normal UTF-8 JSON payloads.call_mcp_toolcallers sometimes stringify numbers and booleans, expand opaque JSON cursors into objects, or collapse arrays into invalid values that previously triggered repeated identical retries.Test evidence
recall 0.7.0(./target/debug/recall) onmacOS 27.2 (Build 26B123).make checkpassed (cargo audit,cargo fmt --all -- --check, workspace Clippy with--all-targets --features bench -- -D warnings, and all workspace unit, integration, and doc tests).src/mcp/read_session.rs,src/event_evidence.rs,src/mcp/budget.rs,src/mcp/file_history.rs,src/mcp/input.rs, andsrc/db/message_store.rs. Observed all six new unit tests fail on the broken code (page 0 exceeded inline budget: 19613 bytes,first page wasted inline budget: 4156 bytes, unstripped ANSI/\r,target file_history page 0 exceeded budget: 28828 bytes, and accepted emptysource: []), then restored the implementation and observed all tests pass.\rbytes plus 18 structuredfile_writeevents and a 15 KBattrs_jsonpayload) into an isolated temporary SQLite database and queried./target/debug/recall mcp --db <temp.db>over stdio JSON-RPC 2.0:list_recent_sessions:8,799UTF-8 bytes (<= 8,800), ANSI and overwritten\rframes stripped.search_sessions(with arraysource: ["codex", "claude-code"]):8,515UTF-8 bytes (<= 8,800), 10 hits returned.search_messages:5,401UTF-8 bytes (<= 8,800), 10 hits returned, short hit preserved in full, ANSI/OSC/\rstripped.file_history(target_project, defaultlimitomitted, resumed with expanded JSON objectcursor): 4 pages of8,606,8,574,8,798, and7,417UTF-8 bytes (<= 8,800), reconstructing all 18 events in exact order17..0without drops or duplicates.get_sessionpaged mode (6,000-character Chinese message with string integer selectors and expanded JSON objectcursor): 3 pages of8,652,8,657, and4,046UTF-8 bytes (<= 8,800), reassembling all 6,000 characters byte-for-byte including raw ANSI and\r.get_sessionevent_refmode (defaultmax_bytesomitted, expanded JSON objectevent_refandcursor): 2 pages of8,800and8,770UTF-8 bytes (<= 8,800), matching the SHA-256content_digest.source: [],cursor: true,around_seq: -1): returnedisError: truewithcall_mcp_toolcorruption details andDo NOT retry the same payload unchanged.tools/calltransport andrecall mcp capabilities --format jsonschema comparison.