Vercel AI SDK
Give AI SDK agents MrScraper tools: retrieve public pages as Markdown, HTML, or screenshots, search the web, 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 the web, and check your MrScraper usage while it works.
Package information
This page documents @mrscraper/ai-sdk version 0.5.0. Its seven tools share their names, descriptions, inputs, and defaults with the MrScraper MCP server, and their inputs follow the API reference. An input with a default is always sent, with its default when the model leaves it out; an input without a default is sent only when the model sets it.
Requirements
- AI SDK 7 and Node.js 18 or later.
- A MrScraper API key from app.mrscraper.com/api-tokens.
Install
npm install @mrscraper/ai-sdk ai zodSet your key as an environment variable:
export MRSCRAPER_API_KEY="your_mrscraper_api_key"The tools use apiKey if you pass one, then MRSCRAPER_API_KEY, then
MRSCRAPER_API_TOKEN. To pass the key in code, use mrscraperTools({ apiKey })
or pass { apiKey } to a tool factory. The key is sent in request headers and
is not a tool input, so the model never sees it.
Quick start
import { generateText, isStepCount } from "ai";
import { mrscraperTools } from "@mrscraper/ai-sdk";
const { text } = await generateText({
model: "openai/gpt-5",
prompt: "Read https://example.com as Markdown and summarize it in two sentences.",
tools: mrscraperTools(),
stopWhen: isStepCount(5),
});mrscraperTools() returns all seven tools, keyed by the names the
MrScraper MCP server uses. To add only some
of them, use the individual factories:
import { scrapeMarkdownTool, webSearchTool } from "@mrscraper/ai-sdk";
const tools = {
scrapeMarkdown: scrapeMarkdownTool(),
webSearch: webSearchTool(),
};Examples use https://example.com as the sample target. Replace it for your
use case.
Tools
| Tool | Factory | Description |
|---|---|---|
status | statusTool() | Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. |
scrapeHtml | scrapeHtmlTool() | Retrieve the raw HTML of a page. Browser rendering is optional. |
scrapeMarkdown | scrapeMarkdownTool() | Retrieve a page as clean Markdown. Browser rendering is optional. |
getScreenshot | getScreenshotTool() | Capture a base64 PNG screenshot of the full page, the first viewport, or a custom viewport. Browser rendering is always enabled. |
scrapeBrand | scrapeBrandTool() | Extract a website's colors, typography, logos, and social links as JSON. |
scrapeJson | scrapeJsonTool() | Extract structured JSON from a page using a natural-language prompt. |
webSearch | webSearchTool() | Search the web and return ranked results with titles, URLs, descriptions, and sources. |
The six scraping and search tools use tokens from your plan; status uses none.
Inputs
Tool inputs use the same names, defaults, and descriptions as the MCP server's tools. They follow the API reference pages for Scrape HTML, Scrape Markdown, Get Screenshot, Scrape Brand, Scrape JSON, and Web Search. An input with a default is always sent, with its default when the model leaves it out. An input without a default is sent only when the model sets it, so the API's own default applies. A tool rejects inputs it does not define before sending any request.
Page controls
scrapeHtml, scrapeMarkdown, getScreenshot, and scrapeJson load a page
and share these inputs. Every request from these four tools also sends
saveResult=true, so its result appears in the Result tab of your MrScraper
dashboard.
| Parameter | Type | Default | Tools | Description |
|---|---|---|---|---|
url | string | Required | all four | Absolute HTTP or HTTPS URL of the page to process. |
browserRendering | boolean | Not sent | all but getScreenshot | Whether to load the page in a browser: true enables it, false disables it unless required. Omit to try without a browser first and switch automatically if blocked. waitForSelector forces true. |
timeout | integer, 1 to 330 | 300 | all four | Maximum seconds to wait for the page to fully load before the request times out. Increase for slow or complex pages. |
warmStart | boolean | false | all but getScreenshot | Warm up session before going directly to the target URL. |
blockResources | boolean | false | all but getScreenshot | Block images, fonts, and stylesheets from loading. Speeds up scraping and reduces bandwidth usage. |
waitForSelector | string, 1 to 500 characters | Not sent | all four | Pause until a specific CSS selector or text appears on the page. Useful for content that loads asynchronously after the initial page load. Requires a rendered page. Setting this parameter automatically forces browserRendering to true. |
geoCode | string, two letters | Not sent | all four | Two-letter country code to load the page from, sent in lowercase. |
maxAge | integer (milliseconds), 0 to 604800000 | 0 | all four | Return a cached result of the same request when it is newer than the selected age. Set to 0 to always fetch fresh results. A cached result costs the same tokens as the original scrape. |
maxRetries | integer, 0 or more | Not sent | all four | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
tokenCap | integer, 0 or more | Not sent | all four | Maximum total tokens the scrape and its retries can use. Automatic retries are bounded by this cap, so the total tokens for a single run stay at or below the value you set. Omit for no limit. |
cookies | string | Not sent | all but scrapeJson | Cookies to send to the target site, as name=value pairs separated by semicolons (URL-encoded), for pages behind a login session. The gateway sends them as the Cookie header and never forwards the parameter itself. A standard Cookie request header works too; this parameter wins when both are sent. Requests with cookies skip the result cache. |
Setting waitForSelector sends browserRendering=true, even when
browserRendering is false. cookies is sent as given, for example
cookies=cookie_name%3Dvalue after query encoding. The HTTP request allows
timeout plus 30 seconds (330 seconds by default).
status
No inputs. The request is
GET https://api.app.mrscraper.com/api/v1/subscription-accounts, with a fixed
HTTP deadline of 600 seconds.
Response: The API body contains message and data. Account details remain nested in data, including subscriptionItem and scraperAllowance. The response envelope therefore exposes account details at data.data. Sensitive response headers are removed.
scrapeHtml
Inputs, in order: url, browserRendering, timeout, warmStart,
blockResources, waitForSelector, geoCode, maxAge, maxRetries,
screenshot, tokenCap, cookies (see Page controls),
where:
| Parameter | Type | Default | Description |
|---|---|---|---|
screenshot | boolean | false | Capture a screenshot too (forces browser rendering). Set to true to include a screenshot, or false (default) for none. |
Query fields, in order: url, html=true, markdown=false,
browserRendering, timeout, warmStart, blockResources,
waitForSelector, geoCode, saveResult=true, tokenCap, maxAge,
maxRetries, screenshot, cookies. browserRendering is sent as set, and
as true when waitForSelector is set or screenshot is true.
Example input and the request it sends:
{
"url": "https://example.com",
"browserRendering": true,
"warmStart": true,
"waitForSelector": "body",
"timeout": 120,
"tokenCap": 20,
"cookies": "cookie_name=value"
}GET https://api.mrscraper.com/?url=https%3A%2F%2Fexample.com&html=true&markdown=false&browserRendering=true&timeout=120&warmStart=true&blockResources=false&waitForSelector=body&saveResult=true&tokenCap=20&maxAge=0&screenshot=false&cookies=cookie_name%3DvalueResponse: HTML text. With screenshot true, JSON with html and a base64
screenshot.
scrapeMarkdown
Inputs, in order: url, browserRendering, timeout, warmStart,
blockResources, waitForSelector, geoCode, maxAge, maxRetries,
tokenCap, cookies (see Page controls).
Query fields, in order: url, markdown=true, html=false,
screenshot=false, browserRendering, timeout, warmStart,
blockResources, waitForSelector, geoCode, saveResult=true,
tokenCap, maxAge, maxRetries, cookies.
Example input and the request it sends:
{
"url": "https://example.com",
"geoCode": "GB",
"maxAge": 86400000
}GET https://api.mrscraper.com/?url=https%3A%2F%2Fexample.com&markdown=true&html=false&screenshot=false&timeout=300&warmStart=false&blockResources=false&geoCode=gb&saveResult=true&maxAge=86400000Response: Markdown text.
getScreenshot
Inputs, in order: url, screenshot, timeout, waitForSelector,
geoCode, maxAge, maxRetries, tokenCap, cookies (see
Page controls), where:
| Parameter | Type | Default | Description |
|---|---|---|---|
screenshot | string: full, top, or WIDTHxHEIGHT[-ZOOM] | "full" | full (default) captures the entire scroll height, top captures the first viewport, or a custom size WIDTHxHEIGHT with optional -ZOOM, e.g. 1280x800 or 1920x1080-75. Width/height 100 to 3840, zoom 25 to 300. |
Query fields, in order: url, screenshot, html=false, markdown=false,
browserRendering=true, timeout, waitForSelector, geoCode,
saveResult=true, tokenCap, maxAge, maxRetries, cookies.
Example input and the request it sends:
{
"url": "https://example.com",
"screenshot": "1920x1080-75"
}GET https://api.mrscraper.com/?url=https%3A%2F%2Fexample.com&screenshot=1920x1080-75&html=false&markdown=false&browserRendering=true&timeout=300&saveResult=true&maxAge=0Response: JSON with the base64 PNG in screenshot and the page html (the
API includes the HTML although html=false is sent).
scrapeBrand
| Parameter | Type | Default | Description |
|---|---|---|---|
url | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
The request is
GET https://api.mrscraper.com/?action=brand-scraping&url=…&bundle=none, with
a fixed HTTP deadline of 120 seconds. Page controls are not accepted.
Response: The API body contains message and a data object with job_id, status, url, final_url, brand, and error. Brand details are available at data.data.brand in the response envelope.
scrapeJson
Inputs, in order: url, prompt, html, browserRendering, timeout,
warmStart, blockResources, waitForSelector, geoCode, maxAge,
maxRetries, screenshot, tokenCap (see Page controls;
cookies is not accepted), where:
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | "Extract all data as complete as possible." | Describe the data shape you want back (e.g. fields like title, price, rating). This prompt only parses the scraped content. It cannot instruct the scraper flow itself. |
html | boolean | true | Whether to include the page HTML in the response. |
screenshot | boolean | false | Whether to include a base64 screenshot in the response. |
Query fields, in order: url, prompt, agent=general, html,
browserRendering, timeout, warmStart, blockResources,
waitForSelector, geoCode, saveResult=true, tokenCap, maxAge,
maxRetries, screenshot. The request is a GET. If its URL would exceed
8,000 characters, it switches to POST with url, prompt, and agent in a
JSON body; the other fields stay in the query.
Example input and the request it sends:
{
"url": "https://example.com",
"prompt": "Extract the first 2 items with title and price.",
"html": false
}GET https://api.mrscraper.com/?url=https%3A%2F%2Fexample.com&prompt=Extract+the+first+2+items+with+title+and+price.&agent=general&html=false&timeout=300&warmStart=false&blockResources=false&saveResult=true&maxAge=0&screenshot=falseResponse: Extraction results are in the API body's data field, plus html
unless it is false and screenshot when it is true.
webSearch
| Parameter | Type | Default | Description |
|---|---|---|---|
query | string, 1 to 1000 characters after trimming | Required | Search query text, trimmed before sending, containing 1 to 1000 characters. |
country | string, two letters | Not sent | Two-letter country code to search from, sent in lowercase. |
numResults | integer, 10 to 100 | 10 | Number of search results to request, as an integer from 10 to 100. Fewer results may be returned. |
Query fields, in order: action=websearch, query, country, numResults.
The HTTP deadline is fixed at 120 seconds.
Example input and the request it sends:
{
"query": "site:example.com documentation",
"country": "ID",
"numResults": 20
}GET https://api.mrscraper.com/?action=websearch&query=site%3Aexample.com+documentation&country=id&numResults=20Response: The API body contains success, message, a data array, and tokenUsage. Each result includes rank, title, url, description, and source.
Response format
Each tool returns the response envelope, MrScraperResponse, with
status_code, data, and headers. data holds the API response body; its
field names are not converted. Credential headers are removed.
{
"status_code": 200,
"data": "<html><body>Example page content...</body></html>",
"headers": {
"content-type": "text/html; charset=utf-8"
}
}The AI SDK sends tool results to the model as JSON. getScreenshot, and
scrapeHtml or scrapeJson when a screenshot is requested, send the base64
screenshot to the model as an image part instead, so a screenshot costs image
tokens rather than text tokens. Your code still receives the base64 string in
data.screenshot.
The package also exports MrScraperToolOptions, MrScraperError, an input
type for each tool (StatusInput, ScrapeHtmlInput, ScrapeMarkdownInput,
GetScreenshotInput, ScrapeBrandInput, ScrapeJsonInput, WebSearchInput),
and the response types MrScraperResponse, PageData, WebSearchResponse,
and WebSearchResult.
Errors
Authentication, HTTP, network, and timeout failures throw MrScraperError,
exported by @mrscraper/ai-sdk. Its status property is the HTTP status when
available, and the API key is never included in the message. The AI SDK
reports the error to the model as a tool error, so the model can explain the
problem or try another approach. Inputs that do not match a tool's schema are
rejected before any request.
Related
- MCP server: connect MCP clients such as Claude, Cursor, or ChatGPT instead.
- Node.js SDK: call the MrScraper API directly.
- Source on GitHub