SDKs

Vercel AI SDK

Give AI SDK agents MrScraper tools: retrieve public pages as Markdown, HTML, or screenshots, search Google, and check account usage with @mrscraper/ai-sdk.

The @mrscraper/ai-sdk package provides MrScraper tools for the Vercel AI SDK. Pass them to generateText, streamText, or an agent, and the model can retrieve web pages, search Google, and check your MrScraper usage while it works.

Requirements

Install

npm install @mrscraper/ai-sdk ai zod

Set your key as an environment variable:

export MRSCRAPER_API_KEY="your_mrscraper_api_key"

The tools read MRSCRAPER_API_KEY, then MRSCRAPER_API_TOKEN. To pass the key in code instead, use mrscraperTools({ apiKey }).

Quick start

import { generateText, isStepCount } from "ai";
import { mrscraperTools } from "@mrscraper/ai-sdk";

const { text } = await generateText({
  model: "openai/gpt-5",
  prompt:
    "Read https://www.scrapethissite.com/pages/simple/ and list the five countries with the largest area.",
  tools: mrscraperTools(),
  stopWhen: isStepCount(5),
});

mrscraperTools() returns scraperAPI, webSearch, and status, the same names the MrScraper MCP server uses. To add only some of them, use the individual factories:

import { scraperApiTool, webSearchTool } from "@mrscraper/ai-sdk";

const tools = {
  scraperAPI: scraperApiTool(),
  webSearch: webSearchTool(),
};

Tools

ToolInputsReturns
scraperAPIurl; formats (markdown, html, screenshot; default markdown); optional browserRendering, waitForSelector, geoCode, timeoutThe requested formats, the API status code, and the tokens used
webSearchquery (search terms or a Google search URL); optional region, language, pageOrganic results (rank, title, link, description, source), "People also ask" entries, and the next page number
statusNoneSubscription status, token limit, tokens used, and tokens remaining

Screenshots are sent to the model as images rather than as base64 text. scraperAPI and webSearch use tokens from your plan; status uses none.

Errors

API errors, such as an invalid key or an exhausted plan, are thrown from the tool. The AI SDK reports them to the model as tool errors, so the model can explain the problem or try another approach. The API key is never included in an error message.

On this page