[Bug]: read_cache cannot rebuild a cut response when its record array is not where the data is
What happened?
When a tool response is over tool_response_limit, the truncator picks one array as the record
list (analyzeJSONStructure → findArraysRecursive → chooseBestArray in
internal/truncate/truncator.go), and read_cache pages only that array. When the data is not in
that array, the part of the response past the cut cannot be read back at all.
Three shapes hit this:
- The data sits in one-element arrays beside a short list.
chooseBestArrayprefers more elements, so a five-string metadata array wins over the one-element arrays that hold the payload. - A record larger than the limit. The record array is right, but a
read_cachepage holding that single record is over the limit, so the recursion guard inmaybeTruncateAndCacheTextPinned(paginableUnits <= 1) cuts it plainly. - Valid JSON with no array, for example one long string field: no handle at all ("cache not available").
A DataForSEO ai_optimization_llm_response result has the first shape: an answer of about 21,000 characters
could not be rebuilt.
Related: #2027. The per-profile limit (#2029) lets a script opt out of the limit, but a client in an ordinary session still loses the tail.
Expected behavior
read_cache can return the whole response, so that joining its pages gives back the original text.
Steps to reproduce
Synthetic reproduction. With tool_response_limit: 20000, a tool returns about 25,000 characters
shaped like this:
{"status_code": 20000,
"tasks": [{"id": "t-1",
"path": ["v3", "a", "b", "c", "live"],
"data": {"prompt": "..."},
"result": [{"items": [{"type": "message",
"sections": [{"type": "text",
"text": "<about 15,000 characters>",
"annotations": [{"title": "...", "url": "https://example.com/1"}]}]}],
"search_results": [{"title": "...", "url": "https://example.com/r1", "snippet": "<about 3,000 characters>"}]}]}]}
- Call the tool. The banner says
records: 5. - Call
read_cachewith the key. It returns["v3","a","b","c","live"]withrecord_path: "tasks[0].path". - The answer text past the cut and the later citations are never returned.
MCPProxy version
main at 40e7df7db
Operating system
macOS
Relevant logs
No response
Proposed fix
When the inferred array cannot rebuild the response (the content outside it is larger than the
preview, or one of its records cannot fit in a read_cache page), or valid JSON has no array, store
the response in text-chunk mode: read_cache returns the full text as consecutive chunks
(record_path: "(text)") that join to the exact original. Pinned record paths, record lists that
work today and non-JSON text keep their current behaviour. A PR with tests follows.
Pre-submission checklist
- [x] I searched existing issues and did not find a duplicate
- [ ] I ran
mcpproxy doctorand reviewed the output
Fixed by #2143 (merged): read_cache now returns a response without a usable record list as text chunks that join to the exact original. Remaining narrow follow-ups are tracked in #2145.