> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sanfoundation.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Add SAN as an MCP toolset on a Pydantic AI agent.

Pydantic AI connects to SAN with `MCPToolset` from `pydantic_ai.mcp`. Attach it to any `Agent` through the `toolsets` argument.

## Prerequisites

* Python 3.10+
* A SAN API key\
  Create one in the [API Quickstart](/api-quickstart) if you don't have one yet.

## Quick Start

<Steps>
  <Step title="Install Pydantic AI with the MCP extra">
    ```bash theme={null}
    pip install "pydantic-ai-slim[mcp]"
    ```
  </Step>

  <Step title="Point a toolset at SAN">
    A URL without an `/sse` suffix uses streamable HTTP. Pass your key in `headers`.

    ```python theme={null}
    from pydantic_ai.mcp import MCPToolset

    server = MCPToolset(
        'https://gateway.sanfoundation.com/mcp',
        headers={'x-api-key': 'sk_...'},
    )
    ```

    <Note>
      On Pydantic AI 1.x, this class is `MCPServerStreamableHTTP` (same arguments). It was renamed to `MCPToolset` in 2.0.
    </Note>
  </Step>

  <Step title="Run an agent with SAN's tools">
    Pass the toolset via `toolsets` and open the agent to manage the connection.

    ```python theme={null}
    import asyncio
    from pydantic_ai import Agent

    agent = Agent('openai:gpt-4o', toolsets=[server])

    async def main() -> None:
        async with agent:
            result = await agent.run('Which SAN agents are available?')
            print(result.output)

    asyncio.run(main())
    ```
  </Step>
</Steps>
