Skip to content

PydanticAI

PydanticAI has native MCP support via MCPServerStreamableHTTP. AllMCP works as a drop-in server.

Get your API key Browse providers
install
pip install 'pydantic-ai-slim[mcp]'

agent.py
import asyncio
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP
allmcp = MCPServerStreamableHTTP(
url="https://go.allmcp.co/mcp/",
headers={"X-API-Key": "YOUR_API_KEY"},
)
agent = Agent(
"anthropic:claude-sonnet-4-6",
toolsets=[allmcp],
)
async def main():
async with agent:
result = await agent.run("List all open deals in my CRM")
print(result.output)
asyncio.run(main())

multi_user.py
def make_agent(user_id: str) -> Agent:
server = MCPServerStreamableHTTP(
url=f"https://go.allmcp.co/mcp/?user_id={user_id}",
headers={"X-API-Key": "YOUR_API_KEY"},
)
return Agent("anthropic:claude-sonnet-4-6", toolsets=[server])
async def handle_request(user_id: str, prompt: str) -> str:
agent = make_agent(user_id)
async with agent:
result = await agent.run(prompt)
return result.output

PydanticAI supports streaming with MCP tools:

streaming.py
async def stream_response():
async with agent:
async with agent.run_stream("Summarize my top 5 leads") as response:
async for chunk in response.stream_text():
print(chunk, end="", flush=True)

system_prompt.py
agent = Agent(
"anthropic:claude-sonnet-4-6",
toolsets=[allmcp],
system_prompt=(
"You are a CRM assistant. When the user asks about contacts or deals, "
"use the Bitrix24 tools. Always confirm before creating or updating records."
),
)

Connect tools from AllMCP alongside other MCP servers:

multi_provider.py
from pydantic_ai.mcp import MCPServerStreamableHTTP
agent = Agent(
"anthropic:claude-sonnet-4-6",
toolsets=[
MCPServerStreamableHTTP(
url="https://go.allmcp.co/mcp/",
headers={"X-API-Key": "YOUR_ALLMCP_KEY"},
),
MCPServerStreamableHTTP(url="https://other-mcp-server.com"),
],
)