Repository navigation
fix(mcp-scan): preserve complete MCP tool results - #727
Merged
Merged
Conversation
boy-hack
approved these changes
Oct 28, 2026
boy-hack
left a comment
Collaborator
There was a problem hiding this comment.
Verified locally on top of latest main (33768c5):
- The fix correctly addresses the truncation reported in #726:
content[0]slicing is replaced by full-result serialization that preserves all content blocks,structuredContent,isError, result_meta, and per-blockannotations/meta. - Good backward-compat touch: the single-block/no-metadata fast path keeps the historical plain
strreturn, so existing consumers see no behavioral change for simple results. - Sensible ordering (status → text → structuredContent → result meta → metadata → media) keeps readable text ahead of opaque media blobs in the agent's bounded preview.
- Tests: new coverage passes locally (multi-block, is_error, structuredContent, result meta, input-required/unsupported types). Full-suite failure set is identical to the main baseline (9 pre-existing environmental failures in test_dispatcher / test_protocol_negotiation / test_surrogate_sanitization, unrelated to this change).
- CI green after re-running the stuck fork workflow.
Thanks for the high-quality fix and the detailed issue report!
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
I fixed dynamic MCP tool-result handling so the agent no longer loses later content blocks or structured results. I preserve the legacy single-text and single-media return shapes when no extra metadata is present, and include
structured_content(including explicit JSON null),is_error, top-levelmeta, and text-block annotations/metadata when they are present. For multi-block results, I place readable text before structured data, metadata, and opaque media, while labeling each original content index to make the display-order change explicit. This prevents earlier opaque media from hiding later evidence that fits within the existing history preview; the preview's length cap still applies to unusually long text.Scope note
InputRequiredResultis a separate interactive SDK result, not aCallToolResultcontent variant. This PR does not enableallow_input_required=True; the SDK default continues to reject that response because the dynamic scanner has no elicitation-response flow.Type of change
data/fingerprints/)data/vuln/)data/mcp/)data/eval/)How was this tested?
cd mcp-scan && .venv/bin/python -m pytest -q pytests/test_mcp_sdk_v2.py— 13 passed. Covers singleton compatibility, multiple text/media/resource blocks,structured_contentincluding explicit null,is_error, result/block metadata, empty-success behavior, explicit rejection ofInputRequiredResult, and late evidence throughToolDispatcher._format_resultintoBaseAgent._build_history_tool_result.cd mcp-scan && .venv/bin/python -m pytest -q pytests/ --ignore=pytests/test_surrogate_sanitization.py— 59 passed.pytests/test_surrogate_sanitization.py(lines 84 and 102). I reran that file on cleanorigin/main; the same two tests fail before scanner code runs becauseos.path.join()combines a string temp directory with a bytes filename (TypeError: Can't mix strings and bytes in path components).go build ./...— passed.ruff checkandruff format --checkon the changed Python files — passed;git diff --check— clean.cd mcp-scan && PYTHONPATH=$PWD .venv/bin/python main.py --help— passed.Related issue
Fixes #726
Checklist
go build ./...succeeds locally