Skip to main content
Guide2 min read

Pydantic AI MCP server: connect an agent to MCP (2026)

Pydantic AI's V2 redesign landed in June 2026 with one of the cleanest MCP clients in the ecosystem. How to attach a server with MCPToolset, manage connections, and why validation makes it a natural fit.

Pydantic AI's V2 redesign landed in June 2026, and its MCP support is one of the cleanest in the ecosystem. A Pydantic AI agent acts as an MCP client: you attach a toolset, and every tool the server exposes becomes callable in an agent run — type-checked, structured, and validated the way Pydantic does everything. Here's the minimal setup and the gotchas worth knowing.

Install

The MCP client lives behind an optional group. Install the slim package with the extra so you don't pull in providers you don't need:

pip install "pydantic-ai-slim[mcp]"

Attach a server with MCPToolset

MCPToolset wraps a FastMCP client and speaks both local stdio and remote Streamable HTTP. For a hosted server, pass the URL; for a local one, point it at a script:

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset

toolset = MCPToolset('http://localhost:8000/mcp')
agent = Agent('anthropic:claude-opus-4-8', toolsets=[toolset])

async with agent:
    result = await agent.run('Summarise the latest open issues')

Manage connections

Open and close every registered server with the async with agent context manager. For stdio servers that also starts and stops the subprocess, so you never leak a dangling process into your test suite or a long-running service. Keep the agent inside that block for the whole run rather than opening a connection per call.

Why it fits Pydantic AI

The draw is validation. MCP tool arguments and results flow through Pydantic models, so a malformed tool call fails loudly at the boundary instead of corrupting state deeper in the run. That makes MCP a natural fit for the framework's whole promise: agents you can actually trust in production, where a bad payload is caught before it does damage rather than after.

Which servers to start with

Point a data agent at Postgres or Supabase; a research agent at Tavily or Exa. Anything in the directory works, because MCPToolset speaks standard MCP — curated, categorised and vetted.

Going further

New to building servers? Start with the Python MCP tutorial and transports compared. Compare frameworks in FastMCP vs the official SDK, and secure remote endpoints with the OAuth 2.1 guide. Browse the ML engineer loadout for a full stack.

Loadout

Build your AI agent loadout

The directory of MCP servers and AI agents that actually work. Pick the right loadout for Slack, Postgres, GitHub, Figma and 20+ integrations — with install commands ready to paste into Claude Desktop, Cursor or your own stack.

© 2026 Loadout. Built on Angular 21 SSR.