Skip to content

fix(adk): preserve non-UI tool results in MCP app model result callback - #2842

Open
harrisleesh wants to merge 1 commit into
kagent-dev:mainfrom
harrisleesh:fix/adk-mcp-app-result-compaction
Open

harrisleesh wants to merge 1 commit into
kagent-dev:mainfrom
harrisleesh:fix/adk-mcp-app-result-compaction

Conversation

@harrisleesh

Copy link
Copy Markdown

Fixes #2716

What

Ports the Python fix from #2579 (compact_mcp_app_response in kagent-adk) to the Go ADK. MakeMCPAppModelResultCallback gated compaction purely on the tool name: once a tool declared _meta.ui.resourceUri at ListTools time (via agentVisibleToolFilter), every non-error result from it was collapsed into mcpAppRenderedNotice — even a call that returned plain text with no _meta.ui and no structuredContent, 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: export HasUIResource(meta) on top of the existing parseMCPUIMetadata, so the per-result check accepts the same two meta shapes (_meta.ui.resourceUri and 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: in compactMCPAppModelResponse, after the existing IsError branch, 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 with structuredContent but no UI resource also passes through untouched.

Error handling is unchanged (content preserved, structuredContent dropped), and results that do carry a UI resource are still collapsed into the terminal notice with _meta preserved.

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, no structuredContent; text must reach the model unchanged (failed before the fix with the canned notice).
  • TestMakeMCPAppModelResultCallbackPassesThroughDataOnlyResultFromAppToolstructuredContent present but empty _meta; passes through untouched (mirrors test_compact_skips_data_only_result_from_a_ui_capable_tool).
  • TestMakeMCPAppModelResultCallbackCompactsFlatUIResourceMetaShape — flat _meta["ui/resourceUri"] still triggers compaction.
  • TestHasUIResourceAcceptsNestedAndFlatMetaShapes / TestHasUIResourceRejectsResultsWithoutUIResource in pkg/mcp (mirrors test_result_has_ui_resource_accepts_nested_and_flat_meta_shapes).

Verified locally from go/:

go build ./adk/...
go vet ./adk/...
go test ./adk/...   # all packages ok

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 HasUIResource approach but drops that PR's extra structuredContent == nil condition so the gate matches the merged Python semantics exactly.

🤖 Generated with Claude Code

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]>
@github-actions github-actions Bot added the bug Something isn't working label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go/adk: MakeMCPAppModelResultCallback blanks non-UI tool results, same gap #2579 fixed in Python

1 participant