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

# Vercel AI SDK Integration

> Integrate MCP servers with Vercel AI SDK using Smithery

The [Vercel AI SDK](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) has built-in support for MCP servers. This guide shows how to use Smithery with the AI SDK to add MCP tools to your AI applications.

## Installation

```bash theme={null}
npm install ai @ai-sdk/mcp @ai-sdk/anthropic @smithery/api
```

## Quick Start

Use `createConnection` from `@smithery/api/mcp` to get a transport for the AI SDK's MCP client:

```typescript theme={null}
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { createConnection } from '@smithery/api/mcp';

const { transport } = await createConnection({
  mcpUrl: 'https://exa.run.tools',
});

const mcpClient = await createMCPClient({ transport });
const tools = await mcpClient.tools();

const { text } = await generateText({
  model: anthropic('claude-sonnet-4-20250514'),
  tools,
  prompt: 'Search for the latest news about MCP.',
});

await mcpClient.close();
```

Smithery handles OAuth, token refresh, and connection management automatically.

## Streaming Responses

Use `streamText` for streaming responses. Close the client in `onFinish`:

```typescript theme={null}
import { createMCPClient } from '@ai-sdk/mcp';
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { createConnection } from '@smithery/api/mcp';

const { transport } = await createConnection({
  mcpUrl: 'https://exa.run.tools',
});

const mcpClient = await createMCPClient({ transport });
const tools = await mcpClient.tools();

const result = await streamText({
  model: anthropic('claude-sonnet-4-20250514'),
  tools,
  prompt: 'Search the web for the latest AI news',
  onFinish: async () => {
    await mcpClient.close();
  },
});
```

## Multiple MCP Servers

Connect to multiple servers and aggregate their tools:

```typescript theme={null}
import { createMCPClient } from '@ai-sdk/mcp';
import { createConnection } from '@smithery/api/mcp';

const servers = [
  'https://exa.run.tools',
  'https://gmail.run.tools',
];

const clients = await Promise.all(
  servers.map(async (mcpUrl) => {
    const { transport } = await createConnection({ mcpUrl });
    return createMCPClient({ transport });
  })
);

// Aggregate tools from all servers
const allTools = Object.assign({}, ...(await Promise.all(clients.map(c => c.tools()))));
```

## Learn More

* [Connect to MCPs](/use/connect) — Full guide including OAuth handling, multi-user setups, and service tokens
* [Token Scoping](/use/token-scoping) — Secure browser and mobile access
* [Vercel AI SDK MCP Documentation](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools)
