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

# Mastra

> Connect SAN's MCP server to a Mastra agent in TypeScript.

Mastra loads SAN through the `MCPClient` from `@mastra/mcp`. It exposes SAN's tools to any Mastra `Agent`.

## Prerequisites

* Node.js 20+
* 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 the packages">
    ```bash theme={null}
    npm install @mastra/core @mastra/mcp
    ```
  </Step>

  <Step title="Point an MCPClient at SAN">
    A `url` created with `new URL()` uses streamable HTTP. Pass your key under `requestInit.headers`.

    ```typescript theme={null}
    import { MCPClient } from '@mastra/mcp'

    const mcp = new MCPClient({
      servers: {
        san: {
          url: new URL('https://gateway.sanfoundation.com/mcp'),
          requestInit: {
            headers: {
              'x-api-key': process.env.SAN_API_KEY!, // "sk_..."
            },
          },
        },
      },
    })
    ```
  </Step>

  <Step title="Give the tools to an agent">
    `listTools()` fetches SAN's tools once so you can bind them to an agent.

    ```typescript theme={null}
    import { Agent } from '@mastra/core/agent'

    export const sanAgent = new Agent({
      name: 'SAN Agent',
      instructions: 'You have access to the SAN MCP server tools.',
      model: 'openai/gpt-4.1', // any model your Mastra setup supports
      tools: await mcp.listTools(),
    })
    ```

    <Note>
      On Mastra v0 (pre-1.0), the method is `getTools()` instead of `listTools()`.
    </Note>
  </Step>
</Steps>
