FastMCPToolset that lets a Pydantic AI agent call tools exposed by any MCP server through the FastMCP Client. Because the toolset is built on the FastMCP Client, it works with FastMCP servers as well as any other MCP server, and supports the full range of transports: in-memory, STDIO, Streamable HTTP, and SSE.
This page shows how to point FastMCPToolset at a FastMCP server, with examples for each transport. For the toolset’s full API, see the Pydantic AI documentation.
Install
FastMCPToolset lives in pydantic-ai-slim behind the fastmcp optional group:
Create a Server
Create a FastMCP server with the tools you want to expose. We’ll use a single dice-rolling tool throughout this guide.server.py
In-Memory
If your FastMCP server lives in the same process as your agent, pass theFastMCP instance directly. The toolset reuses an in-memory transport, which avoids a network round trip and is the fastest option for tests and embedded use.
Streamable HTTP
For a remote FastMCP server reachable over HTTP, pass the URL as a string. The toolset infers the Streamable HTTP transport from the URL./sse URL instead.
STDIO
To launch a FastMCP server as a subprocess, pass a script path and the toolset will use the STDIO transport.StdioTransport directly when you need control over the command, args, or environment.
MCP Configuration
To wire up multiple servers at once, pass an MCP configuration dictionary. The toolset opens one client per server and exposes all of their tools to the agent.Authentication
BecauseFastMCPToolset wraps a FastMCP Client, it inherits the client’s full authentication story. To pass credentials such as a bearer token to a remote server, build a Client (or StreamableHttpTransport) yourself and hand it to the toolset.
OAuth helper when constructing the Client. For server-side token verification, see Token Verification.
