feat(tools): support elicitation_callback in McpToolset#6423
Draft
QuentinBisson wants to merge 1 commit into
Draft
feat(tools): support elicitation_callback in McpToolset#6423QuentinBisson wants to merge 1 commit into
QuentinBisson wants to merge 1 commit into
Conversation
Thread an optional elicitation_callback through McpToolset, MCPSessionManager, and SessionContext into the underlying ClientSession, mirroring the existing sampling_callback plumbing. Providing a callback makes the MCP client declare the elicitation capability, so servers can use elicitation/create (including URL-mode elicitation per SEP-1036) for out-of-band flows such as auth challenges instead of failing opaquely inside the toolset.
9 tasks
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.
Fixes #6422
MCPToolsetandMCPSessionManageraccept asampling_callbackbut expose no way to supply an elicitation callback, even though the MCP Python SDK'sClientSessionsupports one. Servers that use elicitation — in particular URL-mode elicitation (SEP-1036, spec revision 2025-11-25) for third-party consent / auth challenges — fail opaquely inside the toolset because the client never declares the elicitation capability and has no handler.What changed
McpToolset.__init__accepts an optionalelicitation_callback: ElicitationFnTand forwards it toMCPSessionManager.MCPSessionManager.__init__accepts the same parameter and forwards it toSessionContext.SessionContextpasses it into bothClientSession(...)construction sites (stdio and SSE/Streamable HTTP).The plumbing mirrors
sampling_callbackexactly; no behavior changes when the parameter is omitted (the SDK's default callback rejects elicitation requests and the capability is not declared, as before).Use case
Agent runtimes (kagent) fronting an MCP gateway with per-user OAuth to backends: the gateway raises a URL elicitation when the user must complete a login, and the embedding application maps it to the A2A
auth-requiredtask state (A2A spec §7.6). Go twin: google/adk-go#1165.Tests
Unit tests added in
tests/unittests/tools/mcp_tool/:test_mcp_toolset.py: callback stored and forwarded to the session manager; defaults toNone.test_mcp_session_manager.py: callback forwarded toSessionContexton session creation.test_session_context.py: callback forwarded intoClientSessionkwargs.Formatted with
isort+pyinkper pre-commit config.