fix(kagent-adk): compact MCP App tool results only when the result carries a UI resource - #2579
fix(kagent-adk): compact MCP App tool results only when the result carries a UI resource#2579AmirF194 wants to merge 4 commits into
Conversation
…rries a UI resource compact_mcp_app_response collapsed every result from a UI-capable tool into a terminal notice, classifying purely from the tool's definition (_meta.ui.resourceUri at ListTools time) rather than the specific call result. A tool that sometimes returns plain data and sometimes renders UI (e.g. an Atlassian search tool with a UI mode) had every result blanked for headless agents (A2A, kagent invoke), even ones with no UI resource at all. Add _result_has_ui_resource, mirroring the existing _meta.ui.resourceUri / _meta["ui/resourceUri"] parsing kagent already uses to classify a tool definition (go/adk/pkg/mcp/mcp_ui.go), applied to the result instead. compact_mcp_app_response now passes a result through unchanged unless it itself declares a UI resource. Scoped to the Python ADK runtime per the issue; go/adk/pkg/agent/mcp_apps.go has the identical gap and is left as a follow-up. Fixes kagent-dev#2519 Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
|
Looks good. The change correctly moves the compaction decision from tool-level UI capability to the individual CallToolResult, which fixes the data-loss case without changing the existing error path. Non-blocking: I’d add a direct positive test for _meta["ui/resourceUri"] as well as _meta.ui.resourceUri, since _result_has_ui_resource() intentionally supports both representations. We should also track the equivalent Go ADK change separately so Python and Go don’t retain different MCP App semantics. |
dimetron's review: the existing tests only exercise compact_mcp_app_response end to end with the nested _meta.ui.resourceUri shape, never the flat _meta["ui/resourceUri"] one the function also parses. Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
…mpact-result-only
|
Added a direct test for both _meta shapes on _result_has_ui_resource, 7/7 pass in a clean container. Left the Go ADK side out of this PR, one concern at a time, but agreed it's worth its own tracking. Synced onto main to clear the BEHIND state, no conflicts. |
Root cause
compact_mcp_app_response(python/packages/kagent-adk/src/kagent/adk/_mcp_apps.py)collapses a tool's result into a terminal notice whenever the tool's name is in
app_tool_names, a set populated once from the tool's_meta.ui.resourceUriatListToolstime. A single tool can carry a UI mode without every call rendering it(the issue's example: an Atlassian search tool with a UI widget), so any plain,
data-only result from such a tool was silently replaced with the notice text for a
headless caller (A2A,
kagent invoke), with no error.Fix
Added
_result_has_ui_resource, which checks the result's own_meta.ui.resourceUri/
_meta["ui/resourceUri"], the same fieldsgo/adk/pkg/mcp/mcp_ui.goalready parsesto classify a tool's definition, applied here to the per-call result instead.
compact_mcp_app_responsenow passes a result through unchanged unless it declares aUI resource itself.
Scoped to the Python ADK runtime per the issue;
go/adk/pkg/agent/mcp_apps.gohas theidentical gap and is left as a follow-up, since it is outside this change's surface.
Verification
(empty
_meta, and no_metakey at all) now passes through unmodified. Both failon
main(asserting the old collapse) and pass on this branch; confirmed independentlyin a clean container against an unmodified worktree of
mainbefore rebuilding on thebranch.
kagent-adkunit suite (uv run pytest packages/kagent-adk/tests/unittests/):402 passed on Python 3.11 and 3.13, both CI matrix extremes.
ruff checkandruff format --diffon the two changed files: clean.block rather than
_meta(no such server available to test against); the existingand new tests all key on
_meta, matching the only shape this repo's own tests andmcp_ui.gocurrently recognize.Fixes #2519