Repository navigation
fix(mcp): keep the model's thoughts out of to_mcp_server results - #7835
Closed
adityasingh2400 wants to merge 1 commit into
Closed
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
_part_to_content turned every part with text into a TextContent block, thought parts included, and progress messages joined all part text. An agent exposed with to_mcp_server therefore sent its hidden reasoning to MCP clients. Skip thought parts in both places, as AgentTool already does. Fixes google#7834
Collaborator
|
Thank you @adityasingh2400 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 9688feb. Closing this PR as the changes are now in the main branch. |
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:
_part_to_contentturned every part with text into aTextContentblock,thought=Trueparts included, and the progress messages joined all part text. An agent exposed withto_mcp_servertherefore sent the model's hidden reasoning to MCP clients, both in the tool result and inreport_progressmessages.Solution:
_part_to_contentreturnsNonefor thought parts, like other parts with nothing to render (e.g. function calls).AgentToolalready does the same when it builds its result. Non-thought text, images, audio and blobs are mapped exactly as before.Testing Plan
Unit Tests:
Added to
tests/unittests/tools/mcp_tool/test_agent_to_mcp.py:test_run_agent_leaves_thoughts_out_of_the_result: a final event with a thought part and an answer returns only the answer.test_run_agent_leaves_thoughts_out_of_progress: a thought-only partial event reports nothing, and a mixed one reports only its visible text.pre-commit runpasses on the changed files, andmypyreports no issues in_agent_to_mcp.py.Manual End-to-End (E2E) Tests:
I exposed an agent that answers like a thinking model, with a thought part and then the answer, via
to_mcp_server. I called it from an MCPClientSessionconnected over in-memory streams (theconnected_client_sessionhelper from this test package):Checklist
Additional context
None.