@crawlbrulee/mcp 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +88 -17
  2. package/dist/index.js +154 -52
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -49,7 +49,7 @@ claude mcp add crawlbrulee -- npx -y @crawlbrulee/mcp
49
49
  other stdio hosts run the same command: `npx -y @crawlbrulee/mcp`. a few of them (Codex,
50
50
  Cursor, Windsurf, Gemini CLI, Claude Desktop) need the key or the variable named in their
51
51
  config file, and VS Code and the Claude Code plugin can ask for the key in a masked prompt.
52
- the file and the entry for each one: [mcp setup in the docs](https://crawlbrulee.com/docs/mcp#install).
52
+ the file and the entry for each one: [mcp setup in the docs](https://crawlbrulee.com/docs/mcp/local#install).
53
53
 
54
54
  if a key stops working (`invalid_credentials`), it's expired, revoked or mistyped: create a
55
55
  new one the same way, replace the old one, and start your agent again.
@@ -72,7 +72,7 @@ server failing to come up. see
72
72
  ### `scrape`
73
73
 
74
74
  fetch a single url and return the requested content (markdown, cleaned
75
- html, raw html, links, images, screenshot, page metadata).
75
+ html, raw html, links, images, screenshot, pdf, page metadata).
76
76
 
77
77
  **input** — only `url` is required; everything else has sane defaults.
78
78
 
@@ -95,12 +95,14 @@ html, raw html, links, images, screenshot, page metadata).
95
95
 
96
96
  `zero_data_retention` (boolean, default `false`) keeps the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. it adds 1 credit and must be enabled for your organization. `scrape_async` takes it too. see [zero data retention](https://crawlbrulee.com/docs/zero-data-retention).
97
97
 
98
- **named values with `extract.elements`.** to pull a few values from a page — prices, titles, links — give each one a name and a CSS selector, instead of reading the whole markdown. they come back in `elements` under the same names. `all: true` returns every match as a list, and `fields` reads named values inside each match (`:scope` reads the match itself). it costs no extra credits. `scrape_async` takes it too.
98
+ **named values with `extract.elements`.** to pull a few values from a page — prices, titles, links — give each one a name and a CSS selector, instead of reading the whole markdown. they come back in `elements` under the same names. `all: true` returns every match as a list, and `fields` reads named values inside each match (`:scope` reads the match itself). markdown and metadata stay on unless you turn them off, as the example does. it costs no extra credits. `scrape_async` takes it too.
99
99
 
100
100
  ```jsonc
101
101
  {
102
102
  "url": "https://shop.example.com/books/",
103
103
  "extract": {
104
+ "markdown": false,
105
+ "metadata": false,
104
106
  "elements": {
105
107
  "heading": "h1",
106
108
  "books": {
@@ -137,7 +139,39 @@ a name with no match is `null` (or `[]` with `all: true`). limits and selector r
137
139
 
138
140
  your own `User-Agent` can lower the success rate, and the response then carries the `custom_user_agent` warning. never put secrets in the `User-Agent`. the limits and which headers can't be set: see [headers and cookies](https://crawlbrulee.com/docs/scrape/custom-headers-and-cookies).
139
141
 
140
- **output** — full scrape result. page metadata (title, OG tags, etc.) is returned under `metadata`. extracted `images` are returned as absolute urls — query strings are preserved, and relative `src`s are resolved against the page url. screenshots are returned as signed download urls the agent can fetch separately. in rare cases a screenshot can't be captured: when you requested other outputs too, the `screenshot` field is simply left out while the rest is still returned — but a screenshot-only call that can't deliver errors instead (`unsupported_screenshot_output`, HTTP 422, when the content type can't be screenshotted) and isn't billed. the result also carries `page_status_code` and a top-level `response_meta.usage` block:
142
+ **save the page as a pdf with `extract.pdf`.** you get a real document, with text you can select and links that work. `{}` takes every default: the page on a4 sheets, as it looks on screen. a pdf costs what a screenshot costs, and a pdf and a screenshot in one request are billed once. `scrape_async` takes it too.
143
+
144
+ ```jsonc
145
+ {
146
+ "url": "https://example.com/report",
147
+ "extract": {
148
+ "markdown": false,
149
+ "metadata": false,
150
+ "pdf": { "layout": "pages", "paper": "letter", "landscape": false, "media": "print" },
151
+ },
152
+ }
153
+ // → "pdf": { "url": "https://...", "bytes": 48213 }
154
+ ```
155
+
156
+ | option | values | default | what it does |
157
+ | ----------- | ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------- |
158
+ | `layout` | `pages` \| `single_page` | `pages` | `pages` puts the page on sheets of paper. `single_page` makes one page as tall as the web page, up to 15,000 px. |
159
+ | `paper` | `a4` \| `letter` | `a4` | paper size. only with `pages`. |
160
+ | `landscape` | `true` \| `false` | `false` | turn the paper sideways. only with `pages`. |
161
+ | `media` | `screen` \| `print` | `screen` | `print` uses the site's own print style, which on many sites hides menus and images. |
162
+
163
+ the pdf link is a signed link that expires 24 hours after the scrape, like a screenshot link: download the file and keep it, not the link. a cached copy answers only when it has a pdf made with the same settings; `cache.max_age: 0` always makes a new one. in rare cases the pdf can't be made: you still get the rest of the scrape, with the `pdf_unavailable` warning, and the request costs what it costs without the pdf.
164
+
165
+ **dark-theme screenshots with `color_scheme`.** set `extract.screenshot.color_scheme` to `dark` to ask the site for its dark theme. a site with no dark theme looks the same as with `light`, the default. it costs no extra credits. when the request also asks for `extract.pdf`, the pdf shows the dark theme too; a pdf on its own is made with the light theme.
166
+
167
+ ```jsonc
168
+ {
169
+ "url": "https://example.com",
170
+ "extract": { "screenshot": { "type": "viewport", "color_scheme": "dark" } },
171
+ }
172
+ ```
173
+
174
+ **output** — full scrape result. page metadata (title, OG tags, etc.) is returned under `metadata`. extracted `images` are returned as absolute urls — query strings are preserved, and relative `src`s are resolved against the page url. screenshots and pdfs are returned as signed download urls the agent can fetch separately. in rare cases a screenshot can't be captured: when you requested other outputs too, the `screenshot` field is left out while the rest is still returned. a screenshot-only call (every other format off: `markdown: false` and `metadata: false`, and no `cleaned_html`, `raw_html`, `links`, `images` or `elements`) that can't deliver errors instead (`unsupported_screenshot_output`, HTTP 422, when the content type can't be screenshotted) and isn't billed. a pdf-only call works the same way, with `unsupported_pdf_output`. when no capture could be made at all, such a call fails with `internal_server_error` (HTTP 500), also not billed. a `scrape_async` job that asks only for a screenshot, a pdf or both and gets none ends `failed` and isn't billed: `scrape_result` then returns the same `unsupported_screenshot_output` or `unsupported_pdf_output`, or `job_failed` when the capture could not be made. the result also carries `page_status_code` and a top-level `response_meta.usage` block:
141
175
 
142
176
  ```jsonc
143
177
  {
@@ -161,7 +195,7 @@ your own `User-Agent` can lower the success rate, and the response then carries
161
195
  }
162
196
  ```
163
197
 
164
- **a page the site served is a result, not an error.** `page_status_code` is the HTTP status the site answered with for the final page, after redirects. a 404, 410 or 503 page comes back with its content and its status here, so check `page_status_code` before you trust the content: a 404 means the markdown is the site's "not found" page. 2xx and 4xx pages are billed, except 403, 407, 408, 429 and 451; 5xx pages are never billed. when the site can't be reached at all, the tool returns a `target_unreachable` error instead (see [errors](#errors)).
198
+ **a page the site served is a result, not an error.** `page_status_code` is the HTTP status the site answered with for the final page, after redirects. a 404, 410 or 503 page comes back with its content and its status here, so check `page_status_code` before you trust the content: a 404 means the markdown is the site's "not found" page. 2xx and 4xx pages are billed, except 403, 407, 408, 429, 444 and 451; 5xx pages are never billed. when the site can't be reached at all, the tool returns a `target_unreachable` error instead (see [errors](#errors)).
165
199
 
166
200
  alongside `response_meta.usage`, the result surfaces any non-fatal `warnings` — stable string codes an agent can switch on. an outsized page is truncated rather than refused, and the code names which part was cut:
167
201
 
@@ -173,7 +207,7 @@ alongside `response_meta.usage`, the result surfaces any non-fatal `warnings`
173
207
  | `raw_html_truncated` | the page body exceeded 10,000,000 characters; `raw_html` is cut at a tag boundary, never mid-tag. |
174
208
  | `elements_truncated` | an `elements` value hit a limit; see [targeted extraction](https://crawlbrulee.com/docs/scrape/targeted-extraction). |
175
209
 
176
- two more codes are not about size. `screenshot_unavailable` means a screenshot was asked for, but the page came back from the http engine without one; the rest of the result is still there. `custom_user_agent` means the request set its own `User-Agent` header; this can lower the success rate.
210
+ more codes are not about size. `screenshot_unavailable` means a screenshot was asked for, but the page came back from the http engine without one; the rest of the result is still there. `pdf_unavailable` means the same for a pdf. `pdf_single_page_overflow` means a `single_page` pdf was taller than 15,000 px, so it goes on over more pages. `custom_user_agent` means the request set its own `User-Agent` header; this can lower the success rate.
177
211
 
178
212
  and if you requested an extract that doesn't apply to the content type (e.g. `metadata` of a JSON file), the field name comes back in an `unsupported_fields` list — with the rest of the payload still returned.
179
213
 
@@ -208,7 +242,7 @@ the job lifecycle is documented under [async scrape](https://crawlbrulee.com/doc
208
242
 
209
243
  ### `scrape_status`
210
244
 
211
- look up the current lifecycle status of an async job: `pending`, `running`, `done`, or `failed` (with an `error` message when failed). once the job is `done` the response also carries a `response_meta.usage` block (`total_credit_cost` and its parts, billed `engine`, resolved `proxy` tier). a cache hit is represented by `engine: "cache"`. a job whose page the site served ends `done` even when that page is a 404 — read `page_status_code` in the result. poll until `done`, then call `scrape_result`.
245
+ look up the current lifecycle status of an async job: `pending`, `running`, `done`, or `failed` (with an `error` message when failed). once the job is `done` the response also carries a `response_meta.usage` block (`total_credit_cost` and its parts, billed `engine`, resolved `proxy` tier). a cache hit is represented by `engine: "cache"`. a job whose page the site served ends `done` even when that page is a 404 — read `page_status_code` in the result. a job that asked only for a screenshot, a pdf or both and got none ends `failed`, not billed; `scrape_result` names the reason. poll until `done`, then call `scrape_result`.
212
246
 
213
247
  ```jsonc
214
248
  { "job_id": "..." }
@@ -216,7 +250,7 @@ look up the current lifecycle status of an async job: `pending`, `running`, `don
216
250
 
217
251
  ### `scrape_result`
218
252
 
219
- fetch the extracted content of a completed async job — the same result shape as the synchronous `scrape` tool (including `page_status_code`, `metadata`, `elements` and `response_meta.usage`). errors if the job is still `pending`/`running`, so check `scrape_status` first.
253
+ fetch the extracted content of a completed async job — the same result shape as the synchronous `scrape` tool (including `page_status_code`, `metadata`, `elements` and `response_meta.usage`). errors if the job is still `pending`/`running`, so check `scrape_status` first. a `failed` job returns `job_failed`, or `unsupported_screenshot_output` / `unsupported_pdf_output` for a capture-only job on a content type that can't be captured.
220
254
 
221
255
  ```jsonc
222
256
  { "job_id": "..." }
@@ -224,11 +258,23 @@ fetch the extracted content of a completed async job — the same result shape a
224
258
 
225
259
  ### `map`
226
260
 
227
- build (or fetch a cached) link-map for a website. combines sitemap discovery with homepage link extraction. use this to enumerate a site before scraping selected pages. each link is just `{ url }`.
261
+ build (or fetch a cached) link map of a website from its sitemaps, plus the links on its home page. use this to enumerate a site before scraping selected pages. every link is `{ url, type, lastmod }`: `type` is `page`, `sitemap` or `sitemap_index` (a sitemap file that lists other sitemap files), and `lastmod` is the entry's date from the sitemap, in UTC, or `null` when the sitemap gives none. a link found on the home page is a `page` with `lastmod: null`. a `sitemap_index` is a file the map found to be an index. `sitemap` is a file that lists pages, or one the map did not open (past `depth`, or it could not be read). read either kind with `sitemap_url` in another call.
262
+
263
+ a plain map (`{ "url": "https://example.com" }`) returns pages. it reads the site's top sitemap files and two levels of nested ones, and adds the links on the home page.
264
+
265
+ | field | values | default | what it does |
266
+ | ---------------- | ------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
267
+ | `sitemap_url` | a full http or https address | none | start from this sitemap file. it must be on the same site as `url`, or on a host the site's robots.txt names, such as a CDN. left out: start from the site's own top sitemap files. |
268
+ | `depth` | `0` to `3` | `3` | how many levels of nested sitemaps to follow (see below). |
269
+ | `entries` | `pages` \| `sitemaps` \| `all` | `pages` | what to return: page addresses, sitemap files (`sitemap` or `sitemap_index`), or both. |
270
+ | `modified_since` | a date, or ISO 8601 with a zone | none | only entries whose `lastmod` is at or after it (see below). |
271
+ | `max_results` | `1` to `100000` | `5000` | the most entries the map finds, counting only the kind in `entries`. a discovery budget, not a trim at the end (see below). |
272
+ | `limit` | `1` to `10000` | `5000` | links per page of the answer. it only pages the answer. |
273
+ | `sitemap_only` | `true` \| `false` | `false` | use the sitemaps only: leave out the links found on the home page. |
228
274
 
229
- `max_urls` (default `5000`, max `100000`) is a discovery budget, not a trim at the end — discovery stops as soon as that many urls are found, so a smaller value is a faster, cheaper crawl. `limit` (default `5000`, max `10000`) only pages the answer.
275
+ `max_results` stops discovery as soon as that many entries of the asked kind are found, so a smaller value is a faster, lighter map. a map stopped that way returns exactly that many links with `response_capped: false`. the signal that the site has more is `truncation.discovery_cap_reason`.
230
276
 
231
- returned urls are normalized the same way `scrape` normalizes its returned `url`, so map-then-scrape stays on one host. results are ordered with the most useful links first.
277
+ returned urls are normalized the same way `scrape` normalizes its returned `url`, so map-then-scrape stays on one host. results are ordered with the most useful links first. the site root is listed only when a sitemap lists it.
232
278
 
233
279
  the response's `response_meta` carries `pagination`, `truncation`, and a `usage` block (`total_credit_cost` = `engine_credit_cost` × `proxy_multiplier` + `zero_data_retention_credit_cost`, billed `engine`, resolved `proxy` tier). map has no screenshot slicing and no `page_status_code`, since it reads many files, not one page. a map that found nothing because the site answered only with statuses we don't bill (a `5xx`, for example), or not at all, is empty and free.
234
280
 
@@ -237,7 +283,7 @@ the response's `response_meta` carries `pagination`, `truncation`, and a `usage`
237
283
  "url": "https://example.com",
238
284
  "sitemap_only": false,
239
285
  "types": { "internal": true, "external": false, "internal_subdomains": true },
240
- "max_urls": 5000,
286
+ "max_results": 5000,
241
287
  "page": 1,
242
288
  "limit": 1000,
243
289
  "zero_data_retention": false,
@@ -246,23 +292,46 @@ the response's `response_meta` carries `pagination`, `truncation`, and a `usage`
246
292
 
247
293
  `zero_data_retention` works as it does on `scrape` (see [zero data retention](https://crawlbrulee.com/docs/zero-data-retention)).
248
294
 
249
- a map stopped by your own `max_urls` returns exactly that many links with `response_capped: false` — the signal that the site has more is `truncation.discovery_cap_reason`:
250
-
251
295
  ```jsonc
252
296
  {
253
297
  "truncation": {
254
298
  "storage_capped": false,
255
299
  "response_capped": false,
256
- "total_before_max_urls": 5000,
300
+ "total_before_max_results": 5000,
257
301
  "total_detected_before_storage_cap": 5000,
258
302
  "discovery_capped": true, // discovery stopped before reading every sitemap file
259
303
  "sitemaps_skipped": 3, // files skipped or only partly read
260
- "discovery_cap_reason": "max_urls", // retry with a higher max_urls
304
+ "unread_sitemaps": [], // sitemap files this call did not read whole
305
+ "discovery_cap_reason": "max_results", // retry with a higher max_results
261
306
  },
262
307
  }
263
308
  ```
264
309
 
265
- `discovery_cap_reason` is one of `max_urls`, `time`, `file_budget`, `depth`, `file_size`, `unread_files`, or `null` when nothing stopped discovery. only `max_urls` is a limit you can raise from the request. `unread_files` means a sitemap file the site publishes could not be read at all this time — often temporary, so asking again later can return more. `time`, `file_budget`, `depth` and `file_size` mean the site itself is big, slow or deep, and a retry will not help.
310
+ `discovery_cap_reason` is one of these, or `null` when nothing stopped discovery:
311
+
312
+ - `max_results`: your own `max_results` was reached. ask again with a higher one to get more.
313
+ - `depth`: there are sitemap files past the `depth` you asked for. they are in `unread_sitemaps`. this is the answer to the depth you chose, not a fault. read each one with `sitemap_url`, or ask with a higher `depth`.
314
+ - `unread_files`: a sitemap file could not be read whole this time. when its download broke off, the links received before the break are returned, and the file is in `unread_sitemaps`. often temporary, so asking again later can return more.
315
+ - `time`, `file_budget`, `file_size`: the site is big or slow, and a retry will not help. with `file_size`, a file of pages that turns out too large while it is read gives the links in its first part. a file that says up front that it is over the size limit, or any other file that turns out too large (such as a sitemap index), gives nothing and is in `unread_sitemaps`.
316
+
317
+ #### map a very large site in several calls
318
+
319
+ a very large or deep site is mapped in several calls. first ask with `depth: 1` and `entries: "sitemaps"`: one call lists the site's top sitemap files and every file they list. a listed file shows as `sitemap` until a map reads it, even when it is an index. then read each link of type `sitemap`, plus each `sitemap_index` link that is also in `truncation.unread_sitemaps` (an index this map read only in part), with `sitemap_url`, one file per call: the files of an index read whole are already in your list. or ask with a higher `depth`. the full walk-through is in [map a very large or deep site in several calls](https://crawlbrulee.com/docs/map/sitemaps#map-a-very-large-or-deep-site-in-several-calls).
320
+
321
+ ```jsonc
322
+ // 1. list the site's top sitemap files and every file they list
323
+ { "url": "https://example.com", "depth": 1, "entries": "sitemaps" }
324
+ // 2. read one of them: a `sitemap` link, or a `sitemap_index` link that is also in unread_sitemaps
325
+ { "url": "https://example.com", "sitemap_url": "https://example.com/sitemap-products-1.xml.gz" }
326
+ ```
327
+
328
+ `modified_since` leaves out every entry with no `lastmod`, and a map with it is always fresh, so `cache.max_age` does nothing. every sitemap file is read whatever its own date, and each entry is judged by its own `lastmod`. with `entries: "sitemaps"` a file is returned by its own date, not by the dates of the pages in it, so ask with `entries: "pages"` to find the pages that changed. see [find what changed since a date](https://crawlbrulee.com/docs/map/sitemaps#find-what-changed-since-a-date).
329
+
330
+ if the site answers `429` on the file in `sitemap_url`, on its robots.txt or on one of its top sitemap files, the tool returns `too_many_requests` (not billed): wait and try again.
331
+
332
+ #### old names
333
+
334
+ `max_urls` is the old name of `max_results`, and `total_before_max_urls` of `total_before_max_results`. both still work and mean the same. the api drops them on 2027-02-01. this tool still takes `max_urls` and sends it as `max_results`; when you give both, only `max_results` is used.
266
335
 
267
336
  see the [map endpoint](https://crawlbrulee.com/docs/map) for discovery rules and pagination semantics.
268
337
 
@@ -305,6 +374,8 @@ agents can branch on the `errorName` code. the set comes from the sdk's `ApiErro
305
374
  | `zero_data_retention_not_enabled` | `zero_data_retention` is not enabled for your organization (HTTP 403). not billed. |
306
375
  | `scrape_error` | the scrape could not be completed. a page the site served, even a 404, is never this error. |
307
376
  | `unsupported_screenshot_output` | screenshot-only request on a content type that can't be screenshotted (HTTP 422). not billed. |
377
+ | `unsupported_pdf_output` | pdf-only request on a content type that can't be made into a pdf (HTTP 422). not billed. |
378
+ | `job_failed` | the async job ended `failed`, so it has no result (`scrape_result`, HTTP 400). |
308
379
  | `not_found` | async job ID unknown, or submitted more than 24 hours ago (`scrape_status` / `scrape_result`). |
309
380
  | `request_timeout` | network / read timeout. safe to retry. |
310
381
  | `client_closed_request` | caller cancelled before completion. |
package/dist/index.js CHANGED
@@ -223,10 +223,32 @@ const Schema_ScrapeElements = buildElementsMap(3, true);
223
223
  */
224
224
  const Schema_ScrapeElementValues = z.record(z.string(), z.unknown());
225
225
 
226
+ //#endregion
227
+ //#region src/schemas/ScrapePdfSchemas.ts
228
+ const SCRAPE_PDF_LAYOUT_VALUES = ["pages", "single_page"];
229
+ const SCRAPE_PDF_PAPER_VALUES = ["a4", "letter"];
230
+ const SCRAPE_PDF_MEDIA_VALUES = ["screen", "print"];
231
+ /** The tallest `single_page` PDF page, in css pixels. A taller page goes on over more pages. */
232
+ const MAX_SCRAPE_PDF_SINGLE_PAGE_HEIGHT_PX = 15e3;
233
+ const Schema_ApiScrapePdf = z.object({
234
+ layout: z.enum(SCRAPE_PDF_LAYOUT_VALUES).default("pages").describe(`\`pages\` (default): the page on sheets of paper, laid out as in the browser window (the desktop default, or the screenshot device and viewport when the request also asks for a screenshot) and shrunk to fit the paper width. \`single_page\`: one page as wide as the browser window and as tall as the web page, up to ${MAX_SCRAPE_PDF_SINGLE_PAGE_HEIGHT_PX.toLocaleString("en-US")} px; a taller page goes on over more pages, with the \`pdf_single_page_overflow\` warning.`),
235
+ paper: z.enum(SCRAPE_PDF_PAPER_VALUES).optional().describe("Paper size for `layout: \"pages\"`: `a4` (default) or `letter`. Not allowed with `single_page`."),
236
+ landscape: z.boolean().optional().describe("Turn the paper sideways, for `layout: \"pages\"`. Defaults to false. Not allowed with `single_page`."),
237
+ media: z.enum(SCRAPE_PDF_MEDIA_VALUES).default("screen").describe("`screen` (default): the page as it looks on screen. `print`: the site's own print style, which on many sites hides menus and images; a site without one looks as on screen.")
238
+ }).strict().superRefine((pdf, ctx) => {
239
+ if (pdf.layout !== "single_page") return;
240
+ for (const field of ["paper", "landscape"]) if (pdf[field] !== void 0) ctx.addIssue({
241
+ code: "custom",
242
+ path: [field],
243
+ message: `${field} is only allowed with layout "pages"; leave it out for "single_page".`
244
+ });
245
+ });
246
+
226
247
  //#endregion
227
248
  //#region src/schemas/ScrapeScreenshotSchemas.ts
228
249
  const Schema_ApiScrapeScreenshotType = z.enum(["viewport", "full_page"]).describe("Screenshot mode: viewport (visible area) or full_page (entire page)");
229
250
  const Schema_ScrapeScreenshotDeviceMode = z.enum(["desktop", "mobile"]).describe("Device mode to emulate for viewport sizing");
251
+ const Schema_ScrapeScreenshotColorScheme = z.enum(["light", "dark"]).describe("Color scheme to ask the site for: light or dark");
230
252
  const Schema_ScrapeScreenshotBeforeAction = z.discriminatedUnion("type", [z.object({
231
253
  type: z.literal("wait").describe("Wait for a duration before capturing"),
232
254
  ms: z.number().int().nonnegative().describe("Milliseconds to wait")
@@ -260,7 +282,7 @@ const API_PROXY_TIER_VALUES = [
260
282
  "advanced",
261
283
  "auto"
262
284
  ];
263
- const Schema_ApiProxyType = z.enum(API_PROXY_TIER_VALUES).default("auto").describe("Proxy tier: basic, advanced, or auto. Defaults to auto (automatic selection: basic tier first, escalates to advanced on failure).");
285
+ const Schema_ApiProxyType = z.enum(API_PROXY_TIER_VALUES).default("auto").describe("Proxy tier: basic, advanced, or auto. Defaults to auto: we start with the lightest way to get the page and step up our effort on our own when a site needs more, and bill the tier that delivered.");
264
286
  const Schema_ApiScrapeViewport = z.object({
265
287
  width: z.number().int().min(16).max(1e4).describe("Viewport width in pixels (16–10000)"),
266
288
  height: z.number().int().min(16).max(1e4).describe("Viewport height in pixels (16–10000)"),
@@ -270,18 +292,20 @@ const Schema_ApiScrapeFormatScreenshot = z.object({
270
292
  type: Schema_ApiScrapeScreenshotType.describe("Screenshot capture mode"),
271
293
  viewport: Schema_ApiScrapeViewport.optional().describe("Custom viewport dimensions; uses device_mode defaults if omitted"),
272
294
  device_mode: Schema_ScrapeScreenshotDeviceMode.default(DEFAULT_SCRAPE_SCREENSHOT_DEVICE_MODE).describe("Emulate desktop or mobile device viewport"),
295
+ color_scheme: Schema_ScrapeScreenshotColorScheme.optional().describe("`light` (default) or `dark`. `dark` asks the site for its dark theme, if it has one, and the screenshot shows it. A site without a dark theme, or whose dark theme is only a switch on the page, looks the same as with `light`. When the request also asks for `extract.pdf`, the PDF shows the dark theme too. No extra credits."),
273
296
  actions_before: z.array(Schema_ScrapeScreenshotBeforeAction).max(5).default([]).describe("Actions to perform before taking the screenshot (wait, scroll)"),
274
297
  actions_after: z.array(Schema_ScrapeScreenshotAfterAction).max(1).default([]).describe("Actions to perform after taking the screenshot (e.g. slice into tiles)")
275
298
  }).strict().superRefine(refineScrapeScreenshotActionsBefore).describe("Screenshot capture configuration");
276
299
  const Schema_ApiScrapeCache = z.object({ max_age: z.union([z.number().int().nonnegative(), z.iso.datetime()]).default(DEFAULT_API_SCRAPE_CACHE_MAX_AGE_SECONDS).describe("Maximum cache age in seconds, or an ISO 8601 datetime cutoff") }).strict().describe("Cache settings for the scrape request");
277
300
  const Schema_ApiScrapeExtract = z.object({
278
301
  metadata: z.boolean().default(true).describe("Extract page metadata (title, description, OG tags, etc.) from the page head"),
279
- cleaned_html: z.boolean().default(true).describe("Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed"),
280
- markdown: z.boolean().default(false).describe("Extract page content as clean Markdown"),
302
+ cleaned_html: z.boolean().default(false).describe("Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed"),
303
+ markdown: z.boolean().default(true).describe("Extract page content as clean Markdown"),
281
304
  raw_html: z.boolean().default(false).describe("Return the raw, unprocessed HTML, up to 10,000,000 characters of page body. A larger body is truncated at a tag boundary and the response carries a `raw_html_truncated` warning."),
282
305
  links: z.boolean().default(false).describe("Extract links found on the page, up to 30,000 per page. Beyond that the array is truncated and the response carries a `links_truncated` warning."),
283
306
  images: z.boolean().default(false).describe("Extract inline images found on the page, up to 10,000 per page. Beyond that the array is truncated and the response carries an `inline_images_truncated` warning."),
284
307
  screenshot: Schema_ApiScrapeFormatScreenshot.optional().describe("Capture a screenshot of the page"),
308
+ pdf: Schema_ApiScrapePdf.optional().describe("Save the page as a PDF: a real document with selectable text and working links, backgrounds printed, and no header or footer added. `{}` takes every default. The request runs in a browser. The response carries a top-level `pdf` with a signed link that expires 24 hours after the scrape. It costs what a screenshot costs, and a PDF and a screenshot in one request are billed once. A cached copy of the page answers only when it has a PDF made with the same settings; `cache.max_age: 0` always makes a new one. In rare cases the PDF cannot be made: the rest of the scrape still comes back, with the `pdf_unavailable` warning, and the request costs what it costs without the PDF. A PDF-only request (every other format off, `markdown` and `metadata` included) on a page that cannot be made into a PDF is a 422 `unsupported_pdf_output`, not billed. An async job in that case, or one that asked only for a PDF and got none, ends `failed` and is not billed. A PDF on its own is made with the light theme. When the same request also asks for a screenshot with `color_scheme: \"dark\"`, the PDF is dark too."),
285
309
  elements: Schema_ScrapeElements.optional().describe(`Named values to read from the page by CSS selector, returned in the top-level \`elements\` field under the same names. Each value is either a selector string (the text of the first match) or an object with \`selector\`, \`output\`, \`attribute\` and \`all\`. \`fields\` (instead of \`output\`) turns each match into an object of named values read inside that match (the selector \`:scope\` reads the match itself, for example the matched element's own href), so a list of products can return a title, price and url per product. A name with no match is null, or [] with \`all: true\`. Read after cleanup; \`<script>\` and \`<style>\` tags are not part of it. An invalid selector is a 400. No extra credits, also when the page comes from cache. Limits and selector rules: ${ELEMENTS_DOCS_URL}.`)
286
310
  }).strict().describe("Which content formats to extract from the scraped page");
287
311
  const Schema_ApiScrapeLocation = z.object({
@@ -290,11 +314,11 @@ const Schema_ApiScrapeLocation = z.object({
290
314
  }).strict().describe("Optional locale + country emulation for the scrape");
291
315
  const Schema_ApiScrapeRequest = z.object({
292
316
  url: z.string().describe("The URL to scrape. Known tracking parameters are removed before the page is fetched, so they are neither sent to the target site nor part of the cache key. Every other query parameter is kept verbatim and is part of the cache key."),
293
- extract: Schema_ApiScrapeExtract.prefault({}).describe("Which content formats to extract. Defaults to metadata + cleaned_html."),
317
+ extract: Schema_ApiScrapeExtract.prefault({}).describe("Which content formats to extract. Defaults to markdown + metadata."),
294
318
  cache: Schema_ApiScrapeCache.optional().describe("Cache settings for this request"),
295
- require_js: z.boolean().default(false).describe("Use a headless browser to render JavaScript before scraping"),
319
+ require_js: z.boolean().default(false).describe("Go straight to a headless browser to render JavaScript before scraping. Without it, we still move to a browser on our own when a page needs one; set it when you already know the page needs JavaScript, to save time."),
296
320
  cleanup: Schema_ApiScrapeCleanup.prefault({ ...DEFAULT_SCRAPE_CLEANUP }),
297
- proxy: Schema_ApiProxyType.describe("Proxy tier to use for fetching"),
321
+ proxy: Schema_ApiProxyType.describe("Proxy tier. Defaults to auto: we start with the lightest way to get the page and step up our effort on our own when a site needs more (a stronger proxy, a real browser, or both), and bill the tier that delivered. basic or advanced pins the tier."),
298
322
  location: Schema_ApiScrapeLocation.optional(),
299
323
  zero_data_retention: z.boolean().optional().describe("Keeps the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. Adds 1 credit. Must be enabled for your organization. See https://crawlbrulee.com/docs/zero-data-retention."),
300
324
  headers: Schema_ScrapeCustomHeaders.optional().describe(`Your own HTTP headers to send to the site with the request, for example \`Authorization\`, an api key, or a fixed \`User-Agent\` that the site has on an allowlist. Sent only to the origin of \`url\` (same scheme, host and port), or to its https version when \`url\` is http, and not on a redirect to another origin. Up to ${10} headers; headers and cookies together up to ${MAX_SCRAPE_CUSTOM_HEADERS_AND_COOKIES_BYTES} bytes. Values are printable ASCII, with no space or tab at either end. Headers a browser doesn't let a web page set can't be set here either (a 400 names the header). Use \`cookies\` for cookies and \`location.locale\` for the language. Never put secrets in the \`User-Agent\`. Your own \`User-Agent\` can lower the success rate, and the response carries the \`custom_user_agent\` warning. A \`Referer\` must be the full http or https url of a public page, with no username or password; it is sent the way a browser sends it after a click on that page. A request with headers or cookies never reads from or writes to the cache. On a plain http url they travel unencrypted. ${HEADERS_AND_COOKIES_CHAT_NOTE} See ${HEADERS_AND_COOKIES_DOCS_URL}.`),
@@ -306,13 +330,11 @@ const Schema_ApiScrapeRequest = z.object({
306
330
  const Schema_ApiMapLocation = z.object({ country: z.string().regex(/^([a-zA-Z]{2}|europe)$/i, "country must be a 2-letter ISO 3166-1 alpha-2 code, 'eu', or 'europe'").optional().describe("ISO 3166-1 alpha-2 (e.g. 'us', 'de', 'br'; case-insensitive) hint for proxy egress country. Also accepts 'eu' (random EU member state) or 'europe' (random European state incl. UK and non-EU).") }).strict().describe("Optional country emulation for the map");
307
331
  const DEFAULT_API_MAP_CACHE_MAX_AGE_SECONDS = 604800;
308
332
  /**
309
- * How many URLs a /map call discovers and stores when the caller names no
310
- * limit. Sitemap discovery stops here, so the default is real crawl work, not
311
- * a slice taken at the end — 5000 covers the whole site for the great majority
312
- * of roots while keeping an unparameterised call cheap and fast.
333
+ * How many entries a /map call finds when the caller names no limit. Discovery
334
+ * stops here, so the default is real work, not a slice taken at the end.
313
335
  */
314
- const DEFAULT_API_MAP_MAX_URLS = 5e3;
315
- const MAX_API_MAP_MAX_URLS = 1e5;
336
+ const DEFAULT_API_MAP_MAX_RESULTS = 5e3;
337
+ const MAX_API_MAP_MAX_RESULTS = 1e5;
316
338
  const DEFAULT_API_MAP_PAGE_LIMIT = 5e3;
317
339
  const MAX_API_MAP_PAGE_LIMIT = 1e4;
318
340
  const Schema_ApiMapTypes = z.object({
@@ -321,13 +343,24 @@ const Schema_ApiMapTypes = z.object({
321
343
  external: z.boolean().default(true).describe("Include external links (different domains)")
322
344
  }).describe("Filter which link types to include in the map");
323
345
  const Schema_ApiMapCache = z.object({ max_age: z.union([z.number().int().nonnegative(), z.iso.datetime()]).default(DEFAULT_API_MAP_CACHE_MAX_AGE_SECONDS).describe("Maximum cache age in seconds, or an ISO 8601 datetime cutoff") }).describe("Cache settings for the map request");
346
+ const DEFAULT_API_MAP_DEPTH = 3;
347
+ const API_MAP_ENTRIES_VALUES = [
348
+ "pages",
349
+ "sitemaps",
350
+ "all"
351
+ ];
324
352
  const Schema_ApiMapRequest = z.object({
325
353
  url: z.string().describe("The website URL to map. Mapping always targets the site root, so the path, query string and fragment are dropped; known tracking parameters are removed before the request is processed."),
326
- proxy: Schema_ApiProxyType.default("auto").describe("Proxy tier to use for fetching"),
327
- sitemap_only: z.boolean().default(false).describe("Only use sitemap.xml — skip homepage link extraction"),
354
+ proxy: Schema_ApiProxyType.default("auto").describe("Proxy tier. Defaults to auto: we start on basic and move to a stronger proxy on our own when a site needs it, and bill the tier that delivered. basic or advanced pins the tier."),
355
+ sitemap_only: z.boolean().default(false).describe("Use the sitemaps only: leave out the links found on the home page. A map with `modified_since` or `sitemap_url` never adds home page links."),
328
356
  types: Schema_ApiMapTypes.optional().describe("Filter which link types to include"),
329
357
  cache: Schema_ApiMapCache.optional().describe("Cache settings for this request"),
330
- max_urls: z.number().int().positive().max(MAX_API_MAP_MAX_URLS).default(DEFAULT_API_MAP_MAX_URLS).describe("Maximum number of URLs to discover and store in the map. Default 5000, maximum 100000. Sitemap discovery stops as soon as this many URLs have been found, so a smaller value is a faster and lighter crawl, not just a smaller answer."),
358
+ max_results: z.number().int().positive().max(MAX_API_MAP_MAX_RESULTS).optional().describe(`The most entries the map finds, counting only the kind asked for in \`entries\`. Default ${DEFAULT_API_MAP_MAX_RESULTS}, maximum ${MAX_API_MAP_MAX_RESULTS}. Discovery stops as soon as this many have been found, so a smaller value is a faster and lighter map, not just a smaller answer.`),
359
+ max_urls: z.number().int().positive().max(MAX_API_MAP_MAX_RESULTS).optional().describe("Deprecated: use `max_results`, which means the same. This tool sends it as `max_results`. When both are given, only `max_results` is used."),
360
+ sitemap_url: z.string().optional().describe("Start from this sitemap file, as a full http or https address. It must be on the same site as `url`, or on a host the site's robots.txt names, such as a CDN. Left out: start from the site's own top sitemap files."),
361
+ depth: z.number().int().nonnegative().optional().describe(`How many levels of nested sitemaps to follow: 0 to 3, default ${3}. With \`sitemap_url\`, level 0 is that file, and it is read. Without it, level 0 is the list of the site's top sitemap files, which 0 returns without reading their entries. A top file found at one of the usual addresses can still show as \`sitemap_index\`, because finding it shows its kind. A sitemap index holds only sitemap files, so reading one at a low depth with \`entries: "pages"\` returns no pages: ask with \`entries: "sitemaps"\` or a higher depth. \`depth: 1\` with \`entries: "sitemaps"\` lists the site's top sitemap files and every file they list, in one call. A listed file shows as \`sitemap\` until a map opens it, even when it is a sitemap index itself. To go deeper, read a listed file with \`sitemap_url\`, or ask with a higher depth. A large site can reach \`max_results\` or a discovery limit first; \`discovery_cap_reason\` then says which.`),
362
+ entries: z.enum(API_MAP_ENTRIES_VALUES).optional().describe("What to return: `pages` (page addresses, the default), `sitemaps` (sitemap files, of type `sitemap` or `sitemap_index`) or `all` (both)."),
363
+ modified_since: z.union([z.iso.date(), z.iso.datetime({ offset: true })]).optional().describe("Return only entries whose `lastmod` is at or after this date (`2026-11-01`, the start of that day in UTC) or date and time (ISO 8601, with a time zone). An entry with no `lastmod` is left out, so every entry returned matches; links found on the home page have none, so none is returned. Every sitemap file is read whatever its own `lastmod`, and each entry returned, a page or a sitemap file, is judged by its own `lastmod`. With `entries: \"sitemaps\"`, a sitemap file is returned when its own `lastmod` matches, not when a page in it does: to find the pages that changed, ask with `entries: \"pages\"`. A request with this field is always mapped fresh: it never reads from or adds to the cache, so `cache.max_age` does nothing, and it is priced as a fresh map."),
331
364
  page: z.number().int().positive().default(1).describe("Page number for paginated results"),
332
365
  limit: z.number().int().positive().max(MAX_API_MAP_PAGE_LIMIT).default(DEFAULT_API_MAP_PAGE_LIMIT).describe("Number of URLs to return per page. Default 5000, maximum 10000."),
333
366
  location: Schema_ApiMapLocation.optional(),
@@ -373,6 +406,10 @@ const Schema_ApiScreenshotResponse = z.looseObject({
373
406
  properties: Schema_ApiScreenshotProperties.describe("Image properties for the full screenshot"),
374
407
  slices: z.array(Schema_ApiScreenshotSlice).optional().describe("Individual tile slices (present when slice action_after was requested)")
375
408
  });
409
+ const Schema_ApiPdfResponse = z.looseObject({
410
+ url: z.string().describe("Signed link to download the PDF. It expires 24 hours after the scrape (for an async scrape, 24 hours after you submitted it; fetching the result again does not extend it). Download the file, do not keep the link"),
411
+ bytes: z.number().int().describe("Size of the PDF file in bytes")
412
+ });
376
413
  const Schema_ApiPageInlineImgItem = z.looseObject({
377
414
  url: z.string().describe("Absolute URL of the image"),
378
415
  alt: z.string().nullable().describe("Alt text of the image, or null if not set")
@@ -428,7 +465,7 @@ const Schema_ApiScrapeMeta = z.looseObject({
428
465
  const Schema_ApiScrapeSuccessResponse = z.looseObject({
429
466
  url: z.string().describe("The URL that was actually scraped, after any redirects, in normalized form — the base that links, images, and internal labels are computed against"),
430
467
  requested_url: z.string().describe("The URL you requested, echoed verbatim — before any redirects"),
431
- page_status_code: z.number().int().optional().describe("The HTTP status the site answered with for the final page, after redirects. Check it before you trust the content. A page the site served is a successful result whatever its status: a 404 or 503 page comes back with its content here, not as an error, so a 404 means the markdown is the site's \"not found\" page, not the page you asked for. Billing follows this status: 2xx and 4xx pages are billed, except 403, 407, 408, 429 and 451; 5xx pages are never billed. Older api versions do not send it; they only returned pages that loaded normally."),
468
+ page_status_code: z.number().int().optional().describe("The HTTP status the site answered with for the final page, after redirects. Check it before you trust the content. A page the site served is a successful result whatever its status: a 404 or 503 page comes back with its content here, not as an error, so a 404 means the markdown is the site's \"not found\" page, not the page you asked for. Billing follows this status: 2xx and 4xx pages are billed, except 403, 407, 408, 429, 444 and 451; 5xx pages are never billed. Older api versions do not send it; they only returned pages that loaded normally."),
432
469
  content_type: z.string().optional().describe("Content-Type header returned by the server"),
433
470
  unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
434
471
  markdown: z.string().optional().describe("Page content converted to clean Markdown"),
@@ -438,8 +475,9 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
438
475
  images: z.array(Schema_ApiPageInlineImgItem).optional().describe("Inline images found on the page"),
439
476
  links: z.array(Schema_ApiPageLink).optional().describe("Links found on the page"),
440
477
  screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
478
+ pdf: Schema_ApiPdfResponse.optional().describe("PDF of the page, if requested with `extract.pdf` and it could be made"),
441
479
  metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
442
- warnings: z.array(z.string()).optional().describe("Non-error notices about the scrape. Truncation codes — `screenshot_truncated` (long page exceeded the scrolling-screenshot height cap), `links_truncated` / `inline_images_truncated` (page had more links/images than the per-page extraction caps), `raw_html_truncated` (rendered HTML exceeded the per-page size budget) — mean the field is present but capped. `elements_truncated` means at least one `elements` value hit a limit: a list was cut at 1,000 matches, the request reached 10,000 matches in total, or a value did not fit the ~1 MB of values allowed per request (that value is then null, never cut short). Unavailability codes — `links_unavailable` / `inline_images_unavailable` / `metadata_unavailable` — mean that optional field could not be extracted and was omitted (null/empty) while the rest of the scrape succeeded, so an empty field carrying one of these does NOT mean the page had none. `screenshot_unavailable` means a screenshot was asked for, but the page came back from the http engine without one. `custom_user_agent` means the request set its own `User-Agent` header; this can lower the success rate. Stable string codes — clients can switch on them. Warnings are stored with the result: async result fetches and cache hits carry them too, filtered to the fields the request asked for. `metadata_truncated` is retired and no longer sent: metadata has no size limit of its own now, though the code can still appear on results stored before that change."),
480
+ warnings: z.array(z.string()).optional().describe("Non-error notices about the scrape. Truncation codes — `screenshot_truncated` (long page exceeded the scrolling-screenshot height cap), `links_truncated` / `inline_images_truncated` (page had more links/images than the per-page extraction caps), `raw_html_truncated` (rendered HTML exceeded the per-page size budget) — mean the field is present but capped. `elements_truncated` means at least one `elements` value hit a limit: a list was cut at 1,000 matches, the request reached 10,000 matches in total, or a value did not fit the ~1 MB of values allowed per request (that value is then null, never cut short). Unavailability codes — `links_unavailable` / `inline_images_unavailable` / `metadata_unavailable` — mean that optional field could not be extracted and was omitted (null/empty) while the rest of the scrape succeeded, so an empty field carrying one of these does NOT mean the page had none. `screenshot_unavailable` means a screenshot was asked for, but the page came back from the http engine without one. `pdf_unavailable` means a PDF was asked for, but the page came back without one: it came back from the http engine, the site answered an empty error page, the PDF was over 50 MB, or it did not finish in time. `pdf_single_page_overflow` means a `single_page` PDF was taller than the 15,000 px page limit and goes on over more pages. `custom_user_agent` means the request set its own `User-Agent` header; this can lower the success rate. Stable string codes — clients can switch on them. Warnings are stored with the result: async result fetches and cache hits carry them too, filtered to the fields the request asked for. `metadata_truncated` is retired and no longer sent: metadata has no size limit of its own now, though the code can still appear on results stored before that change."),
443
481
  response_meta: Schema_ApiResponseMeta.describe("Request-level metadata. `response_meta.usage` reports what the request cost (total_credit_cost and its parts), the billed engine and the resolved proxy tier.")
444
482
  });
445
483
 
@@ -448,7 +486,7 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
448
486
  const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
449
487
  /** Which limit stopped sitemap discovery first. The FIRST limit to fire wins. */
450
488
  const DISCOVERY_CAP_REASONS = [
451
- "max_urls",
489
+ "max_results",
452
490
  "time",
453
491
  "file_budget",
454
492
  "depth",
@@ -464,22 +502,33 @@ const Schema_ApiMapUsageMeta = z.looseObject({
464
502
  engine: openEnum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
465
503
  proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
466
504
  });
467
- const Schema_ApiMapLinkItem = z.looseObject({ url: z.string().describe("The discovered URL") });
505
+ const API_MAP_LINK_TYPE_VALUES = [
506
+ "page",
507
+ "sitemap",
508
+ "sitemap_index"
509
+ ];
510
+ const Schema_ApiMapLinkItem = z.looseObject({
511
+ url: z.string().describe("The discovered URL"),
512
+ type: openEnum(API_MAP_LINK_TYPE_VALUES).optional().describe("`page` for a page address. `sitemap_index` for a sitemap file that this map found to be a sitemap index (a file that lists other sitemap files), whether it read all of the file, part of it, or only its start. Such a file can also be in `unread_sitemaps` when this map did not read all of it. `sitemap` for any other sitemap file: one that lists pages, or one whose kind this map did not learn (past `depth`, or it could not be read). Read a `sitemap` or `sitemap_index` file with `sitemap_url` in another call (a file on another site only when the site's robots.txt names its host). A link found on the home page is a `page`."),
513
+ lastmod: z.string().nullable().optional().describe("The entry's `lastmod` from the sitemap, as an ISO 8601 date and time in UTC, or null when the sitemap gives none or it cannot be read. Always null for a link found on the home page.")
514
+ });
468
515
  const Schema_ApiMapPagination = z.looseObject({
469
516
  page: z.number().int().positive().describe("Current page number"),
470
517
  limit: z.number().int().positive().describe("Number of items per page"),
471
- total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
518
+ total: z.number().int().nonnegative().describe("How many links this answer holds across all its pages, after `entries`, `types` and `max_results` are applied"),
472
519
  total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
473
520
  has_more: z.boolean().describe("Whether more pages are available")
474
521
  });
475
522
  const Schema_ApiMapTruncation = z.looseObject({
476
- storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
477
- response_capped: z.boolean().describe("Whether more links were eligible than max_urls, so the list was trimmed. Discovery itself stops at max_urls, so this is normally true only when home-page links pushed the total past it. See discovery_cap_reason for a discovery stop."),
478
- total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
479
- total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
523
+ storage_capped: z.boolean().describe("Whether the map found more than 100,000 URLs, the most one map holds, so some were left out."),
524
+ response_capped: z.boolean().describe("Whether more links were eligible than max_results, so the list was trimmed. Discovery itself stops at max_results, so this is normally true only when home-page links pushed the total past it. See discovery_cap_reason for a discovery stop."),
525
+ total_before_max_results: z.number().int().nonnegative().optional().describe("Total links found before applying max_results. Older api versions do not send it."),
526
+ total_before_max_urls: z.number().int().nonnegative().optional().describe("Deprecated: use total_before_max_results, which always has the same value. The api stops sending it on 2027-02-01."),
527
+ total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs found, before the 100,000-URL limit of one map"),
480
528
  discovery_capped: z.boolean().describe("Whether sitemap discovery stopped before it had read every sitemap file it found. When true, the site has more pages than this map lists."),
481
529
  sitemaps_skipped: z.number().int().nonnegative().describe("How many sitemap files were skipped or only partly read during discovery, because a file was too large, could not be fetched, or the discovery limits were reached."),
482
- discovery_cap_reason: openEnum(DISCOVERY_CAP_REASONS).nullable().describe("Which limit stopped sitemap discovery first, or null when nothing stopped it. \"max_urls\" means your own max_urls was reached — ask again with a higher one to get more. \"time\" means discovery ran out of its time budget, \"file_budget\" that the site has more sitemap files than one request reads, \"depth\" that its sitemap indexes nest too deeply, and \"file_size\" that a sitemap file was too large to read. \"unread_files\" means a sitemap file the site publishes could not be read at all this time — the request for it failed or was rate limited, or the file was not a readable sitemap. Only \"max_urls\" is a limit you can raise from the request; \"unread_files\" is often temporary, so asking again later can return more.")
530
+ unread_sitemaps: z.array(z.string()).optional().describe("The sitemap files this call knew about but did not read whole, because a limit stopped it, the file could not be read, or its download broke off. Read each one with `sitemap_url` in another call, except a file that says it is over the size limit: no call reads that one. Files past `depth` are listed here. Up to 1000 addresses; empty when every file was read. When the list is full, ask the same with `entries: \"sitemaps\"` to get every sitemap file as a link. Older api versions do not send it."),
531
+ discovery_cap_reason: openEnum(DISCOVERY_CAP_REASONS).nullable().describe("Which limit stopped sitemap discovery first, or null when nothing stopped it. \"max_results\": your own max_results was reached; ask again with a higher one to get more. \"depth\": there are sitemap files past the `depth` you asked for, listed in unread_sitemaps; this is the answer to the depth you chose, not a fault (with `depth: 0` it is how a site's top sitemap files are listed, and with `depth: 1` and `entries: \"sitemaps\"` how the top files and every file they list are listed). Read each file past it with `sitemap_url`, or ask with a higher depth. \"time\": discovery ran out of its time budget. \"file_budget\": the site has more sitemap files than one request reads. \"file_size\": a sitemap file was too large. A file that says up front that it is over the size limit is not downloaded: nothing comes back from it, and it is listed in unread_sitemaps. A file of pages that turns out too large while it is read returns the links in its first part. Any other file that turns out too large, such as a sitemap index, returns nothing and is listed. \"unread_files\": a sitemap file the site publishes could not be read whole this time (the request failed or was rate limited, the download broke off, or the file was not a readable sitemap). When a download broke off, the links received before the break are returned, and the file is listed in unread_sitemaps. Asking again later can return more.")
483
532
  });
484
533
  const Schema_ApiMapResult = z.looseObject({
485
534
  links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
@@ -493,20 +542,43 @@ const Schema_ApiMapResult = z.looseObject({
493
542
  //#endregion
494
543
  //#region src/tools/map.ts
495
544
  const DESCRIPTION$6 = [
496
- "Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
497
- "link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
498
- "Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
499
- "scraping selected pages.",
500
- "`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
501
- "stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
502
- "A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
503
- "signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
504
- "\"max_urls\", ask again with a higher `max_urls` to get more; \"unread_files\" means a sitemap file",
505
- "could not be read this time and is often temporary, so asking again later can return more;",
506
- "\"time\", \"file_budget\", \"depth\" and \"file_size\" mean the site itself is big, slow or deep and a",
507
- "retry will not help. `discovery_capped` says discovery stopped early, `sitemaps_skipped` how",
508
- "many sitemap files were skipped or only partly read.",
545
+ "Build (or fetch a cached) link map of a website from its sitemaps, plus the links on its home",
546
+ "page. Returns paginated links, each { url, type, lastmod }: `type` is `page`, `sitemap` or",
547
+ "`sitemap_index` (a sitemap file that lists other sitemap files); read either kind of sitemap",
548
+ "file with `sitemap_url` in another call. `lastmod` is the date from the sitemap (UTC) or null.",
549
+ "Filterable by link type (internal /",
550
+ "external / subdomain). Use this to enumerate a site before scraping selected pages.",
551
+ "By default the map reads the site's top sitemap files and 2 levels of nested ones (`depth` 3),",
552
+ "returns pages (`entries`) and finds up to 5000 of them (`max_results`, max 100000).",
553
+ "`max_results` is a discovery budget, not a trim at the end: discovery stops as soon as that many",
554
+ "entries of the asked kind are found, so a smaller value is a faster map. A map stopped that way",
555
+ "returns exactly `max_results` links with `response_capped` false; the signal that the site has",
556
+ "more is `response_meta.truncation.discovery_cap_reason`. \"max_results\": ask again with a higher",
557
+ "`max_results`. \"depth\": there are sitemap files past the `depth` you asked for, listed in",
558
+ "`unread_sitemaps`; that is the answer to your depth, not a fault. \"unread_files\": a sitemap file",
559
+ "could not be read whole this time, often temporary, so asking again later can return more. \"time\",",
560
+ "\"file_budget\" and \"file_size\": the site is big or slow, and a retry will not help.",
561
+ "`discovery_capped` says discovery stopped early, `sitemaps_skipped` how many sitemap files were",
562
+ "skipped or only partly read.",
509
563
  "`limit` (default 5000, max 10000) only pages the answer.",
564
+ "To map a very large site in several calls, first ask with `depth: 1` and `entries: \"sitemaps\"`:",
565
+ "one call lists the top sitemap files and every file they list (a listed file shows as `sitemap`",
566
+ "until a map reads it, even when it is an index). Then read each file with `sitemap_url` (on the",
567
+ "same site as `url`, or on a host the site's robots.txt names, such as a CDN), or ask with a",
568
+ "higher `depth`.",
569
+ "`truncation.unread_sitemaps` names the files a call did not read whole, to read next (except",
570
+ "a file that says it is over the size limit: no call reads that one); when that",
571
+ "list is full, ask the same with `entries: \"sitemaps\"` to get every sitemap file as a link, paged.",
572
+ "A sitemap index holds only sitemap files, so reading one at a low `depth` with",
573
+ "`entries: \"pages\"` returns no pages: ask with `entries: \"sitemaps\"` or a higher `depth`.",
574
+ "`modified_since` keeps only entries whose `lastmod` is at or after it: an entry with no",
575
+ "`lastmod` is left out (so no home page link is returned). Every sitemap file is read whatever",
576
+ "its own date, and each entry is judged by its own `lastmod`. With `entries: \"sitemaps\"` a file",
577
+ "is returned by its own date, so ask with `entries: \"pages\"` to find the pages that changed.",
578
+ "A request with `modified_since` is always mapped fresh, never from the",
579
+ "cache, and priced as a fresh map. A map with `modified_since` or `sitemap_url` adds no home page",
580
+ "links. If the site answers 429 on the file in `sitemap_url`, on its robots.txt or on one of",
581
+ "its top sitemap files, the tool returns `too_many_requests` (not billed): wait and retry.",
510
582
  "Set `zero_data_retention: true` to keep the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. It adds 1 credit and must be enabled for the organization (else a `zero_data_retention_not_enabled` error, not billed). See https://crawlbrulee.com/docs/zero-data-retention.",
511
583
  "Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
512
584
  "map-then-scrape stays on one host. Results are ordered with the most useful links first.",
@@ -514,7 +586,9 @@ const DESCRIPTION$6 = [
514
586
  "`proxy_multiplier` + `zero_data_retention_credit_cost`, plus `engine` and `proxy` (the resolved tier, never `auto`). Map has no screenshot slicing and no",
515
587
  "`page_status_code`: it reads many files, not one page. A map that found nothing because the site",
516
588
  "answered only with statuses we don't bill (a 5xx, for example), or not at all, is empty and free. If the site cannot be reached, the",
517
- "tool can return a `target_unreachable` error (HTTP 502, not billed): retry later or check the URL."
589
+ "tool can return a `target_unreachable` error (HTTP 502, not billed): retry later or check the URL.",
590
+ "The full walk-through for a very large or deep site:",
591
+ "https://crawlbrulee.com/docs/map/sitemaps#map-a-very-large-or-deep-site-in-several-calls."
518
592
  ].join(" ");
519
593
  function registerMapTool(server, getClient) {
520
594
  server.registerTool("map", {
@@ -522,27 +596,46 @@ function registerMapTool(server, getClient) {
522
596
  description: DESCRIPTION$6,
523
597
  inputSchema: Schema_ApiMapRequest.shape,
524
598
  outputSchema: Schema_ApiMapResult
525
- }, (args) => runTool(async () => await getClient().map(args)));
599
+ }, (args) => runTool(async () => await getClient().map(toApiBody(args))));
600
+ }
601
+ /**
602
+ * `max_urls` is the old name of `max_results`. The tool sends it as `max_results`, so it
603
+ * keeps working after the api drops the old name. When both are given, `max_results` wins,
604
+ * as it does in the api.
605
+ */
606
+ function toApiBody(args) {
607
+ const { max_urls: maxUrls, ...body } = args;
608
+ if (maxUrls !== void 0 && body.max_results === void 0) return {
609
+ ...body,
610
+ max_results: maxUrls
611
+ };
612
+ return body;
526
613
  }
527
614
 
528
615
  //#endregion
529
616
  //#region src/tools/scrape.ts
530
617
  const DESCRIPTION$5 = [
531
618
  "Fetch a single URL via the crawlbrulee scraping API and return the requested content",
532
- "(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
619
+ "(markdown, cleaned HTML, raw HTML, links, images, screenshot, PDF, page metadata in `metadata`).",
533
620
  "Use this for one-shot page extraction. For full-site discovery use the `map` tool first.",
534
621
  "To pull named values such as prices, titles or links, set `extract.elements` (name → CSS selector)",
535
622
  "instead of reading the whole markdown: they come back in `elements`, for no extra credits.",
623
+ "Markdown and metadata stay on unless you set `markdown: false` and `metadata: false`, so send",
624
+ "both to get only the values.",
536
625
  "Rules: https://crawlbrulee.com/docs/scrape/targeted-extraction.",
537
626
  "Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
538
627
  "with for the final page. A page the site served is a successful result whatever its status, so a",
539
628
  "404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
540
629
  "site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
541
- "407, 408, 429 and 451; 5xx pages are never billed.",
630
+ "407, 408, 429, 444 and 451; 5xx pages are never billed.",
542
631
  "If the site cannot be reached at all the tool returns a `target_unreachable` error (HTTP 502,",
543
632
  "not billed): retry later or check the URL.",
544
- "Screenshot URLs in the response are signed download links that expire 24 hours after the scrape:",
545
- "download the image if you need it later; do not keep the link.",
633
+ "Set `extract.pdf: {}` to save the page as a PDF (pages or one long page, a4 or letter); it",
634
+ "costs what a screenshot costs, and both together are billed once. Set",
635
+ "`extract.screenshot.color_scheme: \"dark\"` for a screenshot of the site's dark theme, at no extra",
636
+ "cost; the PDF then shows it too.",
637
+ "Screenshot and PDF URLs in the response are signed download links that expire 24 hours after the",
638
+ "scrape: download the file if you need it later; do not keep the link.",
546
639
  "The response also carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
547
640
  "`proxy_multiplier` + `screenshot_slicing_credit_cost` + `zero_data_retention_credit_cost`, plus `engine` and `proxy` (the resolved",
548
641
  "tier — never `auto`). `engine` is the billed engine (`http`, `browser`, `screenshot`, `cache`); a",
@@ -561,7 +654,9 @@ const DESCRIPTION$5 = [
561
654
  "while the rest of the scrape succeeded, so do NOT conclude the page had no links/images/metadata",
562
655
  "— re-run the scrape instead. An empty field with no such warning does mean the page had none.",
563
656
  "`screenshot_unavailable` means a screenshot was asked for, but the page came back from the http",
564
- "engine without one. `custom_user_agent` means the request set its own `User-Agent` header; this",
657
+ "engine without one. `pdf_unavailable` means the PDF could not be made; the rest is there.",
658
+ "`pdf_single_page_overflow` means a `single_page` PDF was too tall for one page and goes on over",
659
+ "more pages. `custom_user_agent` means the request set its own `User-Agent` header; this",
565
660
  "can lower the success rate.",
566
661
  HEADERS_AND_COOKIES_TOOL_TEXT
567
662
  ].join(" ");
@@ -610,6 +705,7 @@ const DESCRIPTION$4 = [
610
705
  "Poll the job with `scrape_status` and fetch the page with `scrape_result` once done.",
611
706
  "Takes `extract.elements` like `scrape` (named values by CSS selector, no extra credits); the",
612
707
  "result carries them in `elements`. Rules: https://crawlbrulee.com/docs/scrape/targeted-extraction.",
708
+ "Takes `extract.pdf` (save the page as a PDF) and `extract.screenshot.color_scheme` like `scrape`.",
613
709
  "Optionally attach a per-job completion `webhook`: we deliver a single",
614
710
  "signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
615
711
  "in production), and echoes your opaque `webhook.metadata` back in the delivery",
@@ -630,18 +726,22 @@ function registerScrapeAsyncTool(server, getClient) {
630
726
  //#region src/tools/scrapeResult.ts
631
727
  const DESCRIPTION$3 = [
632
728
  "Fetch the extracted content of a completed async scrape job (the same result shape as the",
633
- "synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot,",
729
+ "synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot, PDF,",
634
730
  "page metadata in `metadata`, values from `extract.elements` in `elements`, and",
635
731
  "`response_meta.usage`). Errors if the job is still `pending`/`running` — check",
636
732
  "`scrape_status` first (status `done`) before calling this.",
733
+ "A `failed` job has no result: this returns `job_failed`. A job that asked only for a",
734
+ "screenshot, a PDF or both, on a content type that cannot be captured (such as JSON or plain",
735
+ "text), returns `unsupported_screenshot_output` or `unsupported_pdf_output` instead, as `scrape`",
736
+ "does. Either way the job is not billed.",
637
737
  "Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
638
738
  "with for the final page. A page the site served is a successful result whatever its status, so a",
639
739
  "404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
640
740
  "site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
641
- "407, 408, 429 and 451; 5xx pages are never billed.",
642
- "A job answers for 24 hours after it was submitted, then returns `not_found`. Screenshot URLs are",
643
- "signed download links that expire at the same moment, however late you fetch the result: download",
644
- "the image if you need it later."
741
+ "407, 408, 429, 444 and 451; 5xx pages are never billed.",
742
+ "A job answers for 24 hours after it was submitted, then returns `not_found`. Screenshot and PDF",
743
+ "URLs are signed download links that expire at the same moment, however late you fetch the",
744
+ "result: download the file if you need it later."
645
745
  ].join(" ");
646
746
  function registerScrapeResultTool(server, getClient) {
647
747
  server.registerTool("scrape_result", {
@@ -661,7 +761,9 @@ const DESCRIPTION$2 = [
661
761
  "resolved proxy tier) once it is `done`. A job whose page the site served ends `done` even when",
662
762
  "that page is a 404 or 503 — read `page_status_code` in the result. A job that could not reach",
663
763
  "the site at all ends `failed` (the `error` text is a general message, not the reason) and is not",
664
- "billed; retry later or check the url. Poll this until the status is",
764
+ "billed; retry later or check the url. A job that asked only for a screenshot, a PDF or both",
765
+ "and got no capture also ends `failed` and is not billed; `scrape_result` then names the reason.",
766
+ "Poll this until the status is",
665
767
  "`done`, then call `scrape_result` to fetch",
666
768
  "the page. If you registered a completion webhook on submit you can skip polling and react",
667
769
  "to the delivery instead. A job answers for 24 hours after it was submitted; after that this",
@@ -730,7 +832,7 @@ function registerWhoamiTool(server, getClient) {
730
832
  //#endregion
731
833
  //#region src/version.ts
732
834
  const SERVER_NAME = "crawlbrulee";
733
- const SERVER_VERSION = "1.4.0";
835
+ const SERVER_VERSION = "1.6.0";
734
836
 
735
837
  //#endregion
736
838
  //#region src/server.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlbrulee/mcp",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "mcpName": "io.github.crawlbrulee/mcp",
5
5
  "description": "official mcp server for crawlbrulee — EU-native web scraping for AI agents & developers. native scrape and map tools for your agent.",
6
6
  "keywords": [
@@ -63,7 +63,7 @@
63
63
  "prepublishOnly": "pnpm verify"
64
64
  },
65
65
  "dependencies": {
66
- "@crawlbrulee/sdk": "^1.4.0",
66
+ "@crawlbrulee/sdk": "^1.6.0",
67
67
  "@modelcontextprotocol/sdk": "^1.32.1",
68
68
  "zod": "^4.0.0"
69
69
  },