feat(mcp): propagate grounding metadata from MCP _meta - #7047
Open
claxman wants to merge 1 commit into
Open
Conversation
_maybe_add_grounding_metadata returned early unless a tool was named google_search_agent. git log -S shows d689a04 (Xuan Yang) replaced that with getattr(tool, 'propagate_grounding_metadata', False), and b2daf83 (Haiyuan Cao) put the name check back. I ran _handle_after_model_callback with dummy_tool and temp:_adk_grounding_metadata={'foo': 'bar'}: result was None. Restore the d689a04 gate and the canonical_tools_cache read. Add propagate_grounding_metadata on McpTool and McpToolset so _meta.adk_grounding_metadata can populate the same temp key. Verification: 15 passed. upstream/main src: cache test AttributeError on None grounding_metadata; MCP flag-on test TypeError on the new kwarg. Fixes google#6081
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
_maybe_add_grounding_metadatareturns early unless a tool is namedgoogle_search_agent. I ran_handle_after_model_callbackwith a dummy tool andtemp:_adk_grounding_metadata={'foo': 'bar'}set: the callback returnedNoneandLlmResponse.grounding_metadatastayed unset.git log -S propagate_grounding_metadata -- src/google/adk/flows/llm_flows/base_llm_flow.pyshowsd689a04freplaced the name check withgetattr(tool, 'propagate_grounding_metadata', False), andb2daf83dput the name check back.McpTool._run_async_impldumpsCallToolResultand never writes the temp key.Solution:
Restore the
d689a04fgate: attach when some canonical tool haspropagate_grounding_metadataand the temp key is set. Keep thecanonical_tools_cacheread. Addpropagate_grounding_metadata: bool = FalseonMcpToolandMcpToolset. When True, validateadk_grounding_metadatafrom dumpedmeta/_metaasGroundingMetadataand write the temp key. The tool return dict is unchanged. AValidationErroris logged and skipped.Testing Plan
Unit Tests:
15 passed.
The cache test uses a tool named
research_agentwithpropagate_grounding_metadata=True. With the three src files checked out fromupstream/main, that test fails withAttributeError: 'NoneType' object has no attribute 'grounding_metadata', and the MCP flag-on test raisesTypeError: McpTool.__init__() got an unexpected keyword argument 'propagate_grounding_metadata'.Manual End-to-End (E2E) Tests:
Not run. No live MCP server or Gemini Enterprise UI on this machine.
Additional context
Claim: #6081 (comment)
Checklist