feat(mcp): add sampling callback support for MCP sessions#4718
Open
Piyushmrya wants to merge 2 commits intogoogle:mainfrom
Open
feat(mcp): add sampling callback support for MCP sessions#4718Piyushmrya wants to merge 2 commits intogoogle:mainfrom
Piyushmrya wants to merge 2 commits intogoogle:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem
ADK’s MCP integration currently does not expose the MCP sampling callback capability.
This prevents agent-side LLM sampling handlers from being used when interacting with MCP servers that support sampling.
The MCP Python SDK supports sampling callbacks, but these parameters are not propagated through the ADK MCP integration layers.
Solution
Add sampling callback support by propagating the parameters through the MCP stack:
sampling_callbackandsampling_capabilitiesparameters toMcpToolsetMCPSessionManagerSessionContextClientSessioninitializationThis enables agent-side sampling handling when interacting with MCP servers.
Testing Plan
Unit Tests
Added
test_mcp_sampling_callback.pyto verify that the sampling callback is correctly invoked.Example result:
pytest tests/unittests/tools/mcp_tool/test_mcp_sampling_callback.py
1 passed
Manual End-to-End (E2E) Tests
Manual testing was performed using a FastMCP sampling example server where the sampling callback was invoked from the agent side and returned the expected response.
Checklist
Additional context
This change aligns ADK MCP support with the sampling capabilities available in the MCP Python SDK and enables agent implementations to handle sampling requests via a callback.