Replace deprecated pydantic-ai MCP classes with MCPToolset in common.ai#69006
Merged
Conversation
…common.ai pydantic-ai deprecated MCPServerStdio, MCPServerSSE, and MCPServerStreamableHTTP in favor of a unified MCPToolset (all three are removed in pydantic-ai v2). The common.ai MCPHook constructed all three, so it emitted DeprecationWarnings and would break on the v2 upgrade. Build an MCPToolset over the matching FastMCP transport instead: - http -> MCPToolset(StreamableHttpTransport(host, headers=...)) - sse -> MCPToolset(SSETransport(host, headers=...)) - stdio -> MCPToolset(StdioTransport(command=..., args=...), init_timeout=...) Transports are built explicitly rather than relying on FastMCP's URL inference, so the connection's explicit 'transport' field is honored (inference only picks SSE for URLs ending in /sse) and the Authorization header is preserved. MCPToolset has no tool_prefix argument, so the prefix is applied via .prefixed(), matching pydantic-ai's own load_mcp_toolsets and producing the same '<prefix>_<tool>' names as before.
pydantic-ai MCP classes with MCPToolset in common.ai
shahar1
approved these changes
Jun 27, 2026
gopidesupavan
approved these changes
Jun 27, 2026
gopidesupavan
left a comment
Member
There was a problem hiding this comment.
LGTM thanks kaxil :)
not a blocker can we do autospec for tests ?
@patch(_MCP_TOOLSET, autospec=True)
@patch(_HTTP_TRANSPORT, autospec=True)
Member
Author
|
Thanks @gopidesupavan! Good call -- done in 42c8b27. All the |
karenbraganz
pushed a commit
to karenbraganz/airflow
that referenced
this pull request
Jun 30, 2026
75 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.
pydantic-ai deprecated
MCPServerStdio,MCPServerSSE, andMCPServerStreamableHTTPin favor of a unifiedMCPToolset, and removes all three in pydantic-ai v2. The common.aiMCPHookconstructed all three directly, so it emitsDeprecationWarnings today and would break on the v2 upgrade.This migrates
MCPHook.get_conn()to build anMCPToolsetover the matching FastMCP transport.What changed
httpMCPServerStreamableHTTP(host, headers=…, tool_prefix=…)MCPToolset(StreamableHttpTransport(host, headers=…))sseMCPServerSSE(host, headers=…, tool_prefix=…)MCPToolset(SSETransport(host, headers=…))stdioMCPServerStdio(cmd, args=…, timeout=…, tool_prefix=…)MCPToolset(StdioTransport(command=cmd, args=…), init_timeout=…)tool_prefix=constructor arg.prefixed(prefix)Design rationale
MCPToolsetcan infer a transport from a bare URL, but FastMCP only picks SSE when the URL ends in/sse. The connection has an explicittransportfield, so the hook builds the transport explicitly to honor that choice regardless of URL shape, and to keep attaching theAuthorizationheader.StdioTransportfor stdio. The connection supplies an arbitrarycommand+args, which is the case pydantic-ai's deprecation message prescribesStdioTransport(...)for; theMCPToolset("script.py")shorthand only covers literal script paths..prefixed()fortool_prefix.MCPToolsethas notool_prefixargument..prefixed(prefix)produces the same<prefix>_<tool>names as before and matches pydantic-ai's ownload_mcp_toolsets. It returns aPrefixedToolsetthat proxies the async-context-manager protocol, so the connection-backedMCPToolsetwrapper keeps working unchanged.init_timeoutis the successor to the old stdiotimeout; the hook keeps its default of 10s.Tradeoffs / notes
fastmcp.client.transportsis the canonical public import path.pydantic_ai.mcpimports from it, and pydantic-ai's own deprecation message recommendsMCPToolset(fastmcp.client.transports.StdioTransport(...)).Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.