Connect Pydantic AI agents to MCP servers and serve tools
Answer: Pydantic AI includes an MCP client for MCPToolset and the MCP capability, and models can also be used within MCP Servers. Install the mcp optional group, then connect to local stdio or remote Streamable HTTP and SSE servers.
Using MCP as a client
Pydantic AI includes an MCP client that can use server tools during an agent run. MCPToolset wraps the FastMCP Client. It works with local stdio servers and with remote Streamable HTTP or SSE servers. The recommended MCP capability takes a URL, or MCPToolset input via local=, and can opt into native MCP support with native=True. Reach for MCPToolset when you need to manage the client lifecycle, attach the same MCP server to multiple agents, or pass advanced transport configuration. Install pydantic-ai, or pydantic-ai-slim with the mcp optional group, for example pip install "pydantic-ai-slim[mcp]".
Serving tools from an MCP server
Pydantic AI models can also be used within MCP Servers. A simple example creates a FastMCP server, builds a server_agent, and exposes a poet tool that runs the agent and returns r.output. The server starts with server.run(). An example client uses StdioServerParameters with command python and args for the server file, then opens a ClientSession over stdio and calls the tool.
| MCPToolset | FastMCP | |---|---| | MCPToolset | wraps the FastMCP Client | | FastMCP | client and server library | | native=True | opt into native MCP support | | server.run() | starts the MCP server |
See also
Claims
- id: C1 claim: MCPToolset wraps the FastMCP Client and works with stdio and remote MCP servers. source: S1 evidence: "MCPToolset toolset wraps the FastMCP Client"
- id: C2 claim: The MCP capability is recommended for most client use cases, with an optional native=True flag. source: S1 evidence: "For most use cases, use the MCP capability"
- id: C3 claim: A Pydantic AI model can run inside an MCP server tool, for example a FastMCP poet tool. source: S2 evidence: "Pydantic AI models can also be used within MCP Servers"
Sources
- [S1] MCP client. Pydantic AI. https://ai.pydantic.dev/mcp/client/ . License: MIT. Accessed 2026-11-19.
- [S2] MCP Server. pydantic/pydantic-ai (GitHub). https://github.com/pydantic/pydantic-ai/blob/main/docs/mcp/server.md . License: MIT. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Pydantic AI, MCP client; pydantic/pydantic-ai (GitHub), MCP Server. MIT; MIT. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Pydantic AI, MCP client; pydantic/pydantic-ai (GitHub), MCP Server. MIT; MIT.
Cite this
iinventedlight. 2026. "Connect Pydantic AI agents to MCP servers and serve tools." iinventedlight Library, iil:note:w7mpnzm1, version of 2026-11-19. https://iinventedlight.com/library/notes/pydantic-ai-mcp/. License: CC-BY-4.0.
@misc{iil_note_w7mpnzm1,
author = {{iinventedlight}},
title = {{Connect Pydantic AI agents to MCP servers and serve tools}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/pydantic-ai-mcp/},
note = {Permanent ID iil:note:w7mpnzm1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- pydantic-ai-mcp.table.json (table; CC-BY-4.0)
- pydantic-ai-mcp.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pydantic-ai-mcp.md.