# Vercel AI SDK Integration

> Use Aerostack workspace tools with the Vercel AI SDK. Tools auto-execute — no manual tool call loop needed. Works with all Vercel AI models.

Use Aerostack workspace tools with the [Vercel AI SDK](https://sdk.vercel.ai/).
Tools auto-execute — no manual tool call handling needed.

## Install

```bash npm2yarn
npm install @aerostack/sdk-vercel-ai ai @ai-sdk/openai
```

## Quick Start

```typescript

const { tools } = await getTools({
  workspace: 'my-workspace',
  token: 'mwt_...',
});

const { text } = await generateText({
  model: openai('gpt-4o'),
  tools,
  maxSteps: 5,
  prompt: 'Create a GitHub issue for the login bug',
});

console.log(text);
```

That's it. The SDK:
1. Fetches all MCP tools from your workspace
2. Converts them to Vercel AI SDK tool format
3. Each tool has a built-in `execute` function that calls the workspace gateway
4. `maxSteps` enables automatic multi-step tool execution

## Streaming Responses

```typescript

const { tools } = await getTools({
  workspace: 'my-workspace',
  token: 'mwt_...',
});

const result = streamText({
  model: openai('gpt-4o'),
  tools,
  maxSteps: 5,
  prompt: 'Summarize the latest Notion pages and post to Slack',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}
```

## Use Any LLM Provider

The Vercel AI SDK supports multiple providers. Aerostack tools work with all of them:

```typescript

const { tools } = await getTools({
  workspace: 'my-workspace',
  token: 'mwt_...',
});

// Use with Claude
const { text } = await generateText({
  model: anthropic('claude-sonnet-4-20250514'),
  tools,
  maxSteps: 5,
  prompt: 'Check Stripe payments from this week',
});
```

## Factory Pattern (Recommended for Production)

Reuse a single client instance across requests:

```typescript

const aerostack = createAerostackVercelAI({
  workspace: 'my-workspace',
  token: process.env.AEROSTACK_WORKSPACE_TOKEN!,
});

// In your API route or server action:

  const { prompt } = await req.json();
  const { tools } = await aerostack.tools();

  const { text } = await generateText({
    model: openai('gpt-4o'),
    tools,
    maxSteps: 5,
    prompt,
  });

  return Response.json({ text });
}
```

## What `getTools` Returns

```typescript
const result = await getTools(config);

result.tools  // VercelToolSet — pass to generateText/streamText
result.raw    // McpTool[] — raw MCP tool definitions for inspection
```

## Next Steps

- [Create a workspace](/workspaces/create-workspace) and connect MCP servers
- [Browse 250+ MCP servers](/mcp) in the registry
- See the [full API reference](https://github.com/aerostackdev/sdk-vercel-ai) on GitHub
