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

# MCP Web Search & Scrape in the Vercel AI SDK

> Connect the Vercel AI SDK MCP client to Firecrawl's hosted MCP server for web search and scraping

Connect the [Vercel AI SDK](https://ai-sdk.dev) MCP client to Firecrawl's hosted MCP server and use Firecrawl's tools in `generateText` and `streamText`.

<Note>
  Looking for Firecrawl tools packaged as AI SDK tools instead of an MCP connection? See the [Vercel AI SDK guide](/developer-guides/llm-sdks-and-frameworks/vercel-ai-sdk).
</Note>

## Quick setup

[Create a Firecrawl API key](https://www.firecrawl.dev/app/api-keys), then install the AI SDK and its MCP package:

```bash theme={null}
npm install ai @ai-sdk/mcp
export FIRECRAWL_API_KEY="fc-YOUR-API-KEY"
```

Create the client with the HTTP transport and your key in the `Authorization` header:

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

const mcpClient = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://mcp.firecrawl.dev/v2/mcp',
    headers: { Authorization: `Bearer ${process.env.FIRECRAWL_API_KEY}` },
  },
});

const tools = await mcpClient.tools();
console.log(Object.keys(tools));
```

The list includes `firecrawl_scrape`, `firecrawl_search`, `firecrawl_map`, and `firecrawl_crawl`. Pass `tools` to `generateText` or `streamText` as described in the [AI SDK MCP guide](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools), and close the client with `await mcpClient.close()` when the response is finished.

Prefer a local process? Use the AI SDK's stdio transport with `npx -y firecrawl-mcp` and `FIRECRAWL_API_KEY` in `env`; the AI SDK recommends HTTP for production.

## Try it

Call a tool directly to confirm the connection:

```typescript theme={null}
const result = await tools.firecrawl_scrape.execute(
  { url: 'https://firecrawl.dev', formats: ['markdown'], onlyMainContent: true },
  { toolCallId: 'test', messages: [] },
);
console.log(result.content[0].text.slice(0, 300));
await mcpClient.close();
```

Then give the tools to a model with a prompt such as:

```text theme={null}
Search the web for the latest Next.js release notes and summarize the sources.
```

## Troubleshooting

* **Authentication errors:** confirm `FIRECRAWL_API_KEY` is set in the process that runs the client and that the header reads `Bearer <key>`.
* **Redirect errors:** the AI SDK client rejects redirects by default; use the exact URL `https://mcp.firecrawl.dev/v2/mcp`.
* **Open handles after a script ends:** call `mcpClient.close()` when you are done with the tools.


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