@crawlbrulee/mcp 1.0.3 → 1.2.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 +45 -27
- package/dist/index.js +145 -96
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -85,27 +85,38 @@ html, raw html, links, images, screenshot, page metadata).
|
|
|
85
85
|
"cleanup": { "ads_and_popups": true, "exclude_selectors": ["nav", "footer"] },
|
|
86
86
|
"cache": { "max_age": 3600 },
|
|
87
87
|
"location": { "locale": "en-US", "country": "US" },
|
|
88
|
+
"zero_data_retention": false,
|
|
88
89
|
}
|
|
89
90
|
```
|
|
90
91
|
|
|
91
|
-
|
|
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
|
+
|
|
94
|
+
**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
95
|
|
|
93
96
|
```jsonc
|
|
94
97
|
{
|
|
95
98
|
"url": "https://example.com",
|
|
99
|
+
"requested_url": "https://example.com",
|
|
100
|
+
"page_status_code": 200, // the site's own HTTP status for the final page
|
|
96
101
|
"markdown": "...",
|
|
97
102
|
"metadata": { "title": "Example Domain" },
|
|
98
103
|
"response_meta": {
|
|
99
104
|
"usage": {
|
|
100
|
-
|
|
105
|
+
// total_credit_cost = engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost + zero_data_retention_credit_cost
|
|
106
|
+
"total_credit_cost": 1,
|
|
107
|
+
"engine_credit_cost": 1, // http 1, browser 3, screenshot 5, cache 0
|
|
108
|
+
"proxy_multiplier": 1, // basic 1, advanced 5
|
|
109
|
+
"screenshot_slicing_credit_cost": 0, // 1 when the screenshot was split into slices, otherwise 0
|
|
110
|
+
"zero_data_retention_credit_cost": 0, // 1 when zero_data_retention added its credit, otherwise 0
|
|
101
111
|
"engine": "http", // "http" | "browser" | "screenshot" | "cache"
|
|
102
112
|
"proxy": "basic", // resolved tier actually used: "basic" | "advanced" (never "auto")
|
|
103
|
-
"screenshot_slices": 0, // 1 when the screenshot-split add-on was billed, otherwise 0
|
|
104
113
|
},
|
|
105
114
|
},
|
|
106
115
|
}
|
|
107
116
|
```
|
|
108
117
|
|
|
118
|
+
**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)).
|
|
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` + `zero_data_retention_credit_cost`, billed `engine`, resolved `proxy` tier). map has no screenshot slicing and no `page_status_code`, since it reads many files, not one page. a map that found nothing because the site answered only with statuses we don't bill (a `5xx`, for example), or not at all, is empty and free.
|
|
175
186
|
|
|
176
187
|
```jsonc
|
|
177
188
|
{
|
|
@@ -181,9 +192,12 @@ the response's `response_meta` carries `pagination`, `truncation`, and a `usage`
|
|
|
181
192
|
"max_urls": 5000,
|
|
182
193
|
"page": 1,
|
|
183
194
|
"limit": 1000,
|
|
195
|
+
"zero_data_retention": false,
|
|
184
196
|
}
|
|
185
197
|
```
|
|
186
198
|
|
|
199
|
+
`zero_data_retention` works as it does on `scrape` (see [zero data retention](https://crawlbrulee.com/docs/zero-data-retention)).
|
|
200
|
+
|
|
187
201
|
a map stopped by your own `max_urls` returns exactly that many links with `response_capped: false` — the signal that the site has more is `truncation.discovery_cap_reason`:
|
|
188
202
|
|
|
189
203
|
```jsonc
|
|
@@ -222,29 +236,33 @@ every tool returns an mcp error result (`isError: true`) when the api call fails
|
|
|
222
236
|
[<errorName>] <message> (HTTP <status>)
|
|
223
237
|
```
|
|
224
238
|
|
|
239
|
+
a few codes add a short next step after that, e.g. `target_unreachable` and `zero_data_retention_not_enabled`. branch on the `errorName` code, not on the rest of the text.
|
|
240
|
+
|
|
225
241
|
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
242
|
|
|
227
|
-
| code
|
|
228
|
-
|
|
|
229
|
-
| `missing_api_key`
|
|
230
|
-
| `invalid_credentials`
|
|
231
|
-
| `service_unavailable`
|
|
232
|
-
| `too_many_requests`
|
|
233
|
-
| `usage_allocation_error`
|
|
234
|
-
| `validation_error`
|
|
235
|
-
| `invalid_url`
|
|
236
|
-
| `blocked_url`
|
|
237
|
-
| `antibot_blocked`
|
|
238
|
-
| `too_many_redirects`
|
|
239
|
-
| `page_too_large`
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
242
|
-
| `
|
|
243
|
-
| `
|
|
244
|
-
| `
|
|
245
|
-
| `
|
|
246
|
-
| `
|
|
247
|
-
| `
|
|
243
|
+
| code | meaning |
|
|
244
|
+
| --------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
245
|
+
| `missing_api_key` | `CRAWLBRULEE_API_KEY` is not set in the mcp host's env. |
|
|
246
|
+
| `invalid_credentials` | server rejected the api key (revoked, wrong env, etc.). |
|
|
247
|
+
| `service_unavailable` | temporary backend failure (HTTP 503). your key is fine — retry with backoff. |
|
|
248
|
+
| `too_many_requests` | rate limit hit — back off and retry. |
|
|
249
|
+
| `usage_allocation_error` | plan credit / concurrency cap exceeded. show `usage` to user. |
|
|
250
|
+
| `validation_error` | input failed server validation. |
|
|
251
|
+
| `invalid_url` | target url was rejected before fetching. |
|
|
252
|
+
| `blocked_url` | target url is on the blocklist. |
|
|
253
|
+
| `antibot_blocked` | origin's anti-bot defenses blocked the fetch. |
|
|
254
|
+
| `too_many_redirects` | origin redirected the fetch in a loop (HTTP 422). the target's doing — don't retry blindly. |
|
|
255
|
+
| `page_too_large` | the page's html was too large to process (HTTP 422). terminal — never retry it. |
|
|
256
|
+
| `target_unreachable` | we could not reach the site at all (HTTP 502). not billed. retry later or check the url. |
|
|
257
|
+
| `zero_data_retention_not_enabled` | `zero_data_retention` is not enabled for your organization (HTTP 403). not billed. |
|
|
258
|
+
| `scrape_error` | the scrape could not be completed. a page the site served, even a 404, is never this error. |
|
|
259
|
+
| `unsupported_screenshot_output` | screenshot-only request on a content type that can't be screenshotted (HTTP 422). not billed. |
|
|
260
|
+
| `not_found` | async job ID unknown (e.g. bad `job_id` to `scrape_status` / `scrape_result`). |
|
|
261
|
+
| `request_timeout` | network / read timeout. safe to retry. |
|
|
262
|
+
| `client_closed_request` | caller cancelled before completion. |
|
|
263
|
+
| `internal_server_error` | unhandled server-side failure. |
|
|
264
|
+
| `crawlbrulee_error` | sdk error without a typed name. |
|
|
265
|
+
| `internal_error` | bug in this mcp — please open an issue. |
|
|
248
266
|
|
|
249
267
|
the api docs carry the canonical [error reference](https://crawlbrulee.com/docs/errors) — every error name, what causes it, and how to recover.
|
|
250
268
|
|
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,24 @@ 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 = {
|
|
77
|
+
zero_data_retention_not_enabled: "Zero data retention is not enabled for this organization. Send the request again without `zero_data_retention`, or ask us to turn it on (sales@crawlbrulee.com). Not billed.",
|
|
78
|
+
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."
|
|
79
|
+
};
|
|
67
80
|
function crawlbruleeErrorResult(err) {
|
|
68
81
|
const code = err.errorName ?? "crawlbrulee_error";
|
|
69
82
|
const httpPart = err.status > 0 ? ` (HTTP ${err.status})` : "";
|
|
70
|
-
|
|
83
|
+
const hint = ERROR_HINTS[code];
|
|
84
|
+
const hintPart = hint ? ` ${hint}` : "";
|
|
85
|
+
return textErrorResult(`[${code}] ${err.message}${httpPart}${hintPart}`);
|
|
71
86
|
}
|
|
72
87
|
function textErrorResult(text) {
|
|
73
88
|
return {
|
|
@@ -186,7 +201,8 @@ const Schema_ApiScrapeRequest = z.object({
|
|
|
186
201
|
require_js: z.boolean().default(false).describe("Use a headless browser to render JavaScript before scraping"),
|
|
187
202
|
cleanup: Schema_ApiScrapeCleanup.prefault({ ...DEFAULT_SCRAPE_CLEANUP }),
|
|
188
203
|
proxy: Schema_ApiProxyType.describe("Proxy tier to use for fetching"),
|
|
189
|
-
location: Schema_ApiScrapeLocation.optional()
|
|
204
|
+
location: Schema_ApiScrapeLocation.optional(),
|
|
205
|
+
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.")
|
|
190
206
|
}).strict();
|
|
191
207
|
|
|
192
208
|
//#endregion
|
|
@@ -218,7 +234,8 @@ const Schema_ApiMapRequest = z.object({
|
|
|
218
234
|
max_urls: z.number().int().positive().max(MAX_API_MAP_MAX_URLS).default(DEFAULT_API_MAP_MAX_URLS).describe("Maximum number of URLs to discover and store in the map. Default 5000, maximum 100000. Sitemap discovery stops as soon as this many URLs have been found, so a smaller value is a faster and lighter crawl, not just a smaller answer."),
|
|
219
235
|
page: z.number().int().positive().default(1).describe("Page number for paginated results"),
|
|
220
236
|
limit: z.number().int().positive().max(MAX_API_MAP_PAGE_LIMIT).default(DEFAULT_API_MAP_PAGE_LIMIT).describe("Number of URLs to return per page. Default 5000, maximum 10000."),
|
|
221
|
-
location: Schema_ApiMapLocation.optional()
|
|
237
|
+
location: Schema_ApiMapLocation.optional(),
|
|
238
|
+
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.")
|
|
222
239
|
});
|
|
223
240
|
|
|
224
241
|
//#endregion
|
|
@@ -234,81 +251,6 @@ function openEnum(values) {
|
|
|
234
251
|
return z.union([z.enum(values), z.string()]);
|
|
235
252
|
}
|
|
236
253
|
|
|
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
254
|
//#endregion
|
|
313
255
|
//#region src/schemas/ApiScrapeResponse.ts
|
|
314
256
|
const Schema_ApiViewport = z.looseObject({
|
|
@@ -344,19 +286,25 @@ const Schema_ApiPageLink = z.looseObject({
|
|
|
344
286
|
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
287
|
internal: z.boolean().describe("Whether the link points to the same domain (www and the bare domain are equivalent; other subdomains are external)")
|
|
346
288
|
});
|
|
347
|
-
const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
|
|
289
|
+
const API_RESOLVED_PROXY_TIER_VALUES$1 = ["basic", "advanced"];
|
|
290
|
+
const Schema_CreditCost = z.number().int().nonnegative();
|
|
291
|
+
const Schema_ApiProxyMultiplier = z.number().int().positive();
|
|
292
|
+
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
293
|
const Schema_ApiUsageMeta = z.looseObject({
|
|
349
|
-
|
|
294
|
+
total_credit_cost: Schema_CreditCost.optional().describe("Credits charged for this request. Always equals engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost + zero_data_retention_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."),
|
|
295
|
+
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."),
|
|
296
|
+
proxy_multiplier: Schema_ApiProxyMultiplier.optional().describe(PROXY_MULTIPLIER_DESCRIPTION),
|
|
297
|
+
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."),
|
|
298
|
+
zero_data_retention_credit_cost: Schema_CreditCost.optional().describe("Credits added by zero data retention: 1 on a billed, fresh result, else 0. Older api versions do not send it."),
|
|
350
299
|
engine: openEnum([
|
|
351
300
|
"http",
|
|
352
301
|
"browser",
|
|
353
302
|
"screenshot",
|
|
354
303
|
"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
|
-
screenshot_slices: z.number().int().nonnegative().describe("Whether this request was billed the screenshot-split add-on: 1 when the screenshot was split on this request (a flat +1 credit outside the proxy multiplier, regardless of how many slices the split produced), else 0 — including a cache hit that reused an already-existing slice variant.")
|
|
304
|
+
]).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."),
|
|
305
|
+
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.")
|
|
358
306
|
});
|
|
359
|
-
const Schema_ApiResponseMeta = z.looseObject({ usage: Schema_ApiUsageMeta.describe("
|
|
307
|
+
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 + zero_data_retention_credit_cost, plus the billed engine and the resolved proxy tier.") });
|
|
360
308
|
const Schema_ApiScrapeMeta = z.looseObject({
|
|
361
309
|
title: z.string().optional().describe("Page title from the <title> tag"),
|
|
362
310
|
description: z.string().optional().describe("Meta description"),
|
|
@@ -384,6 +332,7 @@ const Schema_ApiScrapeMeta = z.looseObject({
|
|
|
384
332
|
const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
385
333
|
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
334
|
requested_url: z.string().describe("The URL you requested, echoed verbatim — before any redirects"),
|
|
335
|
+
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
336
|
content_type: z.string().optional().describe("Content-Type header returned by the server"),
|
|
388
337
|
unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
|
|
389
338
|
markdown: z.string().optional().describe("Page content converted to clean Markdown"),
|
|
@@ -394,8 +343,90 @@ const Schema_ApiScrapeSuccessResponse = z.looseObject({
|
|
|
394
343
|
screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
|
|
395
344
|
metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
|
|
396
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` / `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
|
|
346
|
+
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
|
+
});
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/schemas/ApiMapResponse.ts
|
|
351
|
+
const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
|
|
352
|
+
/** Which limit stopped sitemap discovery first. The FIRST limit to fire wins. */
|
|
353
|
+
const DISCOVERY_CAP_REASONS = [
|
|
354
|
+
"max_urls",
|
|
355
|
+
"time",
|
|
356
|
+
"file_budget",
|
|
357
|
+
"depth",
|
|
358
|
+
"file_size",
|
|
359
|
+
"unread_files"
|
|
360
|
+
];
|
|
361
|
+
/** Map usage has no screenshot-slice add-on. The new parts are optional: older api versions do not send them. */
|
|
362
|
+
const Schema_ApiMapUsageMeta = z.looseObject({
|
|
363
|
+
total_credit_cost: z.number().int().nonnegative().optional().describe("Credits charged for this map request. Always equals engine_credit_cost × proxy_multiplier + zero_data_retention_credit_cost. 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."),
|
|
364
|
+
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."),
|
|
365
|
+
proxy_multiplier: Schema_ApiProxyMultiplier.optional().describe(PROXY_MULTIPLIER_DESCRIPTION),
|
|
366
|
+
zero_data_retention_credit_cost: z.number().int().nonnegative().optional().describe("Credits added by zero data retention: 1 on a billed, fresh result, else 0. Older api versions do not send it."),
|
|
367
|
+
engine: openEnum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
|
|
368
|
+
proxy: openEnum(API_RESOLVED_PROXY_TIER_VALUES).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
|
|
398
369
|
});
|
|
370
|
+
const Schema_ApiMapLinkItem = z.looseObject({ url: z.string().describe("The discovered URL") });
|
|
371
|
+
const Schema_ApiMapPagination = z.looseObject({
|
|
372
|
+
page: z.number().int().positive().describe("Current page number"),
|
|
373
|
+
limit: z.number().int().positive().describe("Number of items per page"),
|
|
374
|
+
total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
|
|
375
|
+
total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
|
|
376
|
+
has_more: z.boolean().describe("Whether more pages are available")
|
|
377
|
+
});
|
|
378
|
+
const Schema_ApiMapTruncation = z.looseObject({
|
|
379
|
+
storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
|
|
380
|
+
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."),
|
|
381
|
+
total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
|
|
382
|
+
total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
|
|
383
|
+
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."),
|
|
384
|
+
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."),
|
|
385
|
+
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.")
|
|
386
|
+
});
|
|
387
|
+
const Schema_ApiMapResult = z.looseObject({
|
|
388
|
+
links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
|
|
389
|
+
response_meta: z.looseObject({
|
|
390
|
+
pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
|
|
391
|
+
truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
|
|
392
|
+
usage: Schema_ApiMapUsageMeta.describe("What this map request cost: total_credit_cost = engine_credit_cost × proxy_multiplier + zero_data_retention_credit_cost, plus the billed engine and the resolved proxy tier.")
|
|
393
|
+
}).describe("Response metadata including pagination, truncation, and usage info")
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/tools/map.ts
|
|
398
|
+
const DESCRIPTION$6 = [
|
|
399
|
+
"Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
|
|
400
|
+
"link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
|
|
401
|
+
"Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
|
|
402
|
+
"scraping selected pages.",
|
|
403
|
+
"`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
|
|
404
|
+
"stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
|
|
405
|
+
"A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
|
|
406
|
+
"signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
|
|
407
|
+
"\"max_urls\", ask again with a higher `max_urls` to get more; \"unread_files\" means a sitemap file",
|
|
408
|
+
"could not be read this time and is often temporary, so asking again later can return more;",
|
|
409
|
+
"\"time\", \"file_budget\", \"depth\" and \"file_size\" mean the site itself is big, slow or deep and a",
|
|
410
|
+
"retry will not help. `discovery_capped` says discovery stopped early, `sitemaps_skipped` how",
|
|
411
|
+
"many sitemap files were skipped or only partly read.",
|
|
412
|
+
"`limit` (default 5000, max 10000) only pages the answer.",
|
|
413
|
+
"Set `zero_data_retention: true` to keep the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. It adds 1 credit and must be enabled for the organization (else a `zero_data_retention_not_enabled` error, not billed). See https://crawlbrulee.com/docs/zero-data-retention.",
|
|
414
|
+
"Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
|
|
415
|
+
"map-then-scrape stays on one host. Results are ordered with the most useful links first.",
|
|
416
|
+
"The response carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
417
|
+
"`proxy_multiplier` + `zero_data_retention_credit_cost`, plus `engine` and `proxy` (the resolved tier, never `auto`). Map has no screenshot slicing and no",
|
|
418
|
+
"`page_status_code`: it reads many files, not one page. A map that found nothing because the site",
|
|
419
|
+
"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",
|
|
420
|
+
"tool can return a `target_unreachable` error (HTTP 502, not billed): retry later or check the URL."
|
|
421
|
+
].join(" ");
|
|
422
|
+
function registerMapTool(server, getClient) {
|
|
423
|
+
server.registerTool("map", {
|
|
424
|
+
title: "Map a website",
|
|
425
|
+
description: DESCRIPTION$6,
|
|
426
|
+
inputSchema: Schema_ApiMapRequest.shape,
|
|
427
|
+
outputSchema: Schema_ApiMapResult
|
|
428
|
+
}, (args) => runTool(async () => await getClient().map(args)));
|
|
429
|
+
}
|
|
399
430
|
|
|
400
431
|
//#endregion
|
|
401
432
|
//#region src/tools/scrape.ts
|
|
@@ -403,10 +434,19 @@ const DESCRIPTION$5 = [
|
|
|
403
434
|
"Fetch a single URL via the crawlbrulee scraping API and return the requested content",
|
|
404
435
|
"(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
|
|
405
436
|
"Use this for one-shot page extraction. For full-site discovery use the `map` tool first.",
|
|
437
|
+
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
438
|
+
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
439
|
+
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
440
|
+
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
441
|
+
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
442
|
+
"If the site cannot be reached at all the tool returns a `target_unreachable` error (HTTP 502,",
|
|
443
|
+
"not billed): retry later or check the URL.",
|
|
406
444
|
"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
|
-
"`
|
|
445
|
+
"The response also carries `response_meta.usage`: `total_credit_cost` = `engine_credit_cost` ×",
|
|
446
|
+
"`proxy_multiplier` + `screenshot_slicing_credit_cost` + `zero_data_retention_credit_cost`, plus `engine` and `proxy` (the resolved",
|
|
447
|
+
"tier — never `auto`). `engine` is the billed engine (`http`, `browser`, `screenshot`, `cache`); a",
|
|
448
|
+
"cache hit is represented by `engine: \"cache\"`.",
|
|
449
|
+
"Set `zero_data_retention: true` to keep the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. It adds 1 credit and must be enabled for the organization (else a `zero_data_retention_not_enabled` error, not billed). See https://crawlbrulee.com/docs/zero-data-retention.",
|
|
410
450
|
"Extraction is capped per page: 30,000 links, 10,000 inline images and 10,000,000 characters of",
|
|
411
451
|
"HTML. A page past a cap is truncated rather than refused, and the response `warnings` array names",
|
|
412
452
|
"which one (`links_truncated`, `inline_images_truncated`, `raw_html_truncated`) — so treat that",
|
|
@@ -451,8 +491,8 @@ const Schema_ApiScrapeStatusResponse = z.looseObject({
|
|
|
451
491
|
job_id: z.string().describe("The job identifier"),
|
|
452
492
|
status: openEnum(ASYNC_JOB_STATUS_VALUES).describe("Current state of the job (pending, running, done, failed)"),
|
|
453
493
|
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
|
|
494
|
+
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`."),
|
|
495
|
+
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
496
|
});
|
|
457
497
|
|
|
458
498
|
//#endregion
|
|
@@ -466,7 +506,8 @@ const DESCRIPTION$4 = [
|
|
|
466
506
|
"Optionally attach a per-job completion `webhook`: we deliver a single",
|
|
467
507
|
"signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
|
|
468
508
|
"in production), and echoes your opaque `webhook.metadata` back in the delivery",
|
|
469
|
-
"(under `data.metadata`, alongside `data.response_meta.usage`)."
|
|
509
|
+
"(under `data.metadata`, alongside `data.page_status_code` (on success) and `data.response_meta.usage`).",
|
|
510
|
+
"Set `zero_data_retention: true` to keep the result out of the shared cache; anything stored to deliver it is kept for 24 hours, then deleted. It adds 1 credit and must be enabled for the organization (else a `zero_data_retention_not_enabled` error, not billed). See https://crawlbrulee.com/docs/zero-data-retention."
|
|
470
511
|
].join(" ");
|
|
471
512
|
function registerScrapeAsyncTool(server, getClient) {
|
|
472
513
|
server.registerTool("scrape_async", {
|
|
@@ -484,6 +525,11 @@ const DESCRIPTION$3 = [
|
|
|
484
525
|
"synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot,",
|
|
485
526
|
"page metadata in `metadata`, and `response_meta.usage`). Errors if the job is still",
|
|
486
527
|
"`pending`/`running` — check `scrape_status` first (status `done`) before calling this.",
|
|
528
|
+
"Check `page_status_code` before you trust the content: it is the HTTP status the site answered",
|
|
529
|
+
"with for the final page. A page the site served is a successful result whatever its status, so a",
|
|
530
|
+
"404 or 503 page comes back with its content, not as an error. A 404 means the markdown is the",
|
|
531
|
+
"site's \"not found\" page, not the page you asked for. 2xx and 4xx pages are billed, except 403,",
|
|
532
|
+
"407, 408, 429 and 451; 5xx pages are never billed.",
|
|
487
533
|
"Screenshot URLs are signed download links."
|
|
488
534
|
].join(" ");
|
|
489
535
|
function registerScrapeResultTool(server, getClient) {
|
|
@@ -500,9 +546,12 @@ function registerScrapeResultTool(server, getClient) {
|
|
|
500
546
|
const DESCRIPTION$2 = [
|
|
501
547
|
"Look up the current lifecycle status of an async scrape job submitted via `scrape_async`.",
|
|
502
548
|
"Returns the job state (`pending`, `running`, `done`, `failed`), with an `error` message",
|
|
503
|
-
"when it failed and a `response_meta.usage` block (
|
|
504
|
-
"
|
|
505
|
-
"
|
|
549
|
+
"when it failed and a `response_meta.usage` block (total_credit_cost and its parts, billed engine,",
|
|
550
|
+
"resolved proxy tier) once it is `done`. A job whose page the site served ends `done` even when",
|
|
551
|
+
"that page is a 404 or 503 — read `page_status_code` in the result. A job that could not reach",
|
|
552
|
+
"the site at all ends `failed` (the `error` text is a general message, not the reason) and is not",
|
|
553
|
+
"billed; retry later or check the url. Poll this until the status is",
|
|
554
|
+
"`done`, then call `scrape_result` to fetch",
|
|
506
555
|
"the page. If you registered a completion webhook on submit you can skip polling and react",
|
|
507
556
|
"to the delivery instead."
|
|
508
557
|
].join(" ");
|
|
@@ -569,7 +618,7 @@ function registerWhoamiTool(server, getClient) {
|
|
|
569
618
|
//#endregion
|
|
570
619
|
//#region src/version.ts
|
|
571
620
|
const SERVER_NAME = "crawlbrulee";
|
|
572
|
-
const SERVER_VERSION = "1.0
|
|
621
|
+
const SERVER_VERSION = "1.2.0";
|
|
573
622
|
|
|
574
623
|
//#endregion
|
|
575
624
|
//#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.2.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.2.0",
|
|
67
67
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
68
68
|
"zod": "^4.0.0"
|
|
69
69
|
},
|