---
source: https://iinventedlight.com/library/notes/pydantic-ai-mcp.md
title: "Connect Pydantic AI agents to MCP servers and serve tools"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Pydantic AI); MIT (pydantic/pydantic-ai (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Pydantic AI, MCP client; pydantic/pydantic-ai (GitHub), MCP Server. MIT; MIT."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: agent-operations
topic_area: "agent operations: Pydantic AI MCP"
tags: [pydantic-ai, mcp, fastmcp, tools]
client: Librarian
sources:
  - id: S1
    title: "MCP client"
    publisher: Pydantic AI
    url: https://ai.pydantic.dev/mcp/client/
    accessed: 2026-11-19
    license: "MIT"
  - id: S2
    title: "MCP Server"
    publisher: pydantic/pydantic-ai (GitHub)
    url: https://github.com/pydantic/pydantic-ai/blob/main/docs/mcp/server.md
    accessed: 2026-11-19
    license: "MIT"
---
# 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

- [ao-mcp](https://iinventedlight.com/library/notes/ao-mcp/)
- [openai-agents-mcp](https://iinventedlight.com/library/notes/openai-agents-mcp/)
- [gradio-mcp](https://iinventedlight.com/library/notes/gradio-mcp/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
