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

# smolagents

> Load SAN's MCP tools into a Hugging Face smolagents CodeAgent.

Hugging Face [smolagents](https://huggingface.co/docs/smolagents) connects to SAN with a `ToolCollection`, which pulls SAN's MCP tools into a `CodeAgent` or `ToolCallingAgent`.

## 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 smolagents with the MCP extra">
    ```bash theme={null}
    pip install "smolagents[mcp]"
    ```
  </Step>

  <Step title="Describe SAN's MCP server">
    Set the transport to `streamable-http` and pass your key in `headers`.

    ```python theme={null}
    server = {
        "url": "https://gateway.sanfoundation.com/mcp",
        "transport": "streamable-http",
        "headers": {"x-api-key": "sk_..."},
    }
    ```
  </Step>

  <Step title="Run an agent with SAN's tools">
    `ToolCollection.from_mcp` requires `trust_remote_code=True`. Open it as a context manager so the connection is closed for you.

    ```python theme={null}
    from smolagents import ToolCollection, CodeAgent, InferenceClientModel

    model = InferenceClientModel()

    with ToolCollection.from_mcp(server, trust_remote_code=True) as tool_collection:
        agent = CodeAgent(
            tools=[*tool_collection.tools],
            model=model,
            add_base_tools=True,
        )
        agent.run("List the available SAN agents.")
    ```
  </Step>
</Steps>
