Creativity · MCP — integration

MCP + Pydantic AI Integration

Pydantic AI focuses on type safety and testability for Python agent developers. In 2026 it supports MCP as a tool source: point an Agent at one or more MCP servers and Pydantic AI generates typed stubs from each tool's JSON Schema, validates arguments with Pydantic models, and gives you mockable, snapshot-tested agents.

MCP facts

Kind
integration
Ecosystem
anthropic-mcp
Language
Python
Transports
stdio, http

Capabilities

  • Register MCP servers as MCPServer instances passed to an Agent
  • Auto-generate typed Pydantic argument models from tool schemas
  • pytest + VCR-style cassettes for deterministic tests
  • Multi-model: Claude, OpenAI, Gemini, Mistral, local Ollama

Install

pip install pydantic-ai[mcp]

Configuration

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStdio

fs = MCPServerStdio(
    command="npx",
    args=["-y", "@modelcontextprotocol/server-filesystem", "./repo"],
)
agent = Agent("anthropic:claude-opus-4-7", mcp_servers=[fs])

result = agent.run_sync("Find TODOs in the repo and group them by file.")

Frequently asked questions

Why use Pydantic AI over the raw Anthropic SDK?

For larger codebases, Pydantic AI adds structured outputs, typed tools, and first-class testing. If you just need a single chat loop, the Anthropic SDK is simpler.

Does it work with async frameworks?

Yes — Pydantic AI is async-first. Its MCP transports expose both stdio and HTTP/SSE connections compatible with FastAPI or asyncio apps.

How does testing work?

Pydantic AI ships a TestModel that replays recorded tool calls. Combined with MCP mocks, you can write deterministic unit tests for agent behaviour.

Sources

  1. Pydantic AI documentation — accessed 2026-04-20
  2. Pydantic AI GitHub — accessed 2026-04-20
  3. Model Context Protocol — accessed 2026-04-20