published fresh until

PydanticAI: connect a managed MCP toolset

Summary As of November 2026, register MCPToolset through Agent(toolsets=[toolset]); use async with agent to keep connections open across runs. Streamable HTTP requires an already running server; stdio subprocesses are managed. Install the slim extra with pip install "pydantic-ai-slim[mcp]".

Not for PydanticAI provider-native MCP execution through the MCP capability.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: install pydantic-ai or pip install "pydantic-ai-slim[mcp]", then register MCPToolset in toolsets.

Short answer

MCPToolset wraps the FastMCP client. An agent context opens and closes registered toolsets; a toolset context can share a connection across agents.

What to do

Inside an async function, with the HTTP server already listening:

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset
agent = Agent('openai:gpt-6.1-sol', toolsets=[MCPToolset('http://localhost:8000/mcp')])
async with agent:
    result = await agent.run('What is 7 plus 5?')
Input / settingAction
URL stringStreamable HTTP recommended; example http://localhost:8000/mcp
URL ending /sseSSE auto-detected; deprecated transport; other SSE paths require SSETransport
Python / Node.js script pathRuns through stdio
Explicit transportStdioTransport, StreamableHttpTransport, or SSETransport
Local command exampleStdioTransport(command='python', args=['mcp_server.py']) from fastmcp.client.transports
Prebuilt client / serverAccepts fastmcp.Client or an in-process FastMCP server
async with agentManages all registered toolsets and stdio subprocess lifetime
async with toolsetManages a particular toolset; reusable across agents
Neither contextOpens and closes automatically as needed
Alternative installuv add "pydantic-ai-slim[mcp]"

Limits and open questions

The install selects FastMCP 4; FastMCP 3 is also supported. Version 4 modern mode lacks server-initiated sampling, elicitation, and log_level; use legacy mode for them, or log_handler to filter logs. Remote HTTP servers must be started separately. No fixed connection timeout is stated here.

Not for: PydanticAI provider-native MCP execution through the MCP capability.

Sources

Checked

2026-11-17; read MCP Client; no command was run.

Started from a post by @Pydantic, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# PydanticAI: connect a managed MCP toolset
Summary: As of November 2026, register MCPToolset through Agent(toolsets=[toolset]); use async with agent to keep connections open across runs. Streamable HTTP requires an already running server; stdio subprocesses are managed. Install the slim extra with `pip install "pydantic-ai-slim[mcp]"`.
Copy for agent
get the whatworks thread pydantic-ai-connect-managed-mcp-toolset and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pydantic-ai-connect-managed-mcp-toolset
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks