MCPToolset is built on the FastMCP Client, so an agent can use any MCP server over any FastMCP transport. It covers tools, resources, prompts, and elicitation. This page shows how to point it at a FastMCP server; for the full API, see the Pydantic AI docs.
Install
mcp extra installs the client-only fastmcp-slim[client]. Add fastmcp if the same environment also runs a FastMCP server.
With FastMCP 4, use
pydantic-ai-slim 2.45 or newer. Releases 2.32 through 2.44 import httpx without depending on it, and FastMCP 4 no longer installs httpx, so import pydantic_ai.mcp fails.Create a Server
server.py
Connect an Agent
PassMCPToolset anything the FastMCP Client accepts. It infers the transport the same way the client does.
StdioTransport for control over the command, arguments, or environment, or a configured fastmcp.Client for full control.
Authentication
For a bearer token, passheaders. For OAuth, pass auth="oauth" or build the Client yourself.
Multiple Servers
load_mcp_toolsets reads an MCP configuration file and returns one toolset per server. Tool names are prefixed with the server’s key.
mcp_config.json
Elicitation
Pass anelicitation_handler to answer a server’s elicitation requests. It has the same signature as the FastMCP Client’s elicitation handler.
elicitation_handler will never be called. The FastMCP Client still calls it for input-required results.
