> For the complete documentation index, see [llms.txt](https://docs.allmcp.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allmcp.co/documentation/agent-frameworks/pydanticai.md).

# PydanticAI

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

<a href="/pages/416edc1381c20849bc41111b02e482a722a49b94" class="button primary" data-icon="key">Get your API key</a> <a href="/pages/QJVxDLqxIz5KMCH5afbE" class="button secondary" data-icon="table-cells">Browse providers</a>

{% hint style="success" icon="plug" %}
**Native MCP support.** PydanticAI talks to AllMCP through its built-in `MCPServerStreamableHTTP` toolset — no adapter or extra glue code required.
{% endhint %}

***

## Install

{% code title="install" %}

```bash
pip install 'pydantic-ai-slim[mcp]'
```

{% endcode %}

***

## Minimal example

{% code title="agent.py" overflow="wrap" %}

```python
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())
```

{% endcode %}

***

## Multi-user setup

{% hint style="info" icon="users" %}
**Per-user credentials.** Append `?user_id=<id>` to the endpoint URL so each user's tools resolve against their own connected accounts.
{% endhint %}

{% code title="multi\_user.py" overflow="wrap" %}

```python
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
```

{% endcode %}

***

## Streaming

PydanticAI supports streaming with MCP tools:

{% code title="streaming.py" overflow="wrap" %}

```python
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)
```

{% endcode %}

***

## With a system prompt

{% code title="system\_prompt.py" overflow="wrap" %}

```python
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."
    ),
)
```

{% endcode %}

***

## Multi-provider setup

Connect tools from AllMCP alongside other MCP servers:

{% code title="multi\_provider.py" overflow="wrap" %}

```python
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"),
    ],
)
```

{% endcode %}

***

## Next steps

{% content-ref url="/pages/uBaUeZYQpupBMd5c1BY0" %}
[Overview](/documentation/agent-frameworks/frameworks.md)
{% endcontent-ref %}

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Browse providers</strong></td><td>See every app you can connect and the tools each one exposes.</td><td><a href="https://docs.allmcp.co/documentation/providers/">https://docs.allmcp.co/documentation/providers/</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.allmcp.co/documentation/agent-frameworks/pydanticai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
