@crawlbrulee/mcp 1.0.3 → 1.1.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 +21 -7
- package/dist/index.js +147 -94
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,24 +88,35 @@ html, raw html, links, images, screenshot, page metadata).
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
**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 a top-level `response_meta.usage` block:
|
|
91
|
+
**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:
|
|
92
92
|
|
|
93
93
|
```jsonc
|
|
94
94
|
{
|
|
95
95
|
"url": "https://example.com",
|
|
96
|
+
"requested_url": "https://example.com",
|
|
97
|
+
"page_status_code": 200, // the site's own HTTP status for the final page
|
|
96
98
|
"markdown": "...",
|
|
97
99
|
"metadata": { "title": "Example Domain" },
|
|
98
100
|
"response_meta": {
|
|
99
101
|
"usage": {
|
|
100
|
-
|
|
102
|
+
// total_credit_cost = engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost
|
|
103
|
+
"total_credit_cost": 1,
|
|
104
|
+
"engine_credit_cost": 1, // http 1, browser 3, screenshot 5, cache 0
|
|
105
|
+
"proxy_multiplier": 1, // basic 1, advanced 5
|
|
106
|
+
"screenshot_slicing_credit_cost": 0, // 1 when the screenshot was split into slices, otherwise 0
|
|
101
107
|
"engine": "http", // "http" | "browser" | "screenshot" | "cache"
|
|
102
108
|
"proxy": "basic", // resolved tier actually used: "basic" | "advanced" (never "auto")
|
|
103
|
-
"
|
|
109
|
+
"credits": 1, // deprecated: same as total_credit_cost
|
|
110
|
+
"screenshot_slices": 0, // deprecated: same as screenshot_slicing_credit_cost
|
|
104
111
|
},
|
|
105
112
|
},
|
|
106
113
|
}
|
|
107
114
|
```
|
|
108
115
|
|
|
116
|
+
**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)).
|
|
117
|
+
|
|
118
|
+
`credits` and `screenshot_slices` are the old names of `total_credit_cost` and `screenshot_slicing_credit_cost`. they are deprecated and will be removed in a future version. older api versions send only the old names and no `page_status_code`.
|
|
119
|
+
|
|
109
120
|
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:
|
|
110
121
|
|
|
111
122
|
| code | what it means for the payload |
|
|
@@ -149,7 +160,7 @@ the job lifecycle is documented under [async scrape](https://crawlbrulee.com/doc
|
|
|
149
160
|
|
|
150
161
|
### `scrape_status`
|
|
151
162
|
|
|
152
|
-
look up the current lifecycle status of an async job: `pending`, `running`, `done`, or `failed` (with an `error` message when failed). once the job is `done` the response also carries a `response_meta.usage` block (`
|
|
163
|
+
look up the current lifecycle status of an async job: `pending`, `running`, `done`, or `failed` (with an `error` message when failed). once the job is `done` the response also carries a `response_meta.usage` block (`total_credit_cost` and its parts, billed `engine`, resolved `proxy` tier). a cache hit is represented by `engine: "cache"`. a job whose page the site served ends `done` even when that page is a 404 — read `page_status_code` in the result. poll until `done`, then call `scrape_result`.
|
|
153
164
|
|
|
154
165
|
```jsonc
|
|
155
166
|
{ "job_id": "..." }
|
|
@@ -157,7 +168,7 @@ look up the current lifecycle status of an async job: `pending`, `running`, `don
|
|
|
157
168
|
|
|
158
169
|
### `scrape_result`
|
|
159
170
|
|
|
160
|
-
fetch the extracted content of a completed async job — the same result shape as the synchronous `scrape` tool (including `metadata` and `response_meta.usage`). errors if the job is still `pending`/`running`, so check `scrape_status` first.
|
|
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.
|
|
161
172
|
|
|
162
173
|
```jsonc
|
|
163
174
|
{ "job_id": "..." }
|
|
@@ -171,7 +182,7 @@ build (or fetch a cached) link-map for a website. combines sitemap discovery wit
|
|
|
171
182
|
|
|
172
183
|
returned urls are normalized the same way `scrape` normalizes its returned `url`, so map-then-scrape stays on one host. results are ordered with the most useful links first.
|
|
173
184
|
|
|
174
|
-
the response's `response_meta` carries `pagination`, `truncation`, and a `usage` block (`
|
|
185
|
+
the response's `response_meta` carries `pagination`, `truncation`, and a `usage` block (`total_credit_cost` = `engine_credit_cost` × `proxy_multiplier`, billed `engine`, resolved `proxy` tier, and the deprecated `credits`). map has no screenshot slicing and no `page_status_code`, since it reads many files, not one page. a map that found nothing because the site answered only with statuses we don't bill (a `5xx`, for example), or not at all, is empty and free.
|
|
175
186
|
|
|
176
187
|
```jsonc
|
|
177
188
|
{
|
|
@@ -222,6 +233,8 @@ every tool returns an mcp error result (`isError: true`) when the api call fails
|
|
|
222
233
|
[<errorName>] <message> (HTTP <status>)
|
|
223
234
|
```
|
|
224
235
|
|
|
236
|
+
a few codes add a short next step after that, e.g. `target_unreachable`. branch on the `errorName` code, not on the rest of the text.
|
|
237
|
+
|
|
225
238
|
agents can branch on the `errorName` code. the set comes from the sdk's `ApiErrorName` union plus two synthetic codes added by this mcp (`missing_api_key`, `internal_error`):
|
|
226
239
|
|
|
227
240
|
| code | meaning |
|
|
@@ -237,7 +250,8 @@ agents can branch on the `errorName` code. the set comes from the sdk's `ApiErro
|
|
|
237
250
|
| `antibot_blocked` | origin's anti-bot defenses blocked the fetch. |
|
|
238
251
|
| `too_many_redirects` | origin redirected the fetch in a loop (HTTP 422). the target's doing — don't retry blindly. |
|
|
239
252
|
| `page_too_large` | the page's html was too large to process (HTTP 422). terminal — never retry it. |
|
|
240
|
-
| `
|
|
253
|
+
| `target_unreachable` | we could not reach the site at all (HTTP 502). not billed. retry later or check the url. |
|
|
254
|
+
| `scrape_error` | the scrape could not be completed. a page the site served, even a 404, is never this error. |
|
|
241
255
|
| `unsupported_screenshot_output` | screenshot-only request on a content type that can't be screenshotted (HTTP 422). not billed. |
|
|
242
256
|
| `not_found` | async job ID unknown (e.g. bad `job_id` to `scrape_status` / `scrape_result`). |
|
|
243
257
|
| `request_timeout` | network / read timeout. safe to retry. |
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,8 @@ const MISSING_API_KEY_REMEDIATION = `${ENV_API_KEY} is not set on the MCP host.
|
|
|
48
48
|
* stable `errorName` codes and HTTP `status`; both go into the surfaced
|
|
49
49
|
* message so the calling agent can branch on them (e.g. back off and retry on
|
|
50
50
|
* `too_many_requests` or `service_unavailable` — a transient backend failure,
|
|
51
|
-
* not a bad key — and prompt the user on `invalid_credentials`).
|
|
51
|
+
* not a bad key — and prompt the user on `invalid_credentials`). A few codes get
|
|
52
|
+
* a short next step appended (see ERROR_HINTS).
|
|
52
53
|
*
|
|
53
54
|
* One special case: the SDK throws a generic `CrawlbruleeError` (status 0,
|
|
54
55
|
* errorName null) when `CRAWLBRULEE_API_KEY` is missing. We rewrite that
|
|
@@ -64,10 +65,21 @@ function toToolError(err) {
|
|
|
64
65
|
function isMissingApiKeyError(err) {
|
|
65
66
|
return err.status === 0 && err.errorName === null && err.message.includes(ENV_API_KEY);
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* A next step for codes whose api message alone does not tell an agent what to
|
|
70
|
+
* do. Added after the stable `[code] message (HTTP status)` prefix, so anything
|
|
71
|
+
* that branches on the code keeps working.
|
|
72
|
+
*
|
|
73
|
+
* `target_unreachable` arrives as a plain `CrawlbruleeError` (the SDK has no class
|
|
74
|
+
* for it yet), so it is matched by name.
|
|
75
|
+
*/
|
|
76
|
+
const ERROR_HINTS = { target_unreachable: "We could not reach the site: it did not answer, took too long, or its certificate was not valid. Retry later or check the URL. Not billed. This is not the same as a page that says \"not found\": a page the site served comes back as a result, with its status in page_status_code." };
|
|
67
77
|
function crawlbruleeErrorResult(err) {
|
|
68
78
|
const code = err.errorName ?? "crawlbrulee_error";
|
|
69
79
|
const httpPart = err.status > 0 ? ` (HTTP ${err.status})` : "";
|
|
70
|
-
|
|
80
|
+
const hint = ERROR_HINTS[code];
|
|
81
|
+
const hintPart = hint ? ` ${hint}` : "";
|
|
82
|
+
return textErrorResult(`[${code}] ${err.message}${httpPart}${hintPart}`);
|
|
71
83
|
}
|
|
72
84
|
function textErrorResult(text) {
|
|
73
85
|
return {
|
|
@@ -234,81 +246,6 @@ function openEnum(values) {
|
|
|
234
246
|
return z.union([z.enum(values), z.string()]);
|
|
235
247
|
}
|
|
236
248
|
|
|
237
|
-
//#endregion
|
|
238
|
-
//#region src/schemas/ApiMapResponse.ts
|
|
239
|
-
const API_RESOLVED_PROXY_TIER_VALUES$1 = ["basic", "advanced"];
|
|
240
|
-
/** Which limit stopped sitemap discovery first. The FIRST limit to fire wins. */
|
|
241
|
-
const DISCOVERY_CAP_REASONS = [
|
|
242
|
-
"max_urls",
|
|
243
|
-
"time",
|
|
244
|
-
"file_budget",
|
|
245
|
-
"depth",
|
|
246
|
-
"file_size",
|
|
247
|
-
"unread_files"
|
|
248
|
-
];
|
|
249
|
-
/** Map usage has no screenshot-slice add-on. */
|
|
250
|
-
const Schema_ApiMapUsageMeta = z.looseObject({
|
|
251
|
-
credits: z.number().int().nonnegative().describe("Credits charged for this map request"),
|
|
252
|
-
engine: openEnum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
|
|
253
|
-
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES$1).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
|
|
254
|
-
});
|
|
255
|
-
const Schema_ApiMapLinkItem = z.looseObject({ url: z.string().describe("The discovered URL") });
|
|
256
|
-
const Schema_ApiMapPagination = z.looseObject({
|
|
257
|
-
page: z.number().int().positive().describe("Current page number"),
|
|
258
|
-
limit: z.number().int().positive().describe("Number of items per page"),
|
|
259
|
-
total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
|
|
260
|
-
total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
|
|
261
|
-
has_more: z.boolean().describe("Whether more pages are available")
|
|
262
|
-
});
|
|
263
|
-
const Schema_ApiMapTruncation = z.looseObject({
|
|
264
|
-
storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
|
|
265
|
-
response_capped: z.boolean().describe("Whether more links were eligible than max_urls, so the list was trimmed. Discovery itself stops at max_urls, so this is normally true only when home-page links pushed the total past it. See discovery_cap_reason for a discovery stop."),
|
|
266
|
-
total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
|
|
267
|
-
total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
|
|
268
|
-
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."),
|
|
269
|
-
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."),
|
|
270
|
-
discovery_cap_reason: openEnum(DISCOVERY_CAP_REASONS).nullable().describe("Which limit stopped sitemap discovery first, or null when nothing stopped it. \"max_urls\" means your own max_urls was reached — ask again with a higher one to get more. \"time\" means discovery ran out of its time budget, \"file_budget\" that the site has more sitemap files than one request reads, \"depth\" that its sitemap indexes nest too deeply, and \"file_size\" that a sitemap file was too large to read. \"unread_files\" means a sitemap file the site publishes could not be read at all this time — the request for it failed or was rate limited, or the file was not a readable sitemap. Only \"max_urls\" is a limit you can raise from the request; \"unread_files\" is often temporary, so asking again later can return more.")
|
|
271
|
-
});
|
|
272
|
-
const Schema_ApiMapResult = z.looseObject({
|
|
273
|
-
links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
|
|
274
|
-
response_meta: z.looseObject({
|
|
275
|
-
pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
|
|
276
|
-
truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
|
|
277
|
-
usage: Schema_ApiMapUsageMeta.describe("Usage accounting for this map request: credits charged, the billed engine, and the resolved proxy tier.")
|
|
278
|
-
}).describe("Response metadata including pagination, truncation, and usage info")
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/tools/map.ts
|
|
283
|
-
const DESCRIPTION$6 = [
|
|
284
|
-
"Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
|
|
285
|
-
"link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
|
|
286
|
-
"Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
|
|
287
|
-
"scraping selected pages.",
|
|
288
|
-
"`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
|
|
289
|
-
"stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
|
|
290
|
-
"A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
|
|
291
|
-
"signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
|
|
292
|
-
"\"max_urls\", ask again with a higher `max_urls` to get more; \"unread_files\" means a sitemap file",
|
|
293
|
-
"could not be read this time and is often temporary, so asking again later can return more;",
|
|
294
|
-
"\"time\", \"file_budget\", \"depth\" and \"file_size\" mean the site itself is big, slow or deep and a",
|
|
295
|
-
"retry will not help. `discovery_capped` says discovery stopped early, `sitemaps_skipped` how",
|
|
296
|
-
"many sitemap files were skipped or only partly read.",
|
|
297
|
-
"`limit` (default 5000, max 10000) only pages the answer.",
|
|
298
|
-
"Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
|
|
299
|
-
"map-then-scrape stays on one host. Results are ordered with the most useful links first.",
|
|
300
|
-
"The response carries `response_meta.usage` = { credits, engine, proxy } — the resolved proxy",
|
|
301
|
-
"tier is never `auto`; map responses do not include screenshot-slice accounting."
|
|
302
|
-
].join(" ");
|
|
303
|
-
function registerMapTool(server, getClient) {
|
|
304
|
-
server.registerTool("map", {
|
|
305
|
-
title: "Map a website",
|
|
306
|
-
description: DESCRIPTION$6,
|
|
307
|
-
inputSchema: Schema_ApiMapRequest.shape,
|
|
308
|
-
outputSchema: Schema_ApiMapResult
|
|
309
|
-
}, (args) => runTool(async () => await getClient().map(args)));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
249
|
//#endregion
|
|
313
250
|
//#region src/schemas/ApiScrapeResponse.ts
|
|
314
251
|
const Schema_ApiViewport = z.looseObject({
|
|
@@ -344,19 +281,32 @@ const Schema_ApiPageLink = z.looseObject({
|
|
|
344
281
|
href: z.string().describe("The link URL as written on the page, resolved to an absolute URL; verbatim otherwise (query string, fragment, and duplicates preserved)"),
|
|
345
282
|
internal: z.boolean().describe("Whether the link points to the same domain (www and the bare domain are equivalent; other subdomains are external)")
|
|
346
283
|
});
|
|
347
|
-
const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
|
|
284
|
+
const API_RESOLVED_PROXY_TIER_VALUES$1 = ["basic", "advanced"];
|
|
285
|
+
const Schema_CreditCost = z.number().int().nonnegative();
|
|
286
|
+
const Schema_ApiProxyMultiplier = z.number().int().positive();
|
|
287
|
+
const PROXY_MULTIPLIER_DESCRIPTION = "The multiplier of the proxy tier the request ran on: 1 for \"basic\", 5 for \"advanced\". Always reported, even when the engine cost is 0. Older api versions do not send it.";
|
|
348
288
|
const Schema_ApiUsageMeta = z.looseObject({
|
|
349
|
-
|
|
289
|
+
total_credit_cost: Schema_CreditCost.optional().describe("Credits charged for this request. Always equals engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost. 0 when nothing is billed: a cache hit, or a page whose status is not billed (see page_status_code). Older api versions do not send it; read `credits` then, which has the same value."),
|
|
290
|
+
engine_credit_cost: Schema_CreditCost.optional().describe("The engine base charged, before the proxy multiplier: 1 for \"http\", 3 for \"browser\", 5 for \"screenshot\", 0 for \"cache\". Also 0 when the page is not billed (see page_status_code). Older api versions do not send it."),
|
|
291
|
+
proxy_multiplier: Schema_ApiProxyMultiplier.optional().describe(PROXY_MULTIPLIER_DESCRIPTION),
|
|
292
|
+
screenshot_slicing_credit_cost: Schema_CreditCost.optional().describe("The screenshot slicing add-on: 1 when the screenshot was split into slices on this request (a flat +1 credit outside the proxy multiplier, however many slices it made), else 0. A cache hit that reused slices that already existed costs 0. Older api versions do not send it; read `screenshot_slices` then, which has the same value."),
|
|
350
293
|
engine: openEnum([
|
|
351
294
|
"http",
|
|
352
295
|
"browser",
|
|
353
296
|
"screenshot",
|
|
354
297
|
"cache"
|
|
355
|
-
]).describe("The engine
|
|
356
|
-
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES).describe("The proxy tier the request actually ran on (resolved value — never `auto`; `auto` is resolved server-side to `basic` or `advanced`)."),
|
|
357
|
-
|
|
298
|
+
]).describe("The engine the request was billed at — \"http\", \"browser\", \"screenshot\", or \"cache\" (the result was served from cache). Reflects what was delivered, never what was requested."),
|
|
299
|
+
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES$1).describe("The proxy tier the request actually ran on (resolved value — never `auto`; `auto` is resolved server-side to `basic` or `advanced`). \"advanced\" multiplies the engine base by 5."),
|
|
300
|
+
credits: Schema_CreditCost.meta({
|
|
301
|
+
description: "Deprecated: use total_credit_cost, which always has the same value. This field will be removed in a future version.",
|
|
302
|
+
deprecated: true
|
|
303
|
+
}).optional(),
|
|
304
|
+
screenshot_slices: Schema_CreditCost.meta({
|
|
305
|
+
description: "Deprecated: use screenshot_slicing_credit_cost, which always has the same value. Despite its name this is a 0/1 charge, not a count of slices. This field will be removed in a future version.",
|
|
306
|
+
deprecated: true
|
|
307
|
+
}).optional()
|
|
358
308
|
});
|
|
359
|
-
const Schema_ApiResponseMeta = z.looseObject({ usage: Schema_ApiUsageMeta.describe("
|
|
309
|
+
const Schema_ApiResponseMeta = z.looseObject({ usage: Schema_ApiUsageMeta.describe("What this request cost and why: total_credit_cost = engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost, plus the billed engine and the resolved proxy tier.") });
|
|
360
310
|
const Schema_ApiScrapeMeta = z.looseObject({
|
|
361
311
|
title: z.string().optional().describe("Page title from the <title> tag"),
|
|
362
312
|
description: z.string().optional().describe("Meta description"),
|
|
@@ -384,6 +334,7 @@ const Schema_ApiScrapeMeta = z.looseObject({
|
|
|
384
334
|
const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
385
335
|
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"),
|
|
386
336
|
requested_url: z.string().describe("The URL you requested, echoed verbatim — before any redirects"),
|
|
337
|
+
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."),
|
|
387
338
|
content_type: z.string().optional().describe("Content-Type header returned by the server"),
|
|
388
339
|
unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
|
|
389
340
|
markdown: z.string().optional().describe("Page content converted to clean Markdown"),
|
|
@@ -394,8 +345,93 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
|
394
345
|
screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
|
|
395
346
|
metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
|
|
396
347
|
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` / `metadata_truncated` (rendered HTML exceeded the per-page size budget) — mean the field is present but capped. 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. 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."),
|
|
397
|
-
response_meta: Schema_ApiResponseMeta.describe("Request-level metadata. `response_meta.usage` reports
|
|
348
|
+
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.")
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/schemas/ApiMapResponse.ts
|
|
353
|
+
const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
|
|
354
|
+
/** Which limit stopped sitemap discovery first. The FIRST limit to fire wins. */
|
|
355
|
+
const DISCOVERY_CAP_REASONS = [
|
|
356
|
+
"max_urls",
|
|
357
|
+
"time",
|
|
358
|
+
"file_budget",
|
|
359
|
+
"depth",
|
|
360
|
+
"file_size",
|
|
361
|
+
"unread_files"
|
|
362
|
+
];
|
|
363
|
+
/** Map usage has no screenshot-slice add-on. The new parts are optional: older api versions send only `credits`, `engine` and `proxy`. */
|
|
364
|
+
const Schema_ApiMapUsageMeta = z.looseObject({
|
|
365
|
+
total_credit_cost: z.number().int().nonnegative().optional().describe("Credits charged for this map request. Always equals engine_credit_cost × proxy_multiplier. 0 for a cache hit, and for an empty map when the site answered only with statuses we do not bill (a 5xx, for example) or not at all. Older api versions do not send it; read `credits` then, which has the same value."),
|
|
366
|
+
engine_credit_cost: z.number().int().nonnegative().optional().describe("The engine base charged, before the proxy multiplier: 1 for \"http\", 0 for \"cache\". Also 0 for an empty map that is not billed. Older api versions do not send it."),
|
|
367
|
+
proxy_multiplier: Schema_ApiProxyMultiplier.optional().describe(PROXY_MULTIPLIER_DESCRIPTION),
|
|
368
|
+
engine: openEnum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
|
|
369
|
+
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES).describe("The proxy tier the request actually ran on (resolved value — never `auto`)"),
|
|
370
|
+
credits: z.number().int().nonnegative().meta({
|
|
371
|
+
description: "Deprecated: use total_credit_cost, which always has the same value. This field will be removed in a future version.",
|
|
372
|
+
deprecated: true
|
|
373
|
+
}).optional()
|
|
398
374
|
});
|
|
375
|
+
const Schema_ApiMapLinkItem = z.looseObject({ url: z.string().describe("The discovered URL") });
|
|
376
|
+
const Schema_ApiMapPagination = z.looseObject({
|
|
377
|
+
page: z.number().int().positive().describe("Current page number"),
|
|
378
|
+
limit: z.number().int().positive().describe("Number of items per page"),
|
|
379
|
+
total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
|
|
380
|
+
total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
|
|
381
|
+
has_more: z.boolean().describe("Whether more pages are available")
|
|
382
|
+
});
|
|
383
|
+
const Schema_ApiMapTruncation = z.looseObject({
|
|
384
|
+
storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
|
|
385
|
+
response_capped: z.boolean().describe("Whether more links were eligible than max_urls, so the list was trimmed. Discovery itself stops at max_urls, so this is normally true only when home-page links pushed the total past it. See discovery_cap_reason for a discovery stop."),
|
|
386
|
+
total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
|
|
387
|
+
total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
|
|
388
|
+
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."),
|
|
389
|
+
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."),
|
|
390
|
+
discovery_cap_reason: openEnum(DISCOVERY_CAP_REASONS).nullable().describe("Which limit stopped sitemap discovery first, or null when nothing stopped it. \"max_urls\" means your own max_urls was reached — ask again with a higher one to get more. \"time\" means discovery ran out of its time budget, \"file_budget\" that the site has more sitemap files than one request reads, \"depth\" that its sitemap indexes nest too deeply, and \"file_size\" that a sitemap file was too large to read. \"unread_files\" means a sitemap file the site publishes could not be read at all this time — the request for it failed or was rate limited, or the file was not a readable sitemap. Only \"max_urls\" is a limit you can raise from the request; \"unread_files\" is often temporary, so asking again later can return more.")
|
|
391
|
+
});
|
|
392
|
+
const Schema_ApiMapResult = z.looseObject({
|
|
393
|
+
links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
|
|
394
|
+
response_meta: z.looseObject({
|
|
395
|
+
pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
|
|
396
|
+
truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
|
|
397
|
+
usage: Schema_ApiMapUsageMeta.describe("What this map request cost: total_credit_cost = engine_credit_cost × proxy_multiplier, plus the billed engine and the resolved proxy tier.")
|
|
398
|
+
}).describe("Response metadata including pagination, truncation, and usage info")
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/tools/map.ts
|
|
403
|
+
const DESCRIPTION$6 = [
|
|
404
|
+
"Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
|
|
405
|
+
"link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
|
|
406
|
+
"Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
|
|
407
|
+
"scraping selected pages.",
|
|
408
|
+
"`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
|
|
409
|
+
"stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
|
|
410
|
+
"A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
|
|
411
|
+
"signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
|
|
412
|
+
"\"max_urls\", ask again with a higher `max_urls` to get more; \"unread_files\" means a sitemap file",
|
|
413
|
+
"could not be read this time and is often temporary, so asking again later can return more;",
|
|
414
|
+
"\"time\", \"file_budget\", \"depth\" and \"file_size\" mean the site itself is big, slow or deep and a",
|
|
415
|
+
"retry will not help. `discovery_capped` says discovery stopped early, `sitemaps_skipped` how",
|
|
416
|
+
"many sitemap files were skipped or only partly read.",
|
|
417
|
+
"`limit` (default 5000, max 10000) only pages the answer.",
|
|
418
|
+
"Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
|
|
419
|
+
"map-then-scrape stays on one host. Results are ordered with the most useful links first.",
|
|
420
|
+
"The response carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
421
|
+
"`proxy_multiplier`, plus `engine` and `proxy` (the resolved tier, never `auto`); `credits` is the",
|
|
422
|
+
"old, deprecated name of `total_credit_cost`. Map has no screenshot slicing and no",
|
|
423
|
+
"`page_status_code`: it reads many files, not one page. A map that found nothing because the site",
|
|
424
|
+
"answered only with statuses we don't bill (a 5xx, for example), or not at all, is empty and free. If the site cannot be reached, the",
|
|
425
|
+
"tool can return a `target_unreachable` error (HTTP 502, not billed): retry later or check the URL."
|
|
426
|
+
].join(" ");
|
|
427
|
+
function registerMapTool(server, getClient) {
|
|
428
|
+
server.registerTool("map", {
|
|
429
|
+
title: "Map a website",
|
|
430
|
+
description: DESCRIPTION$6,
|
|
431
|
+
inputSchema: Schema_ApiMapRequest.shape,
|
|
432
|
+
outputSchema: Schema_ApiMapResult
|
|
433
|
+
}, (args) => runTool(async () => await getClient().map(args)));
|
|
434
|
+
}
|
|
399
435
|
|
|
400
436
|
//#endregion
|
|
401
437
|
//#region src/tools/scrape.ts
|
|
@@ -403,10 +439,19 @@ const DESCRIPTION$5 = [
|
|
|
403
439
|
"Fetch a single URL via the crawlbrulee scraping API and return the requested content",
|
|
404
440
|
"(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
|
|
405
441
|
"Use this for one-shot page extraction. For full-site discovery use the `map` tool first.",
|
|
442
|
+
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
443
|
+
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
444
|
+
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
445
|
+
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
446
|
+
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
447
|
+
"If the site cannot be reached at all the tool returns a `target_unreachable` error (HTTP 502,",
|
|
448
|
+
"not billed): retry later or check the URL.",
|
|
406
449
|
"Screenshot URLs in the response are signed download links — the agent can fetch them when needed.",
|
|
407
|
-
"The response also carries `response_meta.usage` =
|
|
408
|
-
"
|
|
409
|
-
"`
|
|
450
|
+
"The response also carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
451
|
+
"`proxy_multiplier` + `screenshot_slicing_credit_cost`, plus `engine` and `proxy` (the resolved",
|
|
452
|
+
"tier — never `auto`). `engine` is the billed engine (`http`, `browser`, `screenshot`, `cache`); a",
|
|
453
|
+
"cache hit is represented by `engine: \"cache\"`. `credits` and `screenshot_slices` are the old,",
|
|
454
|
+
"deprecated names of `total_credit_cost` and `screenshot_slicing_credit_cost`.",
|
|
410
455
|
"Extraction is capped per page: 30,000 links, 10,000 inline images and 10,000,000 characters of",
|
|
411
456
|
"HTML. A page past a cap is truncated rather than refused, and the response `warnings` array names",
|
|
412
457
|
"which one (`links_truncated`, `inline_images_truncated`, `raw_html_truncated`) — so treat that",
|
|
@@ -451,8 +496,8 @@ const Schema_ApiScrapeStatusResponse = z.looseObject({
|
|
|
451
496
|
job_id: z.string().describe("The job identifier"),
|
|
452
497
|
status: openEnum(ASYNC_JOB_STATUS_VALUES).describe("Current state of the job (pending, running, done, failed)"),
|
|
453
498
|
created_at: z.string().describe("ISO-8601 UTC timestamp when the job was created"),
|
|
454
|
-
error: z.string().optional().describe("Error message if the job ended in `failed`"),
|
|
455
|
-
response_meta: Schema_ApiResponseMeta.optional().describe("Usage accounting for the finished job. Present only once the job is `done`; `response_meta.usage` reports
|
|
499
|
+
error: z.string().optional().describe("Error message if the job ended in `failed`. A job whose page the site served, even a 404 page, ends `done`, not `failed`: read `page_status_code` in the `scrape_result`."),
|
|
500
|
+
response_meta: Schema_ApiResponseMeta.optional().describe("Usage accounting for the finished job. Present only once the job is `done`; `response_meta.usage` reports what the job cost (total_credit_cost and its parts), the billed engine and the resolved proxy tier.")
|
|
456
501
|
});
|
|
457
502
|
|
|
458
503
|
//#endregion
|
|
@@ -466,7 +511,7 @@ const DESCRIPTION$4 = [
|
|
|
466
511
|
"Optionally attach a per-job completion `webhook`: we deliver a single",
|
|
467
512
|
"signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
|
|
468
513
|
"in production), and echoes your opaque `webhook.metadata` back in the delivery",
|
|
469
|
-
"(under `data.metadata`, alongside `data.response_meta.usage`)."
|
|
514
|
+
"(under `data.metadata`, alongside `data.page_status_code` (on success) and `data.response_meta.usage`)."
|
|
470
515
|
].join(" ");
|
|
471
516
|
function registerScrapeAsyncTool(server, getClient) {
|
|
472
517
|
server.registerTool("scrape_async", {
|
|
@@ -484,6 +529,11 @@ const DESCRIPTION$3 = [
|
|
|
484
529
|
"synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot,",
|
|
485
530
|
"page metadata in `metadata`, and `response_meta.usage`). Errors if the job is still",
|
|
486
531
|
"`pending`/`running` — check `scrape_status` first (status `done`) before calling this.",
|
|
532
|
+
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
533
|
+
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
534
|
+
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
535
|
+
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
536
|
+
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
487
537
|
"Screenshot URLs are signed download links."
|
|
488
538
|
].join(" ");
|
|
489
539
|
function registerScrapeResultTool(server, getClient) {
|
|
@@ -500,9 +550,12 @@ function registerScrapeResultTool(server, getClient) {
|
|
|
500
550
|
const DESCRIPTION$2 = [
|
|
501
551
|
"Look up the current lifecycle status of an async scrape job submitted via `scrape_async`.",
|
|
502
552
|
"Returns the job state (`pending`, `running`, `done`, `failed`), with an `error` message",
|
|
503
|
-
"when it failed and a `response_meta.usage` block (
|
|
504
|
-
"
|
|
505
|
-
"
|
|
553
|
+
"when it failed and a `response_meta.usage` block (total_credit_cost and its parts, billed engine,",
|
|
554
|
+
"resolved proxy tier) once it is `done`. A job whose page the site served ends `done` even when",
|
|
555
|
+
"that page is a 404 or 503 — read `page_status_code` in the result. A job that could not reach",
|
|
556
|
+
"the site at all ends `failed` (the `error` text is a general message, not the reason) and is not",
|
|
557
|
+
"billed; retry later or check the url. Poll this until the status is",
|
|
558
|
+
"`done`, then call `scrape_result` to fetch",
|
|
506
559
|
"the page. If you registered a completion webhook on submit you can skip polling and react",
|
|
507
560
|
"to the delivery instead."
|
|
508
561
|
].join(" ");
|
|
@@ -569,7 +622,7 @@ function registerWhoamiTool(server, getClient) {
|
|
|
569
622
|
//#endregion
|
|
570
623
|
//#region src/version.ts
|
|
571
624
|
const SERVER_NAME = "crawlbrulee";
|
|
572
|
-
const SERVER_VERSION = "1.0
|
|
625
|
+
const SERVER_VERSION = "1.1.0";
|
|
573
626
|
|
|
574
627
|
//#endregion
|
|
575
628
|
//#region src/server.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlbrulee/mcp",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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.1.0",
|
|
67
67
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
68
68
|
"zod": "^4.0.0"
|
|
69
69
|
},
|