Skip to main content
Pass an MCP connection through Agent(mcp_servers=[...]). Pydantic AI provides the client integration.

Pydantic AI 2.x

Use MCPToolset for an HTTP MCP server:
The server must already be running. To connect a subprocess, pass a FastMCP StdioTransport to MCPToolset; see Pydantic AI’s MCP client documentation.

In-process FastMCP

Install the optional server package:

Pydantic AI 1.x

Existing MCPServerStdio and HTTP server instances remain supported when using Pydantic AI 1.x. Those classes were replaced by MCPToolset in 2.x; use the API that matches your installed Pydantic AI version. A Thread context keeps managed server connections available across calls and closes them on exit. See threads.