fix(adk): preserve non-UI tool results in MCP app model result callback - #2842
Open
harrisleesh wants to merge 1 commit into
Open
harrisleesh wants to merge 1 commit into
harrisleesh wants to merge 1 commit into
Conversation
MakeMCPAppModelResultCallback gated compaction purely on the tool name: once a tool declared _meta.ui.resourceUri at ListTools time, every non-error result from it was collapsed into the canned render notice, even calls that returned plain text with no UI resource and nothing to compact. That hid real content from the model. Port the Python fix from kagent-dev#2579 to the Go ADK: only compact when the result itself carries a UI resource (_meta.ui.resourceUri, or the flat _meta["ui/resourceUri"] form parseMCPUIMetadata already accepts); otherwise pass the result through unchanged. Error results keep their existing handling (content preserved, structuredContent dropped). Exports mcp.HasUIResource so the check reuses the same _meta.ui parsing used to classify tools, keeping Go and Python MCP App semantics aligned. Fixes kagent-dev#2716 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: seonghun lee <[email protected]>
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.
Fixes #2716
What
Ports the Python fix from #2579 (
compact_mcp_app_responseinkagent-adk) to the Go ADK.MakeMCPAppModelResultCallbackgated compaction purely on the tool name: once a tool declared_meta.ui.resourceUriatListToolstime (viaagentVisibleToolFilter), every non-error result from it was collapsed intomcpAppRenderedNotice— even a call that returned plain text with no_meta.uiand nostructuredContent, hiding real content from the model.How
Same shape as the merged Python fix: check whether this specific result carries a UI resource before compacting, not just whether the tool is UI-capable by definition.
go/adk/pkg/mcp/mcp_ui.go: exportHasUIResource(meta)on top of the existingparseMCPUIMetadata, so the per-result check accepts the same two meta shapes (_meta.ui.resourceUriand the flat_meta["ui/resourceUri"]) used to classify tools — keeping Go and Python MCP App semantics from drifting.go/adk/pkg/agent/mcp_apps.go: incompactMCPAppModelResponse, after the existingIsErrorbranch, return the response unchanged when!mcp.HasUIResource(result.Meta). The gate is the result's UI resource only (matching fix(kagent-adk): compact MCP App tool results only when the result carries a UI resource #2579's merged semantics): a data-only result withstructuredContentbut no UI resource also passes through untouched.Error handling is unchanged (content preserved,
structuredContentdropped), and results that do carry a UI resource are still collapsed into the terminal notice with_metapreserved.Tests
Ported the #2579 test cases to Go, plus the repro from the issue:
TestMakeMCPAppModelResultCallbackPassesThroughPlainResultFromAppTool— the issue's repro: app-declared tool returning only text content ("No build found for job demo/1..."), no_meta, nostructuredContent; text must reach the model unchanged (failed before the fix with the canned notice).TestMakeMCPAppModelResultCallbackPassesThroughDataOnlyResultFromAppTool—structuredContentpresent but empty_meta; passes through untouched (mirrorstest_compact_skips_data_only_result_from_a_ui_capable_tool).TestMakeMCPAppModelResultCallbackCompactsFlatUIResourceMetaShape— flat_meta["ui/resourceUri"]still triggers compaction.TestHasUIResourceAcceptsNestedAndFlatMetaShapes/TestHasUIResourceRejectsResultsWithoutUIResourceinpkg/mcp(mirrorstest_result_has_ui_resource_accepts_nested_and_flat_meta_shapes).Verified locally from
go/:Existing callback tests (notice on render payload, isError preservation, non-app tool pass-through) all still pass. Also confirmed the new pass-through tests fail against unpatched
mcp_apps.go.Note: #2793 attempted this earlier and was closed unmerged by its author; this PR uses the same
HasUIResourceapproach but drops that PR's extrastructuredContent == nilcondition so the gate matches the merged Python semantics exactly.🤖 Generated with Claude Code