@crawlbrulee/mcp 1.5.0 → 2.0.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.
- package/README.md +23 -9
- package/dist/index.js +175 -73
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -171,6 +171,20 @@ the pdf link is a signed link that expires 24 hours after the scrape, like a scr
|
|
|
171
171
|
}
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
**do things on the page first with `actions`.** close a popup, press "load more", or wait for the part you need, then read the page. the actions run in order: `wait`, `scroll`, `wait_for` (an element), `hover` and `click`, with css selectors. up to 12, and 60 seconds for the whole list. they run after `cleanup`, so the ads, popups and cookie banners it removes are gone first. a click that loads a new page is followed: you get that page, and the rest of the list runs there. a list with an action that does something runs in a browser, is billed as a browser scrape, and never uses the cache. the actions cost no extra credits.
|
|
175
|
+
|
|
176
|
+
```jsonc
|
|
177
|
+
{
|
|
178
|
+
"url": "https://example.com/products",
|
|
179
|
+
"actions": [
|
|
180
|
+
{ "type": "click", "selector": "#load-more" },
|
|
181
|
+
{ "type": "wait_for", "selector": ".product:nth-child(40)" },
|
|
182
|
+
],
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
the response `actions` says what happened to each one: `ok`, `failed`, `skipped` (it failed, but you marked it `optional`) or `not_run`. a failed action stops the list, and the page still comes back as it was then, with the `actions_incomplete` warning. when you know the next page's url, such as `?page=2`, scrape it directly instead of clicking to it: the page loads once, so it comes back faster, and it can come from the cache. a long list on a slow page can take longer than your app waits for a tool reply: use `scrape_async` for it. if a try fails and is tried again, the actions run again from the start, so don't use them for anything that must happen only once, such as an order. to fill in and send a form (type text into a field, pick an option in a dropdown), call the http api: this server doesn't offer those actions. see [actions](https://crawlbrulee.com/docs/scrape/actions).
|
|
187
|
+
|
|
174
188
|
**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:
|
|
175
189
|
|
|
176
190
|
```jsonc
|
|
@@ -195,7 +209,7 @@ the pdf link is a signed link that expires 24 hours after the scrape, like a scr
|
|
|
195
209
|
}
|
|
196
210
|
```
|
|
197
211
|
|
|
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 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)).
|
|
212
|
+
**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)).
|
|
199
213
|
|
|
200
214
|
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:
|
|
201
215
|
|
|
@@ -258,7 +272,7 @@ fetch the extracted content of a completed async job — the same result shape a
|
|
|
258
272
|
|
|
259
273
|
### `map`
|
|
260
274
|
|
|
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` or `sitemap
|
|
275
|
+
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
276
|
|
|
263
277
|
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
278
|
|
|
@@ -266,7 +280,7 @@ a plain map (`{ "url": "https://example.com" }`) returns pages. it reads the sit
|
|
|
266
280
|
| ---------------- | ------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
267
281
|
| `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
282
|
| `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, or both.
|
|
283
|
+
| `entries` | `pages` \| `sitemaps` \| `all` | `pages` | what to return: page addresses, sitemap files (`sitemap` or `sitemap_index`), or both. |
|
|
270
284
|
| `modified_since` | a date, or ISO 8601 with a zone | none | only entries whose `lastmod` is at or after it (see below). |
|
|
271
285
|
| `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
286
|
| `limit` | `1` to `10000` | `5000` | links per page of the answer. it only pages the answer. |
|
|
@@ -310,22 +324,22 @@ the response's `response_meta` carries `pagination`, `truncation`, and a `usage`
|
|
|
310
324
|
`discovery_cap_reason` is one of these, or `null` when nothing stopped discovery:
|
|
311
325
|
|
|
312
326
|
- `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.
|
|
327
|
+
- `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
328
|
- `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
329
|
- `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
330
|
|
|
317
331
|
#### map a very large site in several calls
|
|
318
332
|
|
|
319
|
-
a very large or deep site is mapped in several calls
|
|
333
|
+
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
334
|
|
|
321
335
|
```jsonc
|
|
322
|
-
// 1. list the site's top sitemap files
|
|
323
|
-
{ "url": "https://example.com", "depth":
|
|
324
|
-
// 2. read one of them
|
|
336
|
+
// 1. list the site's top sitemap files and every file they list
|
|
337
|
+
{ "url": "https://example.com", "depth": 1, "entries": "sitemaps" }
|
|
338
|
+
// 2. read one of them: a `sitemap` link, or a `sitemap_index` link that is also in unread_sitemaps
|
|
325
339
|
{ "url": "https://example.com", "sitemap_url": "https://example.com/sitemap-products-1.xml.gz" }
|
|
326
340
|
```
|
|
327
341
|
|
|
328
|
-
`modified_since` leaves out every entry with no `lastmod`, and a map with it is always fresh, so `cache.max_age` does nothing. see [find what changed since a date](https://crawlbrulee.com/docs/map/sitemaps#find-what-changed-since-a-date).
|
|
342
|
+
`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
343
|
|
|
330
344
|
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
345
|
|
package/dist/index.js
CHANGED
|
@@ -99,24 +99,135 @@ function textErrorResult(text) {
|
|
|
99
99
|
|
|
100
100
|
//#endregion
|
|
101
101
|
//#region src/schemas/ScrapeScreenshotRules.ts
|
|
102
|
-
const MAX_SCRAPE_SCREENSHOT_TOTAL_WAIT_MS = 2e4;
|
|
103
|
-
const MAX_SCRAPE_SCREENSHOT_TOTAL_SCROLL_PIXELS = 5e4;
|
|
104
102
|
const DEFAULT_SCRAPE_SCREENSHOT_DEVICE_MODE = "desktop";
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/schemas/openEnum.ts
|
|
106
|
+
/**
|
|
107
|
+
* A response enum the api may extend later. The known values still show up in the
|
|
108
|
+
* tool's output schema, so a reader sees them, but any string is accepted: a value
|
|
109
|
+
* added on the server must not make a validating host refuse the whole result.
|
|
110
|
+
*
|
|
111
|
+
* Output only. Request enums stay closed, so a typo in tool input is still caught.
|
|
112
|
+
*/
|
|
113
|
+
function openEnum(values) {
|
|
114
|
+
return z.union([z.enum(values), z.string()]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/schemas/ApiScrapeActionsSchemas.ts
|
|
119
|
+
const MAX_SCRAPE_ACTIONS = 12;
|
|
120
|
+
const SCRAPE_ACTIONS_TIME_BUDGET_MS = 6e4;
|
|
121
|
+
const MAX_SCRAPE_ACTION_SELECTOR_LENGTH = 500;
|
|
122
|
+
const MAX_SCRAPE_ACTION_POINT = 1e4;
|
|
123
|
+
const SCRAPE_ACTION_ELEMENT_WAIT_MS = 5e3;
|
|
124
|
+
const SCRAPE_WAIT_FOR_TIMEOUT_MS = 1e4;
|
|
125
|
+
const SCRAPE_SCROLL_EDGES = [
|
|
126
|
+
"top",
|
|
127
|
+
"bottom",
|
|
128
|
+
"left",
|
|
129
|
+
"right"
|
|
130
|
+
];
|
|
131
|
+
const SCRAPE_ACTION_TYPES = [
|
|
132
|
+
"wait",
|
|
133
|
+
"scroll",
|
|
134
|
+
"wait_for",
|
|
135
|
+
"hover",
|
|
136
|
+
"click"
|
|
137
|
+
];
|
|
138
|
+
const SCRAPE_ACTION_STATUSES = [
|
|
139
|
+
"ok",
|
|
140
|
+
"failed",
|
|
141
|
+
"skipped",
|
|
142
|
+
"not_run"
|
|
143
|
+
];
|
|
144
|
+
const Schema_ScrapeActionSelector = z.string().min(1).max(500);
|
|
145
|
+
const Schema_ScrapeActionOptional = z.boolean().optional().describe("When true, a failure of this action does not stop the list: it is reported as `skipped` and the next action runs. A page that moves on to another page during the action still stops the list. Defaults to false.");
|
|
146
|
+
const Schema_ScrapeActionWait = z.object({
|
|
147
|
+
type: z.literal("wait").describe("Wait for a set time"),
|
|
148
|
+
ms: z.number().int().nonnegative().max(SCRAPE_ACTIONS_TIME_BUDGET_MS).describe("Milliseconds to wait"),
|
|
149
|
+
optional: Schema_ScrapeActionOptional
|
|
150
|
+
}).strict();
|
|
151
|
+
const Schema_ScrapeActionScroll = z.object({
|
|
152
|
+
type: z.literal("scroll").describe("Scroll the page"),
|
|
153
|
+
pixels: z.number().int().optional().describe("Pixels to scroll down (negative scrolls up). Use either `pixels` or `to`, not both."),
|
|
154
|
+
to: z.string().min(1).max(500).optional().describe(`Where to scroll: ${SCRAPE_SCROLL_EDGES.map((edge) => `\`${edge}\``).join(", ")} of the page, or a CSS selector, which brings the first match to the middle of the window (it waits up to ${SCRAPE_ACTION_ELEMENT_WAIT_MS / 1e3} s for the element). Use either \`pixels\` or \`to\`, not both.`),
|
|
155
|
+
duration_ms: z.number().int().nonnegative().max(SCRAPE_ACTIONS_TIME_BUDGET_MS).optional().describe("How long the scroll takes, in milliseconds. A slow scroll gives images further down the page time to load on the way. 0 jumps at once. Without it, the page scrolls at a steady pace, taking up to 5 s."),
|
|
156
|
+
optional: Schema_ScrapeActionOptional
|
|
157
|
+
}).strict();
|
|
158
|
+
const Schema_ScrapeActionWaitFor = z.object({
|
|
159
|
+
type: z.literal("wait_for").describe("Wait for an element to appear"),
|
|
160
|
+
selector: Schema_ScrapeActionSelector.describe(`CSS selector. The action waits until the first match is on the page and visible, for up to ${SCRAPE_WAIT_FOR_TIMEOUT_MS / 1e3} s; after that it fails.`),
|
|
161
|
+
optional: Schema_ScrapeActionOptional
|
|
162
|
+
}).strict();
|
|
163
|
+
const Schema_ScrapeActionHover = z.object({
|
|
164
|
+
type: z.literal("hover").describe("Move the mouse over an element, or to a point. Desktop only: on a mobile device it is skipped."),
|
|
165
|
+
selector: Schema_ScrapeActionSelector.optional().describe("CSS selector: the mouse goes to the first match, brought into view first. Use either `selector` or `x` and `y`."),
|
|
166
|
+
x: z.number().int().nonnegative().max(MAX_SCRAPE_ACTION_POINT).optional().describe("A point in the visible window, in pixels from its left edge. Needs `y`."),
|
|
167
|
+
y: z.number().int().nonnegative().max(MAX_SCRAPE_ACTION_POINT).optional().describe("A point in the visible window, in pixels from its top edge. Needs `x`."),
|
|
168
|
+
optional: Schema_ScrapeActionOptional
|
|
169
|
+
}).strict();
|
|
170
|
+
const Schema_ScrapeActionClick = z.object({
|
|
171
|
+
type: z.literal("click").describe("Click an element (a tap on a mobile device)"),
|
|
172
|
+
selector: Schema_ScrapeActionSelector.describe("CSS selector: the first match on the page itself (not inside a frame or a shadow root), brought into view first."),
|
|
173
|
+
optional: Schema_ScrapeActionOptional
|
|
174
|
+
}).strict();
|
|
175
|
+
const UNKNOWN_ACTION_TYPE_MESSAGE = `unknown action type; use one of ${SCRAPE_ACTION_TYPES.join(", ")}`;
|
|
176
|
+
const Schema_ApiScrapeAction = z.discriminatedUnion("type", [
|
|
177
|
+
Schema_ScrapeActionWait,
|
|
178
|
+
Schema_ScrapeActionScroll,
|
|
179
|
+
Schema_ScrapeActionWaitFor,
|
|
180
|
+
Schema_ScrapeActionHover,
|
|
181
|
+
Schema_ScrapeActionClick
|
|
182
|
+
], { error: (issue) => {
|
|
183
|
+
const path = issue.path ?? [];
|
|
184
|
+
if (issue.code === "invalid_union" && path[path.length - 1] === "type") return UNKNOWN_ACTION_TYPE_MESSAGE;
|
|
185
|
+
} });
|
|
186
|
+
function refineScrapeAction(action, index, ctx) {
|
|
187
|
+
if (action.type === "scroll") {
|
|
188
|
+
if (action.pixels !== void 0 === (action.to !== void 0)) ctx.addIssue({
|
|
189
|
+
code: "custom",
|
|
190
|
+
path: [index],
|
|
191
|
+
message: "scroll needs either pixels or to, not both"
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (action.type === "hover") {
|
|
196
|
+
const hasSelector = action.selector !== void 0;
|
|
197
|
+
const hasPoint = action.x !== void 0 || action.y !== void 0;
|
|
198
|
+
if (hasSelector === hasPoint) ctx.addIssue({
|
|
199
|
+
code: "custom",
|
|
200
|
+
path: [index],
|
|
201
|
+
message: "hover needs either selector or x and y, not both"
|
|
202
|
+
});
|
|
203
|
+
else if (hasPoint && (action.x === void 0 || action.y === void 0)) ctx.addIssue({
|
|
204
|
+
code: "custom",
|
|
205
|
+
path: [index],
|
|
206
|
+
message: "hover needs both x and y"
|
|
207
|
+
});
|
|
114
208
|
}
|
|
115
|
-
return {
|
|
116
|
-
totalWaitMs,
|
|
117
|
-
totalAbsoluteScrollPixels
|
|
118
|
-
};
|
|
119
209
|
}
|
|
210
|
+
/** The time a list asks for outright: its waits and the scroll durations it set. */
|
|
211
|
+
function statedTimeMs(actions) {
|
|
212
|
+
let totalMs = 0;
|
|
213
|
+
for (const action of actions) if (action.type === "wait") totalMs += action.ms;
|
|
214
|
+
else if (action.type === "scroll") totalMs += action.duration_ms ?? 0;
|
|
215
|
+
return totalMs;
|
|
216
|
+
}
|
|
217
|
+
const Schema_ApiScrapeActions = z.array(Schema_ApiScrapeAction).max(12).superRefine((actions, ctx) => {
|
|
218
|
+
actions.forEach((action, index) => refineScrapeAction(action, index, ctx));
|
|
219
|
+
const statedMs = statedTimeMs(actions);
|
|
220
|
+
if (statedMs > 6e4) ctx.addIssue({
|
|
221
|
+
code: "custom",
|
|
222
|
+
path: [],
|
|
223
|
+
message: `The waits and scroll durations add up to ${statedMs} ms; the whole list may take at most ${SCRAPE_ACTIONS_TIME_BUDGET_MS} ms.`
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
/** One entry of the response's `actions` report. Open enums: see openEnum. */
|
|
227
|
+
const Schema_ApiScrapeActionReportEntry = z.looseObject({
|
|
228
|
+
type: openEnum(SCRAPE_ACTION_TYPES).describe("The action type, as sent"),
|
|
229
|
+
status: openEnum(SCRAPE_ACTION_STATUSES).describe("`ok`: it was done. `failed`: it could not be done (for example its element was not found or was covered by something else, or the page a click loaded failed to load). `skipped`: it could not be done, but it was `optional`, so the list went on; a `hover` is always skipped on a mobile device, which has no mouse. `not_run`: the list never got to it.")
|
|
230
|
+
});
|
|
120
231
|
|
|
121
232
|
//#endregion
|
|
122
233
|
//#region src/schemas/ScrapeCleanupSchemas.ts
|
|
@@ -249,30 +360,10 @@ const Schema_ApiScrapePdf = z.object({
|
|
|
249
360
|
const Schema_ApiScrapeScreenshotType = z.enum(["viewport", "full_page"]).describe("Screenshot mode: viewport (visible area) or full_page (entire page)");
|
|
250
361
|
const Schema_ScrapeScreenshotDeviceMode = z.enum(["desktop", "mobile"]).describe("Device mode to emulate for viewport sizing");
|
|
251
362
|
const Schema_ScrapeScreenshotColorScheme = z.enum(["light", "dark"]).describe("Color scheme to ask the site for: light or dark");
|
|
252
|
-
const Schema_ScrapeScreenshotBeforeAction = z.discriminatedUnion("type", [z.object({
|
|
253
|
-
type: z.literal("wait").describe("Wait for a duration before capturing"),
|
|
254
|
-
ms: z.number().int().nonnegative().describe("Milliseconds to wait")
|
|
255
|
-
}), z.object({
|
|
256
|
-
type: z.literal("scroll").describe("Scroll the page before capturing"),
|
|
257
|
-
pixels: z.number().int().describe("Pixels to scroll (positive = down, negative = up)")
|
|
258
|
-
})]);
|
|
259
363
|
const Schema_ScrapeScreenshotAfterAction = z.object({
|
|
260
364
|
type: z.literal("slice").describe("Slice the screenshot into horizontal tiles"),
|
|
261
365
|
height: z.number().int().min(500).describe("Height of each tile in pixels (minimum 500)")
|
|
262
366
|
});
|
|
263
|
-
function refineScrapeScreenshotActionsBefore(value, ctx) {
|
|
264
|
-
const totals = getScrapeScreenshotBeforeActionTotals(value.actions_before);
|
|
265
|
-
if (totals.totalWaitMs > 2e4) ctx.addIssue({
|
|
266
|
-
code: "custom",
|
|
267
|
-
path: ["actions_before"],
|
|
268
|
-
message: `Total wait time cannot exceed ${MAX_SCRAPE_SCREENSHOT_TOTAL_WAIT_MS}ms.`
|
|
269
|
-
});
|
|
270
|
-
if (totals.totalAbsoluteScrollPixels > 5e4) ctx.addIssue({
|
|
271
|
-
code: "custom",
|
|
272
|
-
path: ["actions_before"],
|
|
273
|
-
message: `Total absolute scroll distance cannot exceed ${MAX_SCRAPE_SCREENSHOT_TOTAL_SCROLL_PIXELS}px.`
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
367
|
|
|
277
368
|
//#endregion
|
|
278
369
|
//#region src/schemas/ApiScrapeRequest.ts
|
|
@@ -282,7 +373,7 @@ const API_PROXY_TIER_VALUES = [
|
|
|
282
373
|
"advanced",
|
|
283
374
|
"auto"
|
|
284
375
|
];
|
|
285
|
-
const Schema_ApiProxyType = z.enum(API_PROXY_TIER_VALUES).default("auto").describe("Proxy tier: basic, advanced, or auto. Defaults to auto
|
|
376
|
+
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.");
|
|
286
377
|
const Schema_ApiScrapeViewport = z.object({
|
|
287
378
|
width: z.number().int().min(16).max(1e4).describe("Viewport width in pixels (16–10000)"),
|
|
288
379
|
height: z.number().int().min(16).max(1e4).describe("Viewport height in pixels (16–10000)"),
|
|
@@ -293,9 +384,8 @@ const Schema_ApiScrapeFormatScreenshot = z.object({
|
|
|
293
384
|
viewport: Schema_ApiScrapeViewport.optional().describe("Custom viewport dimensions; uses device_mode defaults if omitted"),
|
|
294
385
|
device_mode: Schema_ScrapeScreenshotDeviceMode.default(DEFAULT_SCRAPE_SCREENSHOT_DEVICE_MODE).describe("Emulate desktop or mobile device viewport"),
|
|
295
386
|
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."),
|
|
296
|
-
actions_before: z.array(Schema_ScrapeScreenshotBeforeAction).max(5).default([]).describe("Actions to perform before taking the screenshot (wait, scroll)"),
|
|
297
387
|
actions_after: z.array(Schema_ScrapeScreenshotAfterAction).max(1).default([]).describe("Actions to perform after taking the screenshot (e.g. slice into tiles)")
|
|
298
|
-
}).strict().
|
|
388
|
+
}).strict().describe("Screenshot capture configuration");
|
|
299
389
|
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");
|
|
300
390
|
const Schema_ApiScrapeExtract = z.object({
|
|
301
391
|
metadata: z.boolean().default(true).describe("Extract page metadata (title, description, OG tags, etc.) from the page head"),
|
|
@@ -316,12 +406,13 @@ const Schema_ApiScrapeRequest = z.object({
|
|
|
316
406
|
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."),
|
|
317
407
|
extract: Schema_ApiScrapeExtract.prefault({}).describe("Which content formats to extract. Defaults to markdown + metadata."),
|
|
318
408
|
cache: Schema_ApiScrapeCache.optional().describe("Cache settings for this request"),
|
|
319
|
-
require_js: z.boolean().default(false).describe("
|
|
409
|
+
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."),
|
|
320
410
|
cleanup: Schema_ApiScrapeCleanup.prefault({ ...DEFAULT_SCRAPE_CLEANUP }),
|
|
321
|
-
proxy: Schema_ApiProxyType.describe("Proxy tier to
|
|
411
|
+
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."),
|
|
322
412
|
location: Schema_ApiScrapeLocation.optional(),
|
|
323
413
|
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."),
|
|
324
414
|
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}.`),
|
|
415
|
+
actions: Schema_ApiScrapeActions.optional().describe(`Things to do on the page, in order, before it is read: \`wait\`, \`scroll\`, \`wait_for\` (an element), \`hover\` and \`click\`, with CSS selectors. Every output, the screenshot and the PDF included, shows the page as the actions left it. A list with an action that does something runs in a browser, so it is billed as a browser scrape, and never reads from or writes to the cache. The actions run after \`cleanup\`: ads, popups and cookie banners (with \`cleanup.ads_and_popups\` on) and the elements in \`cleanup.exclude_selectors\` are removed first, also from a page a click loads. A popup that opens later can still be in the way of a click and make it fail, so click the popup's close button first. Up to ${12} actions, and ${SCRAPE_ACTIONS_TIME_BUDGET_MS / 1e3} s for the whole list, waits and scroll durations included. An action that fails stops the list: the page still comes back as it is then, billed as usual, with the \`actions_incomplete\` warning; mark an action \`optional\` to go on past it. The response reports each action in \`actions\`. A click that loads a new page is followed: the response is that page (its url, its \`page_status_code\`, its content), and the rest of the list runs there. A click that opens a new tab is ignored. When you know the next page's url, such as \`?page=2\`, scrape that url directly instead of clicking to it: the page loads once, so it comes back faster, and it can come from the cache. If a try fails and we try again, the actions run again from the start, so do not use them for anything that must happen only once, such as an order. The actions themselves cost no extra credits. To fill in and send a form (type text into a field, pick an option in a dropdown), call the HTTP API: this server does not offer those actions.`),
|
|
325
416
|
cookies: Schema_ScrapeCookies.optional().describe(`Your own cookies to send to the site with the request. Each is a \`name\` and a \`value\`, sent only to the host of \`url\`. Cookies the site sets while redirecting are not kept. Up to ${20} cookies, each up to ${MAX_SCRAPE_COOKIE_BYTES} bytes (name and value), counted toward the limit on \`headers\`. A value may not hold ";" or start or end with a space. A \`__Secure-\`, \`__Host-\` or \`__Http-\` cookie needs an https url. A request with headers or cookies never reads from or writes to the cache. ${HEADERS_AND_COOKIES_CHAT_NOTE} See ${HEADERS_AND_COOKIES_DOCS_URL}.`)
|
|
326
417
|
}).strict();
|
|
327
418
|
|
|
@@ -351,35 +442,22 @@ const API_MAP_ENTRIES_VALUES = [
|
|
|
351
442
|
];
|
|
352
443
|
const Schema_ApiMapRequest = z.object({
|
|
353
444
|
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."),
|
|
354
|
-
proxy: Schema_ApiProxyType.default("auto").describe("Proxy tier to
|
|
445
|
+
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
446
|
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."),
|
|
356
447
|
types: Schema_ApiMapTypes.optional().describe("Filter which link types to include"),
|
|
357
448
|
cache: Schema_ApiMapCache.optional().describe("Cache settings for this request"),
|
|
358
449
|
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
450
|
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
451
|
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
|
|
362
|
-
entries: z.enum(API_MAP_ENTRIES_VALUES).optional().describe("What to return: `pages` (page addresses, the default), `sitemaps` (sitemap files) 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.
|
|
452
|
+
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.`),
|
|
453
|
+
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)."),
|
|
454
|
+
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."),
|
|
364
455
|
page: z.number().int().positive().default(1).describe("Page number for paginated results"),
|
|
365
456
|
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."),
|
|
366
457
|
location: Schema_ApiMapLocation.optional(),
|
|
367
458
|
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.")
|
|
368
459
|
});
|
|
369
460
|
|
|
370
|
-
//#endregion
|
|
371
|
-
//#region src/schemas/openEnum.ts
|
|
372
|
-
/**
|
|
373
|
-
* A response enum the api may extend later. The known values still show up in the
|
|
374
|
-
* tool's output schema, so a reader sees them, but any string is accepted: a value
|
|
375
|
-
* added on the server must not make a validating host refuse the whole result.
|
|
376
|
-
*
|
|
377
|
-
* Output only. Request enums stay closed, so a typo in tool input is still caught.
|
|
378
|
-
*/
|
|
379
|
-
function openEnum(values) {
|
|
380
|
-
return z.union([z.enum(values), z.string()]);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
461
|
//#endregion
|
|
384
462
|
//#region src/schemas/ApiScrapeResponse.ts
|
|
385
463
|
const Schema_ApiViewport = z.looseObject({
|
|
@@ -465,7 +543,7 @@ const Schema_ApiScrapeMeta = z.looseObject({
|
|
|
465
543
|
const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
466
544
|
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"),
|
|
467
545
|
requested_url: z.string().describe("The URL you requested, echoed verbatim — before any redirects"),
|
|
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 and 451; 5xx pages are never billed. Older api versions do not send it; they only returned pages that loaded normally."),
|
|
546
|
+
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."),
|
|
469
547
|
content_type: z.string().optional().describe("Content-Type header returned by the server"),
|
|
470
548
|
unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
|
|
471
549
|
markdown: z.string().optional().describe("Page content converted to clean Markdown"),
|
|
@@ -477,7 +555,8 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
|
477
555
|
screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
|
|
478
556
|
pdf: Schema_ApiPdfResponse.optional().describe("PDF of the page, if requested with `extract.pdf` and it could be made"),
|
|
479
557
|
metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
|
|
480
|
-
|
|
558
|
+
actions: z.array(Schema_ApiScrapeActionReportEntry).optional().describe("What happened to each action the request sent, in the same order: its `type` and its `status`. Present only when the request sent actions. When any action is `failed` or `not_run`, `warnings` has `actions_incomplete`. When the page could not be loaded in a browser and was fetched without one, every action that acts on the page is `not_run`."),
|
|
559
|
+
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. `actions_incomplete` means at least one action in `actions` failed or never ran: `actions` says which, and the page is the one the actions left. 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."),
|
|
481
560
|
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.")
|
|
482
561
|
});
|
|
483
562
|
|
|
@@ -502,10 +581,14 @@ const Schema_ApiMapUsageMeta = z.looseObject({
|
|
|
502
581
|
engine: openEnum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
|
|
503
582
|
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
|
|
504
583
|
});
|
|
505
|
-
const API_MAP_LINK_TYPE_VALUES = [
|
|
584
|
+
const API_MAP_LINK_TYPE_VALUES = [
|
|
585
|
+
"page",
|
|
586
|
+
"sitemap",
|
|
587
|
+
"sitemap_index"
|
|
588
|
+
];
|
|
506
589
|
const Schema_ApiMapLinkItem = z.looseObject({
|
|
507
590
|
url: z.string().describe("The discovered URL"),
|
|
508
|
-
type: openEnum(API_MAP_LINK_TYPE_VALUES).optional().describe("`page` for a page address
|
|
591
|
+
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`."),
|
|
509
592
|
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.")
|
|
510
593
|
});
|
|
511
594
|
const Schema_ApiMapPagination = z.looseObject({
|
|
@@ -524,7 +607,7 @@ const Schema_ApiMapTruncation = z.looseObject({
|
|
|
524
607
|
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."),
|
|
525
608
|
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."),
|
|
526
609
|
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."),
|
|
527
|
-
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). \"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.")
|
|
610
|
+
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.")
|
|
528
611
|
});
|
|
529
612
|
const Schema_ApiMapResult = z.looseObject({
|
|
530
613
|
links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
|
|
@@ -539,8 +622,10 @@ const Schema_ApiMapResult = z.looseObject({
|
|
|
539
622
|
//#region src/tools/map.ts
|
|
540
623
|
const DESCRIPTION$6 = [
|
|
541
624
|
"Build (or fetch a cached) link map of a website from its sitemaps, plus the links on its home",
|
|
542
|
-
"page. Returns paginated links, each { url, type, lastmod }: `type` is `page
|
|
543
|
-
"`
|
|
625
|
+
"page. Returns paginated links, each { url, type, lastmod }: `type` is `page`, `sitemap` or",
|
|
626
|
+
"`sitemap_index` (a sitemap file that lists other sitemap files); read either kind of sitemap",
|
|
627
|
+
"file with `sitemap_url` in another call. `lastmod` is the date from the sitemap (UTC) or null.",
|
|
628
|
+
"Filterable by link type (internal /",
|
|
544
629
|
"external / subdomain). Use this to enumerate a site before scraping selected pages.",
|
|
545
630
|
"By default the map reads the site's top sitemap files and 2 levels of nested ones (`depth` 3),",
|
|
546
631
|
"returns pages (`entries`) and finds up to 5000 of them (`max_results`, max 100000).",
|
|
@@ -555,17 +640,21 @@ const DESCRIPTION$6 = [
|
|
|
555
640
|
"`discovery_capped` says discovery stopped early, `sitemaps_skipped` how many sitemap files were",
|
|
556
641
|
"skipped or only partly read.",
|
|
557
642
|
"`limit` (default 5000, max 10000) only pages the answer.",
|
|
558
|
-
"To map a very large site in several calls,
|
|
559
|
-
"
|
|
560
|
-
"
|
|
643
|
+
"To map a very large site in several calls, first ask with `depth: 1` and `entries: \"sitemaps\"`:",
|
|
644
|
+
"one call lists the top sitemap files and every file they list (a listed file shows as `sitemap`",
|
|
645
|
+
"until a map reads it, even when it is an index). Then read each file with `sitemap_url` (on the",
|
|
646
|
+
"same site as `url`, or on a host the site's robots.txt names, such as a CDN), or ask with a",
|
|
647
|
+
"higher `depth`.",
|
|
561
648
|
"`truncation.unread_sitemaps` names the files a call did not read whole, to read next (except",
|
|
562
649
|
"a file that says it is over the size limit: no call reads that one); when that",
|
|
563
650
|
"list is full, ask the same with `entries: \"sitemaps\"` to get every sitemap file as a link, paged.",
|
|
564
651
|
"A sitemap index holds only sitemap files, so reading one at a low `depth` with",
|
|
565
652
|
"`entries: \"pages\"` returns no pages: ask with `entries: \"sitemaps\"` or a higher `depth`.",
|
|
566
653
|
"`modified_since` keeps only entries whose `lastmod` is at or after it: an entry with no",
|
|
567
|
-
"`lastmod` is left out (so no home page link is returned)
|
|
568
|
-
"
|
|
654
|
+
"`lastmod` is left out (so no home page link is returned). Every sitemap file is read whatever",
|
|
655
|
+
"its own date, and each entry is judged by its own `lastmod`. With `entries: \"sitemaps\"` a file",
|
|
656
|
+
"is returned by its own date, so ask with `entries: \"pages\"` to find the pages that changed.",
|
|
657
|
+
"A request with `modified_since` is always mapped fresh, never from the",
|
|
569
658
|
"cache, and priced as a fresh map. A map with `modified_since` or `sitemap_url` adds no home page",
|
|
570
659
|
"links. If the site answers 429 on the file in `sitemap_url`, on its robots.txt or on one of",
|
|
571
660
|
"its top sitemap files, the tool returns `too_many_requests` (not billed): wait and retry.",
|
|
@@ -617,13 +706,24 @@ const DESCRIPTION$5 = [
|
|
|
617
706
|
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
618
707
|
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
619
708
|
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
620
|
-
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
709
|
+
"407, 408, 429, 444 and 451; 5xx pages are never billed.",
|
|
621
710
|
"If the site cannot be reached at all the tool returns a `target_unreachable` error (HTTP 502,",
|
|
622
711
|
"not billed): retry later or check the URL.",
|
|
623
712
|
"Set `extract.pdf: {}` to save the page as a PDF (pages or one long page, a4 or letter); it",
|
|
624
713
|
"costs what a screenshot costs, and both together are billed once. Set",
|
|
625
714
|
"`extract.screenshot.color_scheme: \"dark\"` for a screenshot of the site's dark theme, at no extra",
|
|
626
715
|
"cost; the PDF then shows it too.",
|
|
716
|
+
"Set `actions` to do things on the page before it is read: `wait`, `scroll`, `wait_for` (an",
|
|
717
|
+
"element), `hover` and `click`, with CSS selectors; up to 12, and 60 seconds for the whole list.",
|
|
718
|
+
"They run after `cleanup`, so a cookie banner it removes is gone first. A click that loads a new",
|
|
719
|
+
"page is followed: the response is that page, and the rest of the list runs there. The response",
|
|
720
|
+
"`actions` reports each one (`ok`, `failed`, `skipped`, `not_run`); `actions_incomplete` in",
|
|
721
|
+
"`warnings` means one failed or never ran, and the page is the one the actions left. When you know",
|
|
722
|
+
"the next page's URL, scrape it directly instead of clicking to it. A long list on a slow page can",
|
|
723
|
+
"take longer than your app waits for a tool reply: use `scrape_async` for it. If a try fails and",
|
|
724
|
+
"is tried again, the actions run again from the start, so do not use them for anything that must",
|
|
725
|
+
"happen only once, such as an order. To fill in and send a form (type text into a field, pick",
|
|
726
|
+
"an option in a dropdown), call the HTTP API: this server does not offer those actions.",
|
|
627
727
|
"Screenshot and PDF URLs in the response are signed download links that expire 24 hours after the",
|
|
628
728
|
"scrape: download the file if you need it later; do not keep the link.",
|
|
629
729
|
"The response also carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
@@ -647,7 +747,7 @@ const DESCRIPTION$5 = [
|
|
|
647
747
|
"engine without one. `pdf_unavailable` means the PDF could not be made; the rest is there.",
|
|
648
748
|
"`pdf_single_page_overflow` means a `single_page` PDF was too tall for one page and goes on over",
|
|
649
749
|
"more pages. `custom_user_agent` means the request set its own `User-Agent` header; this",
|
|
650
|
-
"can lower the success rate.",
|
|
750
|
+
"can lower the success rate. `actions_incomplete` means an action failed or never ran.",
|
|
651
751
|
HEADERS_AND_COOKIES_TOOL_TEXT
|
|
652
752
|
].join(" ");
|
|
653
753
|
function registerScrapeTool(server, getClient) {
|
|
@@ -696,6 +796,8 @@ const DESCRIPTION$4 = [
|
|
|
696
796
|
"Takes `extract.elements` like `scrape` (named values by CSS selector, no extra credits); the",
|
|
697
797
|
"result carries them in `elements`. Rules: https://crawlbrulee.com/docs/scrape/targeted-extraction.",
|
|
698
798
|
"Takes `extract.pdf` (save the page as a PDF) and `extract.screenshot.color_scheme` like `scrape`.",
|
|
799
|
+
"Takes `actions` like `scrape` (wait, scroll, wait_for, hover, click); the result reports each",
|
|
800
|
+
"one in `actions`. A long action list on a slow page is a good fit for this tool.",
|
|
699
801
|
"Optionally attach a per-job completion `webhook`: we deliver a single",
|
|
700
802
|
"signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
|
|
701
803
|
"in production), and echoes your opaque `webhook.metadata` back in the delivery",
|
|
@@ -728,7 +830,7 @@ const DESCRIPTION$3 = [
|
|
|
728
830
|
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
729
831
|
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
730
832
|
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
731
|
-
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
833
|
+
"407, 408, 429, 444 and 451; 5xx pages are never billed.",
|
|
732
834
|
"A job answers for 24 hours after it was submitted, then returns `not_found`. Screenshot and PDF",
|
|
733
835
|
"URLs are signed download links that expire at the same moment, however late you fetch the",
|
|
734
836
|
"result: download the file if you need it later."
|
|
@@ -822,7 +924,7 @@ function registerWhoamiTool(server, getClient) {
|
|
|
822
924
|
//#endregion
|
|
823
925
|
//#region src/version.ts
|
|
824
926
|
const SERVER_NAME = "crawlbrulee";
|
|
825
|
-
const SERVER_VERSION = "
|
|
927
|
+
const SERVER_VERSION = "2.0.0";
|
|
826
928
|
|
|
827
929
|
//#endregion
|
|
828
930
|
//#region src/server.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlbrulee/mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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.
|
|
66
|
+
"@crawlbrulee/sdk": "^1.6.0",
|
|
67
67
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
68
68
|
"zod": "^4.0.0"
|
|
69
69
|
},
|