@crawlbrulee/mcp 1.2.1 → 1.3.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 +32 -3
- package/dist/index.js +95 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -91,6 +91,33 @@ html, raw html, links, images, screenshot, page metadata).
|
|
|
91
91
|
|
|
92
92
|
`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).
|
|
93
93
|
|
|
94
|
+
**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. it costs no extra credits. `scrape_async` takes it too.
|
|
95
|
+
|
|
96
|
+
```jsonc
|
|
97
|
+
{
|
|
98
|
+
"url": "https://books.toscrape.com/",
|
|
99
|
+
"extract": {
|
|
100
|
+
"elements": {
|
|
101
|
+
"heading": "h1",
|
|
102
|
+
"books": {
|
|
103
|
+
"selector": "article.product_pod",
|
|
104
|
+
"all": true,
|
|
105
|
+
"fields": {
|
|
106
|
+
"title": { "selector": "h3 a", "output": "attribute", "attribute": "title" },
|
|
107
|
+
"price": ".price_color",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
// → "elements": {
|
|
114
|
+
// "heading": "All products",
|
|
115
|
+
// "books": [{ "title": "A Light in the Attic", "price": "£51.77" }, ...]
|
|
116
|
+
// }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
a name with no match is `null` (or `[]` with `all: true`). limits and selector rules: see [elements](https://crawlbrulee.com/docs/scrape/elements).
|
|
120
|
+
|
|
94
121
|
**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:
|
|
95
122
|
|
|
96
123
|
```jsonc
|
|
@@ -125,9 +152,11 @@ alongside `response_meta.usage`, the result surfaces any non-fatal `warnings`
|
|
|
125
152
|
| `links_truncated` | the page had more than 30,000 links; the `links` array is cut at the cap and is incomplete. |
|
|
126
153
|
| `inline_images_truncated` | the page had more than 10,000 inline images; the `images` array is cut at the cap and is incomplete. |
|
|
127
154
|
| `raw_html_truncated` | the page body exceeded 10,000,000 characters; `raw_html` is cut at a tag boundary, never mid-tag. |
|
|
128
|
-
| `
|
|
155
|
+
| `elements_truncated` | an `elements` value hit a limit; see [elements](https://crawlbrulee.com/docs/scrape/elements). |
|
|
156
|
+
|
|
157
|
+
one more code is 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.
|
|
129
158
|
|
|
130
|
-
and if you requested an extract that doesn't apply to the content type (e.g. `
|
|
159
|
+
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.
|
|
131
160
|
|
|
132
161
|
every input field, its default, and its constraints are documented under the [scrape endpoint](https://crawlbrulee.com/docs/scrape) — with [extraction](https://crawlbrulee.com/docs/scrape/extraction), [screenshots](https://crawlbrulee.com/docs/scrape/screenshots), [proxies & location](https://crawlbrulee.com/docs/proxies), and [caching](https://crawlbrulee.com/docs/scrape/caching) covering the individual blocks.
|
|
133
162
|
|
|
@@ -168,7 +197,7 @@ look up the current lifecycle status of an async job: `pending`, `running`, `don
|
|
|
168
197
|
|
|
169
198
|
### `scrape_result`
|
|
170
199
|
|
|
171
|
-
fetch the extracted content of a completed async job — the same result shape as the synchronous `scrape` tool (including `page_status_code`, `metadata` and `response_meta.usage`). errors if the job is still `pending`/`running`, so check `scrape_status` first.
|
|
200
|
+
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.
|
|
172
201
|
|
|
173
202
|
```jsonc
|
|
174
203
|
{ "job_id": "..." }
|
package/dist/index.js
CHANGED
|
@@ -130,6 +130,83 @@ const Schema_ApiScrapeCleanup = z.object({
|
|
|
130
130
|
exclude_selectors: z.array(z.string().max(500)).max(100).optional().describe("CSS selectors whose elements are removed before anything is captured. Affects the extracted content and the screenshot, never raw_html. Use it for a banner or widget that ads_and_popups does not recognise. Sending any selector here makes the request skip the cache.")
|
|
131
131
|
}).strict().describe("What is removed from the page before any output is built. Applies to markdown, cleaned_html, links and images on every engine, and to the screenshot. Never applies to raw_html, which is always the page before we removed anything.");
|
|
132
132
|
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/schemas/ScrapeElementsSchemas.ts
|
|
135
|
+
/**
|
|
136
|
+
* Mirrors `packages/core/src/model/common/ScrapeElements*` in the server repo.
|
|
137
|
+
* Kept in step by hand — this package deliberately does not import from the
|
|
138
|
+
* monorepo. If the server's shape changes, change it here too.
|
|
139
|
+
*
|
|
140
|
+
* `extract.elements`: named values read from the page by CSS selector. `fields`
|
|
141
|
+
* nests, at most ELEMENT_FIELDS_DEPTH deep. The schemas are built level by level
|
|
142
|
+
* instead of with `z.lazy`, so the depth limit holds by shape and the tool's JSON
|
|
143
|
+
* Schema stays a plain tree (no `$ref`) that every host can read.
|
|
144
|
+
*
|
|
145
|
+
* Only the public per-string limits are checked here. The total selector count, the
|
|
146
|
+
* CSS syntax and the name length are left to the api, which answers a clear 400.
|
|
147
|
+
*/
|
|
148
|
+
const ELEMENTS_DOCS_URL = "https://crawlbrulee.com/docs/scrape/elements";
|
|
149
|
+
/** How deep `fields` may nest. The innermost level has no `fields`. */
|
|
150
|
+
const ELEMENT_FIELDS_DEPTH = 3;
|
|
151
|
+
const MAX_ELEMENT_SELECTOR_LENGTH = 500;
|
|
152
|
+
const MAX_ELEMENT_ATTRIBUTE_LENGTH = 100;
|
|
153
|
+
const ELEMENT_OUTPUT_VALUES = [
|
|
154
|
+
"text",
|
|
155
|
+
"html",
|
|
156
|
+
"attribute"
|
|
157
|
+
];
|
|
158
|
+
const Schema_ElementSelector = z.string().max(500);
|
|
159
|
+
function refineSpec(spec, ctx) {
|
|
160
|
+
if (spec.fields !== void 0) {
|
|
161
|
+
if (spec.output !== void 0 || spec.attribute !== void 0) ctx.addIssue({
|
|
162
|
+
code: "custom",
|
|
163
|
+
path: ["fields"],
|
|
164
|
+
message: "fields cannot be combined with output or attribute: each match becomes an object"
|
|
165
|
+
});
|
|
166
|
+
if (Object.keys(spec.fields).length === 0) ctx.addIssue({
|
|
167
|
+
code: "custom",
|
|
168
|
+
path: ["fields"],
|
|
169
|
+
message: "fields needs at least one field"
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (spec.output === "attribute" && !spec.attribute) ctx.addIssue({
|
|
174
|
+
code: "custom",
|
|
175
|
+
path: ["attribute"],
|
|
176
|
+
message: "attribute is required when output is \"attribute\""
|
|
177
|
+
});
|
|
178
|
+
if (spec.output !== "attribute" && spec.attribute !== void 0) ctx.addIssue({
|
|
179
|
+
code: "custom",
|
|
180
|
+
path: ["attribute"],
|
|
181
|
+
message: "attribute is only allowed when output is \"attribute\""
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function describeTop(schema, top, text) {
|
|
185
|
+
return top ? schema.describe(text) : schema;
|
|
186
|
+
}
|
|
187
|
+
/** One `{ name: spec }` map that may still nest `fields` `fieldsDepth` more levels. */
|
|
188
|
+
function buildElementsMap(fieldsDepth, top = false) {
|
|
189
|
+
const spec = z.object({
|
|
190
|
+
selector: describeTop(Schema_ElementSelector, top, "CSS selector, up to 500 characters"),
|
|
191
|
+
output: describeTop(z.enum(ELEMENT_OUTPUT_VALUES).optional(), top, "What to return for a match: `text` (default), `html` (the outer HTML) or `attribute`"),
|
|
192
|
+
attribute: describeTop(z.string().min(1).max(100).optional(), top, "The attribute to read when `output` is `attribute`. `href` and `src` come back as full urls"),
|
|
193
|
+
all: describeTop(z.boolean().default(false), top, "Return every match as a list instead of the first. Defaults to false"),
|
|
194
|
+
...fieldsDepth > 0 ? { fields: describeTop(buildElementsMap(fieldsDepth - 1).optional(), top, "Used instead of `output`: turns each match into an object of named values, each read inside that match only. Same shape as `elements`; nests up to 3 levels") } : {}
|
|
195
|
+
}).strict().superRefine(refineSpec);
|
|
196
|
+
return z.record(z.string(), z.union([Schema_ElementSelector, spec]));
|
|
197
|
+
}
|
|
198
|
+
const Schema_ScrapeElements = buildElementsMap(3, true);
|
|
199
|
+
/**
|
|
200
|
+
* The answer: name → value. Today a value is a string, an object (`fields`), a
|
|
201
|
+
* list of either (`all: true`), or `null` when nothing matched, nested 3 levels.
|
|
202
|
+
* That shape lives in the field description only. Each value is left open on
|
|
203
|
+
* purpose, like every other response field here: a host checks structured
|
|
204
|
+
* output against this schema, and one value it does not expect (a new output
|
|
205
|
+
* kind, a deeper level) would fail the whole tool call and lose the rest of the
|
|
206
|
+
* result.
|
|
207
|
+
*/
|
|
208
|
+
const Schema_ScrapeElementValues = z.record(z.string(), z.unknown());
|
|
209
|
+
|
|
133
210
|
//#endregion
|
|
134
211
|
//#region src/schemas/ScrapeScreenshotSchemas.ts
|
|
135
212
|
const Schema_ApiScrapeScreenshotType = z.enum(["viewport", "full_page"]).describe("Screenshot mode: viewport (visible area) or full_page (entire page)");
|
|
@@ -182,13 +259,14 @@ const Schema_ApiScrapeFormatScreenshot = z.object({
|
|
|
182
259
|
}).strict().superRefine(refineScrapeScreenshotActionsBefore).describe("Screenshot capture configuration");
|
|
183
260
|
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");
|
|
184
261
|
const Schema_ApiScrapeExtract = z.object({
|
|
185
|
-
metadata: z.boolean().default(true).describe("Extract page metadata (title, description, OG tags, etc.)
|
|
262
|
+
metadata: z.boolean().default(true).describe("Extract page metadata (title, description, OG tags, etc.) from the page head"),
|
|
186
263
|
cleaned_html: z.boolean().default(true).describe("Extract cleaned HTML (main content only)"),
|
|
187
264
|
markdown: z.boolean().default(false).describe("Extract page content as clean Markdown"),
|
|
188
265
|
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."),
|
|
189
266
|
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."),
|
|
190
267
|
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."),
|
|
191
|
-
screenshot: Schema_ApiScrapeFormatScreenshot.optional().describe("Capture a screenshot of the page")
|
|
268
|
+
screenshot: Schema_ApiScrapeFormatScreenshot.optional().describe("Capture a screenshot of the page"),
|
|
269
|
+
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 only, so a list of product cards can return a title, price and url per card. 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}.`)
|
|
192
270
|
}).strict().describe("Which content formats to extract from the scraped page");
|
|
193
271
|
const Schema_ApiScrapeLocation = z.object({
|
|
194
272
|
locale: z.string().min(2).max(35).optional().describe("BCP-47 locale (2-35 chars, e.g. 'en-US', 'de-DE', 'pt-BR') driving Accept-Language and navigator.language"),
|
|
@@ -338,11 +416,12 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
|
338
416
|
markdown: z.string().optional().describe("Page content converted to clean Markdown"),
|
|
339
417
|
cleaned_html: z.string().optional().describe("Cleaned HTML of the main page content"),
|
|
340
418
|
raw_html: z.string().optional().describe("Raw, unprocessed HTML of the page"),
|
|
419
|
+
elements: Schema_ScrapeElementValues.optional().describe("The values asked for in `extract.elements`, under the same names. Each name is a string, an object (a spec with `fields`), a list of either (`all: true`), or null when nothing matched (`[]` with `all: true`). An object holds its field names with the same kinds of values, nested up to 3 levels. Every requested name is always present, at every level of `fields`."),
|
|
341
420
|
images: z.array(Schema_ApiPageInlineImgItem).optional().describe("Inline images found on the page"),
|
|
342
421
|
links: z.array(Schema_ApiPageLink).optional().describe("Links found on the page"),
|
|
343
422
|
screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
|
|
344
423
|
metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
|
|
345
|
-
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`
|
|
424
|
+
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. 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."),
|
|
346
425
|
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.")
|
|
347
426
|
});
|
|
348
427
|
|
|
@@ -434,6 +513,9 @@ const DESCRIPTION$5 = [
|
|
|
434
513
|
"Fetch a single URL via the crawlbrulee scraping API and return the requested content",
|
|
435
514
|
"(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
|
|
436
515
|
"Use this for one-shot page extraction. For full-site discovery use the `map` tool first.",
|
|
516
|
+
"To pull named values such as prices, titles or links, set `extract.elements` (name → CSS selector)",
|
|
517
|
+
"instead of reading the whole markdown: they come back in `elements`, for no extra credits.",
|
|
518
|
+
"Rules: https://crawlbrulee.com/docs/scrape/elements.",
|
|
437
519
|
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
438
520
|
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
439
521
|
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
@@ -451,7 +533,7 @@ const DESCRIPTION$5 = [
|
|
|
451
533
|
"Extraction is capped per page: 30,000 links, 10,000 inline images and 10,000,000 characters of",
|
|
452
534
|
"HTML. A page past a cap is truncated rather than refused, and the response `warnings` array names",
|
|
453
535
|
"which one (`links_truncated`, `inline_images_truncated`, `raw_html_truncated`) — so treat that",
|
|
454
|
-
"output as incomplete.",
|
|
536
|
+
"output as incomplete. `elements_truncated` means an `elements` value hit a limit.",
|
|
455
537
|
"Use `cleanup` to control what is removed before any output is built: `ads_and_popups` (on by",
|
|
456
538
|
"default) drops ads, cookie banners and chat widgets, and `exclude_selectors` removes anything",
|
|
457
539
|
"else. It shapes markdown, cleaned_html, links, images and the screenshot, and NEVER `raw_html` —",
|
|
@@ -459,7 +541,9 @@ const DESCRIPTION$5 = [
|
|
|
459
541
|
"`warnings` also reports a section whose extraction failed outright (`links_unavailable`,",
|
|
460
542
|
"`inline_images_unavailable`, `metadata_unavailable`): that field comes back omitted or empty",
|
|
461
543
|
"while the rest of the scrape succeeded, so do NOT conclude the page had no links/images/metadata",
|
|
462
|
-
"— re-run the scrape instead. An empty field with no such warning does mean the page had none."
|
|
544
|
+
"— re-run the scrape instead. An empty field with no such warning does mean the page had none.",
|
|
545
|
+
"`screenshot_unavailable` means a screenshot was asked for, but the page came back from the http",
|
|
546
|
+
"engine without one."
|
|
463
547
|
].join(" ");
|
|
464
548
|
function registerScrapeTool(server, getClient) {
|
|
465
549
|
server.registerTool("scrape", {
|
|
@@ -504,6 +588,8 @@ const DESCRIPTION$4 = [
|
|
|
504
588
|
"(heavy JS rendering, full-page screenshots of long pages) — for a quick one-shot",
|
|
505
589
|
"fetch prefer the synchronous `scrape` tool, which blocks and returns the page directly.",
|
|
506
590
|
"Poll the job with `scrape_status` and fetch the page with `scrape_result` once done.",
|
|
591
|
+
"Takes `extract.elements` like `scrape` (named values by CSS selector, no extra credits); the",
|
|
592
|
+
"result carries them in `elements`. Rules: https://crawlbrulee.com/docs/scrape/elements.",
|
|
507
593
|
"Optionally attach a per-job completion `webhook`: we deliver a single",
|
|
508
594
|
"signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
|
|
509
595
|
"in production), and echoes your opaque `webhook.metadata` back in the delivery",
|
|
@@ -524,8 +610,9 @@ function registerScrapeAsyncTool(server, getClient) {
|
|
|
524
610
|
const DESCRIPTION$3 = [
|
|
525
611
|
"Fetch the extracted content of a completed async scrape job (the same result shape as the",
|
|
526
612
|
"synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot,",
|
|
527
|
-
"page metadata in `metadata`,
|
|
528
|
-
"`
|
|
613
|
+
"page metadata in `metadata`, values from `extract.elements` in `elements`, and",
|
|
614
|
+
"`response_meta.usage`). Errors if the job is still `pending`/`running` — check",
|
|
615
|
+
"`scrape_status` first (status `done`) before calling this.",
|
|
529
616
|
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
530
617
|
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
531
618
|
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
@@ -622,7 +709,7 @@ function registerWhoamiTool(server, getClient) {
|
|
|
622
709
|
//#endregion
|
|
623
710
|
//#region src/version.ts
|
|
624
711
|
const SERVER_NAME = "crawlbrulee";
|
|
625
|
-
const SERVER_VERSION = "1.
|
|
712
|
+
const SERVER_VERSION = "1.3.0";
|
|
626
713
|
|
|
627
714
|
//#endregion
|
|
628
715
|
//#region src/server.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlbrulee/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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.3.0",
|
|
67
67
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
68
68
|
"zod": "^4.0.0"
|
|
69
69
|
},
|