@crawlbrulee/mcp 1.0.2 → 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.
Files changed (3) hide show
  1. package/README.md +21 -7
  2. package/dist/index.js +179 -113
  3. 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
- "credits": 1,
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
- "screenshot_slices": 0, // 1 when the screenshot-split add-on was billed, otherwise 0
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 (`credits`, billed `engine`, resolved `proxy` tier, `screenshot_slices`). a cache hit is represented by `engine: "cache"`. poll until `done`, then call `scrape_result`.
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 (`credits`, billed `engine`, resolved `proxy` tier). map responses do not include screenshot-slice accounting.
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
- | `scrape_error` | origin returned an error during scraping. |
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
- return textErrorResult(`[${code}] ${err.message}${httpPart}`);
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 {
@@ -222,129 +234,80 @@ const Schema_ApiMapRequest = z.object({
222
234
  });
223
235
 
224
236
  //#endregion
225
- //#region src/schemas/ApiMapResponse.ts
226
- const API_RESOLVED_PROXY_TIER_VALUES$1 = ["basic", "advanced"];
227
- /** Which limit stopped sitemap discovery first. The FIRST limit to fire wins. */
228
- const DISCOVERY_CAP_REASONS = [
229
- "max_urls",
230
- "time",
231
- "file_budget",
232
- "depth",
233
- "file_size",
234
- "unread_files"
235
- ];
236
- /** Map usage has no screenshot-slice add-on. */
237
- const Schema_ApiMapUsageMeta = z.object({
238
- credits: z.number().int().nonnegative().describe("Credits charged for this map request"),
239
- engine: z.enum(["http", "cache"]).describe("The map billing engine: `http` for fresh discovery or `cache` for a cached result"),
240
- proxy: z.enum(API_RESOLVED_PROXY_TIER_VALUES$1).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
241
- });
242
- const Schema_ApiMapLinkItem = z.object({ url: z.string().describe("The discovered URL") });
243
- const Schema_ApiMapPagination = z.object({
244
- page: z.number().int().positive().describe("Current page number"),
245
- limit: z.number().int().positive().describe("Number of items per page"),
246
- total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
247
- total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
248
- has_more: z.boolean().describe("Whether more pages are available")
249
- });
250
- const Schema_ApiMapTruncation = z.object({
251
- storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
252
- 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."),
253
- total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
254
- total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
255
- 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."),
256
- 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."),
257
- discovery_cap_reason: z.enum(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.")
258
- });
259
- const Schema_ApiMapResult = z.object({
260
- links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
261
- response_meta: z.object({
262
- pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
263
- truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
264
- usage: Schema_ApiMapUsageMeta.describe("Usage accounting for this map request: credits charged, the billed engine, and the resolved proxy tier.")
265
- }).describe("Response metadata including pagination, truncation, and usage info")
266
- });
267
-
268
- //#endregion
269
- //#region src/tools/map.ts
270
- const DESCRIPTION$6 = [
271
- "Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
272
- "link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
273
- "Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
274
- "scraping selected pages.",
275
- "`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
276
- "stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
277
- "A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
278
- "signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
279
- "\"max_urls\", ask again with a higher `max_urls` to get more; \"unread_files\" means a sitemap file",
280
- "could not be read this time and is often temporary, so asking again later can return more;",
281
- "\"time\", \"file_budget\", \"depth\" and \"file_size\" mean the site itself is big, slow or deep and a",
282
- "retry will not help. `discovery_capped` says discovery stopped early, `sitemaps_skipped` how",
283
- "many sitemap files were skipped or only partly read.",
284
- "`limit` (default 5000, max 10000) only pages the answer.",
285
- "Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
286
- "map-then-scrape stays on one host. Results are ordered with the most useful links first.",
287
- "The response carries `response_meta.usage` = { credits, engine, proxy } — the resolved proxy",
288
- "tier is never `auto`; map responses do not include screenshot-slice accounting."
289
- ].join(" ");
290
- function registerMapTool(server, getClient) {
291
- server.registerTool("map", {
292
- title: "Map a website",
293
- description: DESCRIPTION$6,
294
- inputSchema: Schema_ApiMapRequest.shape,
295
- outputSchema: Schema_ApiMapResult.shape
296
- }, (args) => runTool(async () => await getClient().map(args)));
237
+ //#region src/schemas/openEnum.ts
238
+ /**
239
+ * A response enum the api may extend later. The known values still show up in the
240
+ * tool's output schema, so a reader sees them, but any string is accepted: a value
241
+ * added on the server must not make a validating host refuse the whole result.
242
+ *
243
+ * Output only. Request enums stay closed, so a typo in tool input is still caught.
244
+ */
245
+ function openEnum(values) {
246
+ return z.union([z.enum(values), z.string()]);
297
247
  }
298
248
 
299
249
  //#endregion
300
250
  //#region src/schemas/ApiScrapeResponse.ts
301
- const Schema_ApiViewport = z.object({
251
+ const Schema_ApiViewport = z.looseObject({
302
252
  width: z.number().describe("Viewport width in pixels"),
303
253
  height: z.number().describe("Viewport height in pixels"),
304
254
  device_scale_factor: z.number().describe("Device pixel ratio used for the capture")
305
255
  });
306
- const Schema_ApiScreenshotProperties = z.object({
256
+ const Schema_ApiScreenshotProperties = z.looseObject({
307
257
  file_name: z.string().describe("File name of the screenshot image"),
308
258
  mime: z.string().describe("MIME type of the screenshot (e.g. image/png)"),
309
259
  width: z.number().describe("Image width in pixels"),
310
260
  height: z.number().describe("Image height in pixels"),
311
261
  viewport: Schema_ApiViewport.describe("Viewport dimensions used during capture")
312
262
  });
313
- const Schema_ApiScreenshotSlice = z.object({
263
+ const Schema_ApiScreenshotSlice = z.looseObject({
314
264
  row_nr: z.number().describe("Row index of this slice (0-based)"),
315
265
  url: z.string().describe("URL to download this slice image"),
316
266
  type: z.literal("slice").describe("Slice type identifier"),
317
267
  properties: Schema_ApiScreenshotProperties.describe("Image properties for this slice")
318
268
  });
319
- const Schema_ApiScreenshotResponse = z.object({
269
+ const Schema_ApiScreenshotResponse = z.looseObject({
320
270
  url: z.string().describe("URL to download the full screenshot image"),
321
- type: Schema_ApiScrapeScreenshotType.describe("Screenshot capture mode that was used"),
271
+ type: openEnum(["viewport", "full_page"]).describe("Screenshot capture mode that was used"),
322
272
  properties: Schema_ApiScreenshotProperties.describe("Image properties for the full screenshot"),
323
273
  slices: z.array(Schema_ApiScreenshotSlice).optional().describe("Individual tile slices (present when slice action_after was requested)")
324
274
  });
325
- const Schema_ApiPageInlineImgItem = z.object({
275
+ const Schema_ApiPageInlineImgItem = z.looseObject({
326
276
  url: z.string().describe("Absolute URL of the image"),
327
277
  alt: z.string().nullable().describe("Alt text of the image, or null if not set")
328
278
  });
329
- const Schema_ApiPageLink = z.object({
279
+ const Schema_ApiPageLink = z.looseObject({
330
280
  text: z.string().describe("Anchor text of the link"),
331
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)"),
332
282
  internal: z.boolean().describe("Whether the link points to the same domain (www and the bare domain are equivalent; other subdomains are external)")
333
283
  });
334
- const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
335
- const Schema_ApiUsageMeta = z.object({
336
- credits: z.number().int().nonnegative().describe("Credits actually charged for this request. Always equals the engine base × the proxy multiplier, plus screenshot_slices. A cache hit has engine \"cache\" (base 0), so it costs only the parts we still had to compute — a newly produced screenshot-slice variant — and is otherwise free."),
337
- engine: z.enum([
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.";
288
+ const Schema_ApiUsageMeta = z.looseObject({
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."),
293
+ engine: openEnum([
338
294
  "http",
339
295
  "browser",
340
296
  "screenshot",
341
297
  "cache"
342
- ]).describe("The engine base the request was billed at — \"http\" (1 credit), \"browser\" (3), \"screenshot\" (5), or \"cache\" (0, the result was served from cache) — before the proxy multiplier. Reflects what was delivered, never what was requested."),
343
- proxy: z.enum(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`)."),
344
- 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.")
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()
345
308
  });
346
- const Schema_ApiResponseMeta = z.object({ usage: Schema_ApiUsageMeta.describe("Usage accounting for this request: credits charged, billed engine, resolved proxy tier, and screenshot-slice add-on.") });
347
- const Schema_ApiScrapeMeta = z.object({
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.") });
310
+ const Schema_ApiScrapeMeta = z.looseObject({
348
311
  title: z.string().optional().describe("Page title from the <title> tag"),
349
312
  description: z.string().optional().describe("Meta description"),
350
313
  keywords: z.array(z.string()).optional().describe("Meta keywords"),
@@ -368,9 +331,10 @@ const Schema_ApiScrapeMeta = z.object({
368
331
  robots: z.string().optional().describe("Robots meta directive (e.g. noindex, nofollow)"),
369
332
  favicon_url: z.string().nullish().describe("Resolved favicon URL for the page (best-effort, from <head> icon hints + manifest)")
370
333
  });
371
- const Schema_ApiScrapeSuccessResponse = z.object({
334
+ const Schema_ApiScrapeSuccessResponse = z.looseObject({
372
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"),
373
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."),
374
338
  content_type: z.string().optional().describe("Content-Type header returned by the server"),
375
339
  unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
376
340
  markdown: z.string().optional().describe("Page content converted to clean Markdown"),
@@ -381,19 +345,113 @@ const Schema_ApiScrapeSuccessResponse = z.object({
381
345
  screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
382
346
  metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
383
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."),
384
- response_meta: Schema_ApiResponseMeta.describe("Request-level metadata. `response_meta.usage` reports credits charged, the billed engine, the resolved proxy tier, and any screenshot-slice add-on.")
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()
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")
385
399
  });
386
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
+ }
435
+
387
436
  //#endregion
388
437
  //#region src/tools/scrape.ts
389
438
  const DESCRIPTION$5 = [
390
439
  "Fetch a single URL via the crawlbrulee scraping API and return the requested content",
391
440
  "(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
392
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.",
393
449
  "Screenshot URLs in the response are signed download links — the agent can fetch them when needed.",
394
- "The response also carries `response_meta.usage` = { credits, engine, proxy (the resolved tier —",
395
- "never `auto`), screenshot_slices }. `engine` is the billed engine (`http`, `browser`, `screenshot`,",
396
- "`cache`); a cache hit is represented by `engine: \"cache\"`, so you can see what the request cost.",
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`.",
397
455
  "Extraction is capped per page: 30,000 links, 10,000 inline images and 10,000,000 characters of",
398
456
  "HTML. A page past a cap is truncated rather than refused, and the response `warnings` array names",
399
457
  "which one (`links_truncated`, `inline_images_truncated`, `raw_html_truncated`) — so treat that",
@@ -412,7 +470,7 @@ function registerScrapeTool(server, getClient) {
412
470
  title: "Scrape a URL",
413
471
  description: DESCRIPTION$5,
414
472
  inputSchema: Schema_ApiScrapeRequest.shape,
415
- outputSchema: Schema_ApiScrapeSuccessResponse.shape
473
+ outputSchema: Schema_ApiScrapeSuccessResponse
416
474
  }, (args) => runTool(async () => await getClient().scrape(args)));
417
475
  }
418
476
 
@@ -433,13 +491,13 @@ const ASYNC_JOB_STATUS_VALUES = [
433
491
  "failed"
434
492
  ];
435
493
  const Schema_AsyncJobId = z.object({ job_id: z.string().describe("Job identifier returned by the `scrape_async` tool") });
436
- const Schema_ApiScrapeAsyncResponse = z.object({ job_id: z.string().describe("Job identifier — pass it to the `scrape_status` / `scrape_result` tools") });
437
- const Schema_ApiScrapeStatusResponse = z.object({
494
+ const Schema_ApiScrapeAsyncResponse = z.looseObject({ job_id: z.string().describe("Job identifier — pass it to the `scrape_status` / `scrape_result` tools") });
495
+ const Schema_ApiScrapeStatusResponse = z.looseObject({
438
496
  job_id: z.string().describe("The job identifier"),
439
- status: z.enum(ASYNC_JOB_STATUS_VALUES).describe("Current state of the job (pending, running, done, failed)"),
497
+ status: openEnum(ASYNC_JOB_STATUS_VALUES).describe("Current state of the job (pending, running, done, failed)"),
440
498
  created_at: z.string().describe("ISO-8601 UTC timestamp when the job was created"),
441
- error: z.string().optional().describe("Error message if the job ended in `failed`"),
442
- response_meta: Schema_ApiResponseMeta.optional().describe("Usage accounting for the finished job. Present only once the job is `done`; `response_meta.usage` reports credits charged, the billed engine, the resolved proxy tier, and any screenshot-slice add-on.")
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.")
443
501
  });
444
502
 
445
503
  //#endregion
@@ -453,14 +511,14 @@ const DESCRIPTION$4 = [
453
511
  "Optionally attach a per-job completion `webhook`: we deliver a single",
454
512
  "signed `scrape.complete` POST to your endpoint when the job finishes (HTTPS required",
455
513
  "in production), and echoes your opaque `webhook.metadata` back in the delivery",
456
- "(under `data.metadata`, alongside `data.response_meta.usage`)."
514
+ "(under `data.metadata`, alongside `data.page_status_code` (on success) and `data.response_meta.usage`)."
457
515
  ].join(" ");
458
516
  function registerScrapeAsyncTool(server, getClient) {
459
517
  server.registerTool("scrape_async", {
460
518
  title: "Scrape a URL asynchronously",
461
519
  description: DESCRIPTION$4,
462
520
  inputSchema: Schema_ApiScrapeAsyncRequest.shape,
463
- outputSchema: Schema_ApiScrapeAsyncResponse.shape
521
+ outputSchema: Schema_ApiScrapeAsyncResponse
464
522
  }, (args) => runTool(async () => await getClient().scrapeAsync(args)));
465
523
  }
466
524
 
@@ -471,6 +529,11 @@ const DESCRIPTION$3 = [
471
529
  "synchronous `scrape` tool: markdown, cleaned HTML, raw HTML, links, images, screenshot,",
472
530
  "page metadata in `metadata`, and `response_meta.usage`). Errors if the job is still",
473
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.",
474
537
  "Screenshot URLs are signed download links."
475
538
  ].join(" ");
476
539
  function registerScrapeResultTool(server, getClient) {
@@ -478,7 +541,7 @@ function registerScrapeResultTool(server, getClient) {
478
541
  title: "Get an async scrape job result",
479
542
  description: DESCRIPTION$3,
480
543
  inputSchema: Schema_AsyncJobId.shape,
481
- outputSchema: Schema_ApiScrapeSuccessResponse.shape
544
+ outputSchema: Schema_ApiScrapeSuccessResponse
482
545
  }, (args) => runTool(async () => await getClient().getScrapeResult(args.job_id)));
483
546
  }
484
547
 
@@ -487,9 +550,12 @@ function registerScrapeResultTool(server, getClient) {
487
550
  const DESCRIPTION$2 = [
488
551
  "Look up the current lifecycle status of an async scrape job submitted via `scrape_async`.",
489
552
  "Returns the job state (`pending`, `running`, `done`, `failed`), with an `error` message",
490
- "when it failed and a `response_meta.usage` block (credits, billed engine, resolved proxy tier,",
491
- "screenshot_slices) once it is",
492
- "`done`. Poll this until the status is `done`, then call `scrape_result` to fetch",
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",
493
559
  "the page. If you registered a completion webhook on submit you can skip polling and react",
494
560
  "to the delivery instead."
495
561
  ].join(" ");
@@ -498,13 +564,13 @@ function registerScrapeStatusTool(server, getClient) {
498
564
  title: "Check an async scrape job status",
499
565
  description: DESCRIPTION$2,
500
566
  inputSchema: Schema_AsyncJobId.shape,
501
- outputSchema: Schema_ApiScrapeStatusResponse.shape
567
+ outputSchema: Schema_ApiScrapeStatusResponse
502
568
  }, (args) => runTool(async () => await getClient().getScrapeStatus(args.job_id)));
503
569
  }
504
570
 
505
571
  //#endregion
506
572
  //#region src/schemas/ApiUsageResponse.ts
507
- const Schema_ApiUsageResponse = z.object({
573
+ const Schema_ApiUsageResponse = z.looseObject({
508
574
  total_credits: z.number().int().nonnegative().describe("Total credits available for the current billing cycle (plan base + purchased + gifted)."),
509
575
  used_credits: z.number().int().nonnegative().describe("Credits spent so far in the current billing cycle. May exceed total_credits on plans that allow overages."),
510
576
  available_credits: z.number().int().nonnegative().describe("Remaining credits (max(0, total_credits - used_credits)). Clamped to 0 when in overage."),
@@ -525,13 +591,13 @@ function registerUsageTool(server, getClient) {
525
591
  title: "Get current usage",
526
592
  description: DESCRIPTION$1,
527
593
  inputSchema: {},
528
- outputSchema: Schema_ApiUsageResponse.shape
594
+ outputSchema: Schema_ApiUsageResponse
529
595
  }, () => runTool(async () => await getClient().usage()));
530
596
  }
531
597
 
532
598
  //#endregion
533
599
  //#region src/schemas/ApiWhoamiResponse.ts
534
- const Schema_ApiWhoamiResponse = z.object({
600
+ const Schema_ApiWhoamiResponse = z.looseObject({
535
601
  organization_name: z.string().describe("Display name of the organization that owns the token."),
536
602
  token_name: z.string().describe("User-assigned name of the API token authenticating the request."),
537
603
  token_preview: z.string().describe("Truncated preview of the API token (e.g. `cwbl_…xyz`). Safe to display; does not authenticate.")
@@ -549,14 +615,14 @@ function registerWhoamiTool(server, getClient) {
549
615
  title: "Identify the API token",
550
616
  description: DESCRIPTION,
551
617
  inputSchema: {},
552
- outputSchema: Schema_ApiWhoamiResponse.shape
618
+ outputSchema: Schema_ApiWhoamiResponse
553
619
  }, () => runTool(async () => await getClient().whoami()));
554
620
  }
555
621
 
556
622
  //#endregion
557
623
  //#region src/version.ts
558
624
  const SERVER_NAME = "crawlbrulee";
559
- const SERVER_VERSION = "1.0.2";
625
+ const SERVER_VERSION = "1.1.0";
560
626
 
561
627
  //#endregion
562
628
  //#region src/server.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlbrulee/mcp",
3
- "version": "1.0.2",
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.0.0",
66
+ "@crawlbrulee/sdk": "^1.1.0",
67
67
  "@modelcontextprotocol/sdk": "^1.29.0",
68
68
  "zod": "^4.0.0"
69
69
  },