@crawlbrulee/mcp 1.6.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 +14 -0
- package/dist/index.js +145 -53
- package/package.json +1 -1
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
|
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;
|
|
114
194
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
});
|
|
208
|
+
}
|
|
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;
|
|
119
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
|
|
@@ -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"),
|
|
@@ -322,6 +412,7 @@ const Schema_ApiScrapeRequest = z.object({
|
|
|
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
|
|
|
@@ -367,19 +458,6 @@ const Schema_ApiMapRequest = z.object({
|
|
|
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({
|
|
@@ -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
|
|
|
@@ -634,6 +713,17 @@ const DESCRIPTION$5 = [
|
|
|
634
713
|
"costs what a screenshot costs, and both together are billed once. Set",
|
|
635
714
|
"`extract.screenshot.color_scheme: \"dark\"` for a screenshot of the site's dark theme, at no extra",
|
|
636
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.",
|
|
637
727
|
"Screenshot and PDF URLs in the response are signed download links that expire 24 hours after the",
|
|
638
728
|
"scrape: download the file if you need it later; do not keep the link.",
|
|
639
729
|
"The response also carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
@@ -657,7 +747,7 @@ const DESCRIPTION$5 = [
|
|
|
657
747
|
"engine without one. `pdf_unavailable` means the PDF could not be made; the rest is there.",
|
|
658
748
|
"`pdf_single_page_overflow` means a `single_page` PDF was too tall for one page and goes on over",
|
|
659
749
|
"more pages. `custom_user_agent` means the request set its own `User-Agent` header; this",
|
|
660
|
-
"can lower the success rate.",
|
|
750
|
+
"can lower the success rate. `actions_incomplete` means an action failed or never ran.",
|
|
661
751
|
HEADERS_AND_COOKIES_TOOL_TEXT
|
|
662
752
|
].join(" ");
|
|
663
753
|
function registerScrapeTool(server, getClient) {
|
|
@@ -706,6 +796,8 @@ const DESCRIPTION$4 = [
|
|
|
706
796
|
"Takes `extract.elements` like `scrape` (named values by CSS selector, no extra credits); the",
|
|
707
797
|
"result carries them in `elements`. Rules: https://crawlbrulee.com/docs/scrape/targeted-extraction.",
|
|
708
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.",
|
|
709
801
|
"Optionally attach a per-job completion `webhook`: we deliver a single",
|
|
710
802
|
"signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
|
|
711
803
|
"in production), and echoes your opaque `webhook.metadata` back in the delivery",
|
|
@@ -832,7 +924,7 @@ function registerWhoamiTool(server, getClient) {
|
|
|
832
924
|
//#endregion
|
|
833
925
|
//#region src/version.ts
|
|
834
926
|
const SERVER_NAME = "crawlbrulee";
|
|
835
|
-
const SERVER_VERSION = "
|
|
927
|
+
const SERVER_VERSION = "2.0.0";
|
|
836
928
|
|
|
837
929
|
//#endregion
|
|
838
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": [
|