Skip to main content
Pydantic AI’s 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

The 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

Pass MCPToolset anything the FastMCP Client accepts. It infers the transport the same way the client does.
Pass a FastMCP transport such as StdioTransport for control over the command, arguments, or environment, or a configured fastmcp.Client for full control.

Authentication

For a bearer token, pass headers. For OAuth, pass auth="oauth" or build the Client yourself.
For server-side token verification, see Token Verification.

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 an elicitation_handler to answer a server’s elicitation requests. It has the same signature as the FastMCP Client’s elicitation handler.
On 2026-07-28 connections, Pydantic AI may warn that elicitation_handler will never be called. The FastMCP Client still calls it for input-required results.