← All notes

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

Sources

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

Permanent ID: iil:note:w7mpnzm1

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.},
}

Markdown

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.

All artifact files (JSON index)

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.