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

# Use Brew with Vercel Connect

> Connect Brew to apps and agents deployed on Vercel through Vercel Connect, using the MCP server over OAuth or the REST API with an API key.

## Overview

[Vercel Connect](https://vercel.com/docs/connect) holds the credentials for third-party services at the Vercel team level. Your deployed code asks it for a short-lived token whenever it needs one. With Brew connected, no Brew API key or OAuth token ever lives in your project's environment variables.

There are two ways to connect Brew:

| Connection | Reaches | Who the token acts as | Use it when |
| :- | :- | :- | :- |
| **OAuth** | The Brew MCP server, `https://brew.new/api/mcp` | The person who signed in to Brew, scoped to one brand or the whole organization | An AI agent should use Brew's tools on behalf of a user |
| **API key** | The REST API, `https://brew.new/api/v1`, and the MCP server | The key's brand or organization | Your backend calls the API directly, for example to fire an automation trigger |

<Note>
  OAuth tokens work only with the MCP server. To call the REST API, use an API-key connection.
</Note>

## Prerequisites

<CardGroup cols="2">
  <Card title="Brew Account" icon="mug-hot">
    Sign up at [brew.new](https://brew.new) and set up your brand.
  </Card>

  <Card title="Vercel Project" icon="triangle">
    Link your directory with `vercel link`, then run `vercel env pull` to get a development OIDC token for Vercel Connect.
  </Card>
</CardGroup>

## MCP Server with OAuth

Vercel Connect registers its own OAuth client with Brew, so you don't create an app or copy a client secret.

<Steps>
  <Step title="Create the connector">
    In the Vercel dashboard, open **Connect → Browse Connectors**, choose **Brew**, and pick **OAuth**. From the CLI, create it by the MCP server URL, which works whether or not Brew is in the catalog yet:

    ```bash theme={null}
    vercel connect create https://brew.new/api/mcp --name brew
    ```

    Vercel reads Brew's OAuth discovery documents and registers the client automatically. Note the connector's UID; the examples below use `brew`.
  </Step>

  <Step title="Attach it to your project">
    ```bash theme={null}
    vercel connect attach brew
    ```

    This allows Production, Preview, and Development to request tokens. Pass `-e` to limit it to particular environments.
  </Step>

  <Step title="Install the packages">
    ```bash theme={null}
    pnpm add @vercel/connect ai @ai-sdk/mcp
    ```
  </Step>

  <Step title="Connect an AI SDK route to Brew">
    `connectAuthProvider` asks Vercel Connect for a current Brew token on every MCP request:

    ```ts app/api/chat/route.ts theme={null}
    import { createMCPClient } from '@ai-sdk/mcp';
    import {
      connectAuthProvider,
      ConsentRequiredError,
    } from '@vercel/connect/ai-sdk';
    import { stepCountIs, streamText } from 'ai';

    export const maxDuration = 60;

    export async function POST(request: Request) {
      const { prompt } = await request.json();
      // Take this from your authenticated session, never from the request body.
      const userId = 'user_123';
      let brew: Awaited<ReturnType<typeof createMCPClient>> | undefined;

      try {
        brew = await createMCPClient({
          transport: {
            type: 'http',
            url: 'https://brew.new/api/mcp',
            authProvider: connectAuthProvider(
              'brew',
              { subject: { type: 'user', id: userId } },
              { redirectUrl: new URL('/', request.url).toString() },
            ),
          },
        });

        const result = streamText({
          model: 'anthropic/claude-sonnet-5.5',
          tools: await brew.tools(),
          prompt,
          stopWhen: stepCountIs(8),
          onFinish: async () => {
            await brew?.close();
          },
        });

        return result.toTextStreamResponse();
      } catch (error) {
        await brew?.close();
        if (error instanceof ConsentRequiredError) {
          return Response.redirect(error.url, 303);
        }
        throw error;
      }
    }
    ```
  </Step>

  <Step title="Approve access in Brew">
    The first request for a user throws `ConsentRequiredError`, and the route redirects them to Brew. They sign in and choose what to connect: **one brand**, or **All brands** if they're an organization admin. The consent page shows **Returns to connect.vercel.com**. After **Allow access**, the user starts a new chat turn, and the tools load.
  </Step>
</Steps>

The connection acts with that person's current Brew access, and Brew re-checks it on every request. On a brand connection, every tool works on that brand. On an organization connection, brand tools need a `brand_id`, which the agent finds with `list_brands`. See [MCP Authentication & Scoping](/api-reference/mcp/authentication-and-scoping).

<Warning>
  OAuth connections pause before real sends. `send_email` and audience-wide `run_automation` return `confirmation_required` until the agent calls again with `confirmed: true`. Have your chat UI collect the person's approval before that second call.
</Warning>

## REST API with an API Key

<Steps>
  <Step title="Create a Brew API key">
    Create a key at [brew.new/settings/api](https://brew.new/settings/api). Anyone with access to a brand can create a key for it while that brand is active. An organization key, which reaches every brand, needs an organization admin.
  </Step>

  <Step title="Create the connector">
    In the Vercel dashboard, open **Connect → Browse Connectors**, choose **Brew**, pick **API key**, and paste the key. If Brew isn't in the catalog yet, create a generic **API key** connector instead. Once the connector exists, the key lives only in Vercel Connect. Then attach the connector to your project:

    ```bash theme={null}
    vercel connect attach brew-api
    ```
  </Step>

  <Step title="Call the API">
    `getToken` returns the stored key. Send it as a bearer token:

    ```ts app/lib/brew.ts theme={null}
    import { getToken } from '@vercel/connect';

    export async function fireBrewTrigger(
      triggerEventId: string,
      payload: Record<string, unknown>,
      idempotencyKey: string,
    ) {
      const key = await getToken('brew-api', { subject: { type: 'app' } });

      const response = await fetch(
        `https://brew.new/api/v1/automations/triggers/${triggerEventId}/fire`,
        {
          method: 'POST',
          headers: {
            Authorization: `Bearer ${key}`,
            'Content-Type': 'application/json',
            'Idempotency-Key': idempotencyKey,
          },
          body: JSON.stringify({ payload }),
        },
      );
      if (!response.ok) {
        throw new Error(`Brew returned ${response.status}`);
      }
      return response.json();
    }
    ```

    With an organization key, also send `X-Brand-Id` on brand-scoped calls. See [Authentication](/api-reference/api/authentication).
  </Step>
</Steps>

## Disconnect

* **OAuth:** each user's connection appears in Brew under **Settings → MCP**, in the "Connected via OAuth" list, where they can disconnect it. Revoking from Vercel (`revokeToken`, the dashboard, or the CLI) also ends the grant in Brew. Deleting the connector revokes every grant it holds.
* **API key:** delete the key at [brew.new/settings/api](https://brew.new/settings/api). Removing the connector in Vercel only deletes Vercel's copy.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Brew shows &#x22;Couldn’t start the connection&#x22;" icon="triangle-exclamation">
    The authorization request asked for something Brew doesn't offer. Brew has one scope, `brew:all`, so leave the connector's default scopes as they are. A `resource` other than `https://brew.new/api/mcp` is refused too.
  </Accordion>

  <Accordion title="The REST API answers 401 INVALID_API_KEY" icon="key">
    An OAuth token was sent to `/api/v1`. OAuth tokens only work with the MCP server. Use an API-key connection for REST calls.
  </Accordion>

  <Accordion title="Tools fail with BRAND_ID_REQUIRED" icon="building">
    The connection covers the whole organization. Have the agent call `list_brands` and pass `brand_id`, or reconnect and pick one brand.
  </Accordion>

  <Accordion title="ClientNotLinkedToProjectError" icon="link">
    The calling project or environment isn't attached to the connector. Run `vercel connect attach <uid>` for that environment, and run `vercel env pull` again locally if your OIDC token is older than about 12 hours.
  </Accordion>
</AccordionGroup>

## Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

<Tabs>
  <Tab title="Self-Service Tools">
    <CardGroup cols="2">
      <Card title="Search Documentation" icon="magnifying-glass" color="#c44925">
        Type in the "Ask any question" search bar at the top left to instantly find relevant documentation pages.
      </Card>

      <Card title="ChatGPT/Claude Integration" icon="robot" color="#c44925">
        Click "Open in ChatGPT" at the top right of any page to explore it further with ChatGPT or Claude.
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Talk to Our Team">
    <CardGroup cols="2">
      <Card title="Schedule a Call" icon="calendar" color="#c44925" href="https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ1iYoRUG1J792XQpbuQLjSRRDupr7MwraFK-HQRCtTYdBmrQi8nZu2qXfzKQigb8gbKJK3KN3-R">
        Book time with our founders for personalized guidance on strategy, best practices, or complex implementation questions.
      </Card>

      <Card title="Call Us Directly" icon="phone" color="#c44925">
        Need immediate assistance? Reach us at **+1-(332)-203-2145** for urgent issues or time-sensitive questions.
      </Card>

      <Card title="Slack Channel" icon="slack" color="#c44925">
        Our preferred support channel. You'll receive an invite after signup for direct founder support and fast responses.
      </Card>

      <Card title="Email Support" icon="envelope" color="#c44925" href="mailto:support@brew.new">
        Contact us at **[support@brew.new](mailto:support@brew.new)** for detailed inquiries or if you prefer not to use Slack.
      </Card>
    </CardGroup>
  </Tab>
</Tabs>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.