@crawlbrulee/mcp 0.8.1 → 0.12.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 +35 -8
  2. package/dist/index.js +128 -67
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -13,7 +13,7 @@ the official [mcp](https://modelcontextprotocol.io) server for the [crawlbrulee]
13
13
  this readme covers the mcp server itself — its tools and how to wire it into a host. for how the api behaves — endpoints, parameters, and error semantics — please see our
14
14
  [api docs](https://crawlbrulee.com/docs).
15
15
 
16
- > **status:** v0.8.1 (beta). tool surface is stabilizing — expect minor changes between 0.x releases.
16
+ > **status:** v0.12.0 (beta). tool surface is stabilizing — expect minor changes between 0.x releases.
17
17
 
18
18
  **get a free api key** → [dashboard.crawlbrulee.com](https://dashboard.crawlbrulee.com)
19
19
 
@@ -75,7 +75,7 @@ html, raw html, links, images, screenshot, page metadata).
75
75
  },
76
76
  "require_js": false,
77
77
  "proxy": "basic",
78
- "exclude_selectors": ["nav", "footer"],
78
+ "cleanup": { "ads_and_popups": true, "exclude_selectors": ["nav", "footer"] },
79
79
  "cache": { "max_age": 3600 },
80
80
  "location": { "locale": "en-US", "country": "US" },
81
81
  }
@@ -90,9 +90,10 @@ html, raw html, links, images, screenshot, page metadata).
90
90
  "metadata": { "title": "Example Domain" },
91
91
  "response_meta": {
92
92
  "usage": {
93
- "credits": 1, // 0 on a fully cached result — only parts still computed fresh are charged
93
+ "credits": 1,
94
+ "engine": "text", // "text" | "browser" | "screenshot" | "cache"
94
95
  "proxy": "basic", // resolved tier actually used: "basic" | "advanced" (never "auto")
95
- "cache_hit": false, // whether the result was served from cache
96
+ "screenshot_slices": 0, // 1 when the screenshot-split add-on was billed, otherwise 0
96
97
  },
97
98
  },
98
99
  }
@@ -135,13 +136,13 @@ takes the same input as `scrape` plus an optional per-job completion `webhook`:
135
136
 
136
137
  **output** — `{ "job_id": "..." }`.
137
138
 
138
- when a `webhook` is attached, we deliver a single signed `scrape.complete` POST to your endpoint once the job reaches a terminal state, with your `metadata` echoed under `data.metadata` and the job's usage under `data.response_meta.usage` — so you can react to completion (and reconcile cost) without polling. verify the `X-Cwbl-Signature` header with the sdk's `verifyWebhookSignature` (configure the signing secret in the dashboard under account → webhooks).
139
+ when a `webhook` is attached, we deliver a single signed `scrape.complete` POST to your endpoint once the job reaches a terminal state, with your `metadata` echoed under `data.metadata` and the job's usage under `data.response_meta.usage` — so you can react to completion (and track cost) without polling. verify the `X-Cwbl-Signature` header with the sdk's `verifyWebhookSignature` (configure the signing secret in the dashboard under account → webhooks).
139
140
 
140
141
  the job lifecycle is documented under [async scrape](https://crawlbrulee.com/docs/scrape/async); the delivery contract and payload shape under [webhooks](https://crawlbrulee.com/docs/scrape/webhooks), with the signature scheme in [webhook verification](https://crawlbrulee.com/docs/webhook-verification).
141
142
 
142
143
  ### `scrape_status`
143
144
 
144
- 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`, resolved `proxy` tier, `cache_hit`). poll until `done`, then call `scrape_result`.
145
+ 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`.
145
146
 
146
147
  ```jsonc
147
148
  { "job_id": "..." }
@@ -157,7 +158,13 @@ fetch the extracted content of a completed async job — the same result shape a
157
158
 
158
159
  ### `map`
159
160
 
160
- build (or fetch a cached) link-map for a website. combines sitemap discovery with homepage link extraction. use this to enumerate a site before scraping selected pages. the response's `response_meta` carries `pagination`, `truncation`, and a `usage` block (`credits`, resolved `proxy` tier, `cache_hit`).
161
+ build (or fetch a cached) link-map for a website. combines sitemap discovery with homepage link extraction. use this to enumerate a site before scraping selected pages. each link is just `{ url }`.
162
+
163
+ `max_urls` (default `5000`, max `100000`) is a discovery budget, not a trim at the end — discovery stops as soon as that many urls are found, so a smaller value is a faster, cheaper crawl. `limit` (default `5000`, max `10000`) only pages the answer.
164
+
165
+ 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.
166
+
167
+ 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.
161
168
 
162
169
  ```jsonc
163
170
  {
@@ -170,6 +177,24 @@ build (or fetch a cached) link-map for a website. combines sitemap discovery wit
170
177
  }
171
178
  ```
172
179
 
180
+ 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`:
181
+
182
+ ```jsonc
183
+ {
184
+ "truncation": {
185
+ "storage_capped": false,
186
+ "response_capped": false,
187
+ "total_before_max_urls": 5000,
188
+ "total_detected_before_storage_cap": 5000,
189
+ "discovery_capped": true, // discovery stopped before reading every sitemap file
190
+ "sitemaps_skipped": 3, // files skipped or only partly read
191
+ "discovery_cap_reason": "max_urls", // retry with a higher max_urls; other reasons won't help
192
+ },
193
+ }
194
+ ```
195
+
196
+ `discovery_cap_reason` is one of `max_urls`, `time`, `file_budget`, `depth`, `file_size`, or `null` when nothing stopped discovery. only `max_urls` is worth a retry — the rest mean the site itself is big, slow or deep.
197
+
173
198
  see the [map endpoint](https://crawlbrulee.com/docs/map) for discovery rules and pagination semantics.
174
199
 
175
200
  ### `usage`
@@ -184,7 +209,7 @@ returns the organization name, token name, and truncated token preview for the c
184
209
 
185
210
  ## errors
186
211
 
187
- every tool returns an mcp error envelope (`isError: true`) when the api call fails. the error text follows a stable format:
212
+ every tool returns an mcp error result (`isError: true`) when the api call fails. the error text follows a stable format:
188
213
 
189
214
  ```
190
215
  [<errorName>] <message> (HTTP <status>)
@@ -203,6 +228,8 @@ agents can branch on the `errorName` code. the set comes from the sdk's `ApiErro
203
228
  | `invalid_url` | target url was rejected before fetching. |
204
229
  | `blocked_url` | target url is on the blocklist. |
205
230
  | `antibot_blocked` | origin's anti-bot defenses blocked the fetch. |
231
+ | `too_many_redirects` | origin redirected the fetch in a loop (HTTP 422). the target's doing — don't retry blindly. |
232
+ | `page_too_large` | the page's html was too large to process (HTTP 422). terminal — never retry it. |
206
233
  | `scrape_error` | origin returned an error during scraping. |
207
234
  | `unsupported_screenshot_output` | screenshot-only request on a content type that can't be screenshotted (HTTP 422). not billed. |
208
235
  | `not_found` | async job ID unknown (e.g. bad `job_id` to `scrape_status` / `scrape_result`). |
package/dist/index.js CHANGED
@@ -84,7 +84,6 @@ function textErrorResult(text) {
84
84
  const MAX_SCRAPE_SCREENSHOT_TOTAL_WAIT_MS = 2e4;
85
85
  const MAX_SCRAPE_SCREENSHOT_TOTAL_SCROLL_PIXELS = 5e4;
86
86
  const DEFAULT_SCRAPE_SCREENSHOT_DEVICE_MODE = "desktop";
87
- const DEFAULT_SCRAPE_SCREENSHOT_CLEANUP = { ads_and_popups: true };
88
87
  function getScrapeScreenshotBeforeActionTotals(actions) {
89
88
  let totalWaitMs = 0;
90
89
  let totalAbsoluteScrollPixels = 0;
@@ -101,11 +100,25 @@ function getScrapeScreenshotBeforeActionTotals(actions) {
101
100
  };
102
101
  }
103
102
 
103
+ //#endregion
104
+ //#region src/schemas/ScrapeCleanupSchemas.ts
105
+ /**
106
+ * Mirrors `packages/core/src/model/common/ScrapeCleanup*` in the server repo.
107
+ * Kept in step by hand — this package deliberately does not import from the
108
+ * monorepo. If the server's shape changes, change it here too.
109
+ */
110
+ const DEFAULT_SCRAPE_CLEANUP = { ads_and_popups: true };
111
+ const MAX_SCRAPE_EXCLUDE_SELECTORS = 100;
112
+ const MAX_SCRAPE_EXCLUDE_SELECTOR_LENGTH = 500;
113
+ const Schema_ApiScrapeCleanup = z.object({
114
+ ads_and_popups: z.boolean().default(DEFAULT_SCRAPE_CLEANUP.ads_and_popups).describe("Remove ads, cookie banners, consent dialogs and chat widgets. Defaults to true. Also affects the screenshot. Set it to false to capture the page as-is, or to get past a site that refuses to serve an ad-blocking client."),
115
+ exclude_selectors: z.array(z.string().max(500)).max(100).optional().describe("CSS selectors whose elements are removed before anything is captured. Affects the extracted content and the screenshot, never raw_html. Use it for a banner or widget that ads_and_popups does not recognise. Sending any selector here makes the request skip the cache.")
116
+ }).strict().describe("What is removed from the page before any output is built. Applies to markdown, cleaned_html, links and images on every engine, and to the screenshot. Never applies to raw_html, which is always the page before we removed anything.");
117
+
104
118
  //#endregion
105
119
  //#region src/schemas/ScrapeScreenshotSchemas.ts
106
120
  const Schema_ApiScrapeScreenshotType = z.enum(["viewport", "full_page"]).describe("Screenshot mode: viewport (visible area) or full_page (entire page)");
107
121
  const Schema_ScrapeScreenshotDeviceMode = z.enum(["desktop", "mobile"]).describe("Device mode to emulate for viewport sizing");
108
- const Schema_ScrapeScreenshotCleanup = z.object({ ads_and_popups: z.boolean().default(DEFAULT_SCRAPE_SCREENSHOT_CLEANUP.ads_and_popups).describe("Remove ads, cookie banners, and popups before capturing") }).strict().describe("Page cleanup options applied before screenshot capture");
109
122
  const Schema_ScrapeScreenshotBeforeAction = z.discriminatedUnion("type", [z.object({
110
123
  type: z.literal("wait").describe("Wait for a duration before capturing"),
111
124
  ms: z.number().int().nonnegative().describe("Milliseconds to wait")
@@ -149,7 +162,6 @@ const Schema_ApiScrapeFormatScreenshot = z.object({
149
162
  type: Schema_ApiScrapeScreenshotType.describe("Screenshot capture mode"),
150
163
  viewport: Schema_ApiScrapeViewport.optional().describe("Custom viewport dimensions; uses device_mode defaults if omitted"),
151
164
  device_mode: Schema_ScrapeScreenshotDeviceMode.default(DEFAULT_SCRAPE_SCREENSHOT_DEVICE_MODE).describe("Emulate desktop or mobile device viewport"),
152
- cleanup: Schema_ScrapeScreenshotCleanup.default(DEFAULT_SCRAPE_SCREENSHOT_CLEANUP).describe("Page cleanup options applied before capturing"),
153
165
  actions_before: z.array(Schema_ScrapeScreenshotBeforeAction).max(5).default([]).describe("Actions to perform before taking the screenshot (wait, scroll)"),
154
166
  actions_after: z.array(Schema_ScrapeScreenshotAfterAction).max(1).default([]).describe("Actions to perform after taking the screenshot (e.g. slice into tiles)")
155
167
  }).strict().superRefine(refineScrapeScreenshotActionsBefore).describe("Screenshot capture configuration");
@@ -168,11 +180,11 @@ const Schema_ApiScrapeLocation = z.object({
168
180
  country: z.string().regex(/^([a-zA-Z]{2}|europe)$/i, "country must be a 2-letter ISO 3166-1 alpha-2 code, 'eu', or 'europe'").optional().describe("ISO 3166-1 alpha-2 (e.g. 'us', 'de', 'br'; case-insensitive) driving the emulated browser timezone and proxy exit country. Also accepts 'eu' (random EU member state) or 'europe' (random European state incl. UK and non-EU).")
169
181
  }).strict().describe("Optional locale + country emulation for the scrape");
170
182
  const Schema_ApiScrapeRequest = z.object({
171
- url: z.string().describe("The URL to scrape. Known tracking parameters (utm_*, mtm_*, ga_*, pk_*, gclid, fbclid, msclkid, and others) are removed before the page is fetched, so they are neither sent to the target site nor part of the cache key. Every other query parameter is kept verbatim and is part of the cache key."),
183
+ url: z.string().describe("The URL to scrape. Known tracking parameters are removed before the page is fetched, so they are neither sent to the target site nor part of the cache key. Every other query parameter is kept verbatim and is part of the cache key."),
172
184
  extract: Schema_ApiScrapeExtract.prefault({}).describe("Which content formats to extract. Defaults to metadata + cleaned_html."),
173
185
  cache: Schema_ApiScrapeCache.optional().describe("Cache settings for this request"),
174
186
  require_js: z.boolean().default(false).describe("Use a headless browser to render JavaScript before scraping"),
175
- exclude_selectors: z.array(z.string()).optional().describe("CSS selectors to exclude from the extracted content"),
187
+ cleanup: Schema_ApiScrapeCleanup.prefault({ ...DEFAULT_SCRAPE_CLEANUP }),
176
188
  proxy: Schema_ApiProxyType.describe("Proxy tier to use for fetching"),
177
189
  location: Schema_ApiScrapeLocation.optional()
178
190
  }).strict();
@@ -181,28 +193,106 @@ const Schema_ApiScrapeRequest = z.object({
181
193
  //#region src/schemas/ApiMapRequest.ts
182
194
  const Schema_ApiMapLocation = z.object({ country: z.string().regex(/^([a-zA-Z]{2}|europe)$/i, "country must be a 2-letter ISO 3166-1 alpha-2 code, 'eu', or 'europe'").optional().describe("ISO 3166-1 alpha-2 (e.g. 'us', 'de', 'br'; case-insensitive) hint for proxy egress country. Also accepts 'eu' (random EU member state) or 'europe' (random European state incl. UK and non-EU).") }).strict().describe("Optional country emulation for the map");
183
195
  const DEFAULT_API_MAP_CACHE_MAX_AGE_SECONDS = 10080 * 60;
184
- const DEFAULT_API_MAP_MAX_URLS = 1e5;
196
+ /**
197
+ * How many URLs a /map call discovers and stores when the caller names no
198
+ * limit. Sitemap discovery stops here, so the default is real crawl work, not
199
+ * a slice taken at the end — 5000 covers the whole site for the great majority
200
+ * of roots while keeping an unparameterised call cheap and fast.
201
+ */
202
+ const DEFAULT_API_MAP_MAX_URLS = 5e3;
185
203
  const MAX_API_MAP_MAX_URLS = 1e5;
186
- const DEFAULT_API_MAP_PAGE_LIMIT = 1e4;
204
+ const DEFAULT_API_MAP_PAGE_LIMIT = 5e3;
187
205
  const MAX_API_MAP_PAGE_LIMIT = 1e4;
188
206
  const Schema_ApiMapTypes = z.object({
189
- internal: z.boolean().default(true).describe("Include internal links (same domain)"),
190
- internal_subdomains: z.boolean().default(true).describe("Include links to subdomains of the target domain"),
207
+ internal: z.boolean().default(true).describe("Include internal links (same domain; www and the bare domain are equivalent)"),
208
+ internal_subdomains: z.boolean().default(true).describe("Include links to subdomains of the target domain (other than www)"),
191
209
  external: z.boolean().default(true).describe("Include external links (different domains)")
192
210
  }).describe("Filter which link types to include in the map");
193
211
  const Schema_ApiMapCache = z.object({ max_age: z.union([z.number().int().nonnegative(), z.iso.datetime()]).default(DEFAULT_API_MAP_CACHE_MAX_AGE_SECONDS).describe("Maximum cache age in seconds, or an ISO 8601 datetime cutoff") }).describe("Cache settings for the map request");
194
212
  const Schema_ApiMapRequest = z.object({
195
- url: z.string().describe("The website URL to map. Mapping always targets the site root, so the path, query string and fragment are dropped; known tracking parameters (utm_*, mtm_*, ga_*, pk_*, gclid, fbclid, msclkid, and others) are removed before the request is processed."),
213
+ url: z.string().describe("The website URL to map. Mapping always targets the site root, so the path, query string and fragment are dropped; known tracking parameters are removed before the request is processed."),
196
214
  proxy: Schema_ApiProxyType.default("auto").describe("Proxy tier to use for fetching"),
197
215
  sitemap_only: z.boolean().default(false).describe("Only use sitemap.xml — skip homepage link extraction"),
198
216
  types: Schema_ApiMapTypes.optional().describe("Filter which link types to include"),
199
217
  cache: Schema_ApiMapCache.optional().describe("Cache settings for this request"),
200
- max_urls: z.number().int().positive().max(MAX_API_MAP_MAX_URLS).default(DEFAULT_API_MAP_MAX_URLS).describe("Maximum number of URLs to store in the map"),
218
+ 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."),
201
219
  page: z.number().int().positive().default(1).describe("Page number for paginated results"),
202
- 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"),
220
+ 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."),
203
221
  location: Schema_ApiMapLocation.optional()
204
222
  });
205
223
 
224
+ //#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
+ ];
235
+ /** Map usage has no screenshot-slice add-on. */
236
+ const Schema_ApiMapUsageMeta = z.object({
237
+ credits: z.number().int().nonnegative().describe("Credits charged for this map request"),
238
+ engine: z.enum(["text", "cache"]).describe("The map billing engine: `text` for fresh discovery or `cache` for a cached result"),
239
+ proxy: z.enum(API_RESOLVED_PROXY_TIER_VALUES$1).describe("The proxy tier the request actually ran on (resolved value — never `auto`)")
240
+ });
241
+ const Schema_ApiMapLinkItem = z.object({ url: z.string().describe("The discovered URL") });
242
+ const Schema_ApiMapPagination = z.object({
243
+ page: z.number().int().positive().describe("Current page number"),
244
+ limit: z.number().int().positive().describe("Number of items per page"),
245
+ total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
246
+ total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
247
+ has_more: z.boolean().describe("Whether more pages are available")
248
+ });
249
+ const Schema_ApiMapTruncation = z.object({
250
+ storage_capped: z.boolean().describe("Whether the stored map hit the 100000-URL storage cap."),
251
+ 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."),
252
+ total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
253
+ total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied"),
254
+ 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."),
255
+ 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."),
256
+ 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. Only \"max_urls\" is something you can change from the request.")
257
+ });
258
+ const Schema_ApiMapResult = z.object({
259
+ links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
260
+ response_meta: z.object({
261
+ pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
262
+ truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
263
+ usage: Schema_ApiMapUsageMeta.describe("Usage accounting for this map request: credits charged, the billed engine, and the resolved proxy tier.")
264
+ }).describe("Response metadata including pagination, truncation, and usage info")
265
+ });
266
+
267
+ //#endregion
268
+ //#region src/tools/map.ts
269
+ const DESCRIPTION$6 = [
270
+ "Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
271
+ "link extraction. Returns paginated lists of discovered URLs, each item just { url }.",
272
+ "Filterable by link type (internal / external / subdomain). Use this to enumerate a site before",
273
+ "scraping selected pages.",
274
+ "`max_urls` (default 5000, max 100000) is a discovery budget, not a trim at the end: discovery",
275
+ "stops as soon as that many URLs are found, so a smaller value is a faster, cheaper crawl.",
276
+ "A map stopped that way returns exactly `max_urls` links with `response_capped` false — the",
277
+ "signal that the site has more is `response_meta.truncation.discovery_cap_reason`. When that is",
278
+ "\"max_urls\", ask again with a higher `max_urls` to get more; \"time\", \"file_budget\", \"depth\" and",
279
+ "\"file_size\" mean the site itself is big, slow or deep and a retry will not help. `discovery_capped`",
280
+ "says discovery stopped early, `sitemaps_skipped` how many sitemap files were skipped or only",
281
+ "partly read. `limit` (default 5000, max 10000) only pages the answer.",
282
+ "Returned URLs are normalized the same way `scrape` normalizes its returned `url`, so",
283
+ "map-then-scrape stays on one host. Results are ordered with the most useful links first.",
284
+ "The response carries `response_meta.usage` = { credits, engine, proxy } — the resolved proxy",
285
+ "tier is never `auto`; map responses do not include screenshot-slice accounting."
286
+ ].join(" ");
287
+ function registerMapTool(server, getClient) {
288
+ server.registerTool("map", {
289
+ title: "Map a website",
290
+ description: DESCRIPTION$6,
291
+ inputSchema: Schema_ApiMapRequest.shape,
292
+ outputSchema: Schema_ApiMapResult.shape
293
+ }, (args) => runTool(async () => await getClient().map(args)));
294
+ }
295
+
206
296
  //#endregion
207
297
  //#region src/schemas/ApiScrapeResponse.ts
208
298
  const Schema_ApiViewport = z.object({
@@ -240,11 +330,17 @@ const Schema_ApiPageLink = z.object({
240
330
  });
241
331
  const API_RESOLVED_PROXY_TIER_VALUES = ["basic", "advanced"];
242
332
  const Schema_ApiUsageMeta = z.object({
243
- credits: z.number().int().nonnegative().describe("Credits charged for this request. `0` on a fully cached result; only parts still computed fresh (e.g. a newly produced screenshot-slice variant) are charged."),
333
+ 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."),
334
+ engine: z.enum([
335
+ "text",
336
+ "browser",
337
+ "screenshot",
338
+ "cache"
339
+ ]).describe("The engine base the request was billed at — \"text\" (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."),
244
340
  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`)."),
245
- cache_hit: z.boolean().describe("Whether the result was served from cache (`true`) or freshly fetched (`false`).")
341
+ 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.")
246
342
  });
247
- const Schema_ApiResponseMeta = z.object({ usage: Schema_ApiUsageMeta.describe("Usage accounting for this request: credits charged, resolved proxy tier, and cache-hit flag.") });
343
+ 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.") });
248
344
  const Schema_ApiScrapeMeta = z.object({
249
345
  title: z.string().optional().describe("Page title from the <title> tag"),
250
346
  description: z.string().optional().describe("Meta description"),
@@ -270,7 +366,7 @@ const Schema_ApiScrapeMeta = z.object({
270
366
  favicon_url: z.string().nullish().describe("Resolved favicon URL for the page (best-effort, from <head> icon hints + manifest)")
271
367
  });
272
368
  const Schema_ApiScrapeSuccessResponse = z.object({
273
- url: z.string().describe("The URL that was actually scraped, after any redirects, in cleaned canonical form (tracking params and fragment removed) — the base that links, images, and internal labels are computed against"),
369
+ 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"),
274
370
  requested_url: z.string().describe("The URL you requested, echoed verbatim — before any redirects"),
275
371
  content_type: z.string().optional().describe("Content-Type header returned by the server"),
276
372
  unsupported_fields: z.array(z.string()).optional().describe("Extract fields that were requested but are not supported for this content type"),
@@ -282,49 +378,8 @@ const Schema_ApiScrapeSuccessResponse = z.object({
282
378
  screenshot: Schema_ApiScreenshotResponse.optional().describe("Screenshot of the page, if requested"),
283
379
  metadata: Schema_ApiScrapeMeta.optional().describe("Extracted page metadata (title, OG tags, etc.)"),
284
380
  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."),
285
- response_meta: Schema_ApiResponseMeta.describe("Request-level metadata. `response_meta.usage` reports credits charged (0 on a fully cached result; only parts still computed fresh are charged), the resolved proxy tier, and the cache-hit flag.")
286
- });
287
-
288
- //#endregion
289
- //#region src/schemas/ApiMapResponse.ts
290
- const Schema_ApiMapLinkItem = z.object({ url: z.string().describe("The discovered URL") });
291
- const Schema_ApiMapPagination = z.object({
292
- page: z.number().int().positive().describe("Current page number"),
293
- limit: z.number().int().positive().describe("Number of items per page"),
294
- total: z.number().int().nonnegative().describe("Total number of URLs in the map"),
295
- total_pages: z.number().int().nonnegative().describe("Total number of pages available"),
296
- has_more: z.boolean().describe("Whether more pages are available")
381
+ 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.")
297
382
  });
298
- const Schema_ApiMapTruncation = z.object({
299
- storage_capped: z.boolean().describe("Whether the stored map was capped by the max_urls limit"),
300
- response_capped: z.boolean().describe("Whether the response was capped by pagination"),
301
- total_before_max_urls: z.number().int().nonnegative().describe("Total URLs found before applying the max_urls cap"),
302
- total_detected_before_storage_cap: z.number().int().nonnegative().describe("Total URLs detected during discovery before the storage cap was applied")
303
- });
304
- const Schema_ApiMapResult = z.object({
305
- links: z.array(Schema_ApiMapLinkItem).describe("List of discovered URLs for the current page"),
306
- response_meta: z.object({
307
- pagination: Schema_ApiMapPagination.describe("Pagination details for the result set"),
308
- truncation: Schema_ApiMapTruncation.describe("Information about whether the results were truncated"),
309
- usage: Schema_ApiUsageMeta.describe("Usage accounting for this map request: credits charged (0 on a fully cached result; only parts still computed fresh are charged), the resolved proxy tier, and the cache-hit flag.")
310
- }).describe("Response metadata including pagination, truncation, and usage info")
311
- });
312
-
313
- //#endregion
314
- //#region src/tools/map.ts
315
- const DESCRIPTION$6 = [
316
- "Build (or fetch a cached) link-map for a website by combining sitemap discovery with homepage",
317
- "link extraction. Returns paginated lists of discovered URLs. Filterable by link type",
318
- "(internal / external / subdomain). Use this to enumerate a site before scraping selected pages."
319
- ].join(" ");
320
- function registerMapTool(server, getClient) {
321
- server.registerTool("map", {
322
- title: "Map a website",
323
- description: DESCRIPTION$6,
324
- inputSchema: Schema_ApiMapRequest.shape,
325
- outputSchema: Schema_ApiMapResult.shape
326
- }, (args) => runTool(async () => await getClient().map(args)));
327
- }
328
383
 
329
384
  //#endregion
330
385
  //#region src/tools/scrape.ts
@@ -333,13 +388,18 @@ const DESCRIPTION$5 = [
333
388
  "(markdown, cleaned HTML, raw HTML, links, images, screenshot, page metadata in `metadata`).",
334
389
  "Use this for one-shot page extraction. For full-site discovery use the `map` tool first.",
335
390
  "Screenshot URLs in the response are signed download links — the agent can fetch them when needed.",
336
- "The response also carries `response_meta.usage` = { credits (0 on a fully cached result; only",
337
- "parts still computed fresh are charged), proxy (the resolved tier — never `auto`), cache_hit }",
391
+ "The response also carries `response_meta.usage` = { credits, engine, proxy (the resolved tier —",
392
+ "never `auto`), screenshot_slices }. `engine` is the billed engine (`text`, `browser`, `screenshot`,",
393
+ "`cache`); a cache hit is represented by `engine: \"cache\"`.",
338
394
  "so you can see what the request cost.",
339
- "Extraction is capped per page: 30,000 links, 10,000 inline images, 10,000,000 characters of body",
340
- "HTML and 2,000,000 characters of head HTML. A page past a cap is truncated rather than refused,",
341
- "and the response `warnings` array names which one (`links_truncated`, `inline_images_truncated`,",
342
- "`raw_html_truncated`, `metadata_truncated`) — so treat that output as incomplete.",
395
+ "Extraction is capped per page: 30,000 links, 10,000 inline images and 10,000,000 characters of",
396
+ "HTML. A page past a cap is truncated rather than refused, and the response `warnings` array names",
397
+ "which one (`links_truncated`, `inline_images_truncated`, `raw_html_truncated`) — so treat that",
398
+ "output as incomplete.",
399
+ "Use `cleanup` to control what is removed before any output is built: `ads_and_popups` (on by",
400
+ "default) drops ads, cookie banners and chat widgets, and `exclude_selectors` removes anything",
401
+ "else. It shapes markdown, cleaned_html, links, images and the screenshot, and NEVER `raw_html` —",
402
+ "so request `raw_html` when you need the page exactly as it arrived.",
343
403
  "`warnings` also reports a section whose extraction failed outright (`links_unavailable`,",
344
404
  "`inline_images_unavailable`, `metadata_unavailable`): that field comes back omitted or empty",
345
405
  "while the rest of the scrape succeeded, so do NOT conclude the page had no links/images/metadata",
@@ -377,7 +437,7 @@ const Schema_ApiScrapeStatusResponse = z.object({
377
437
  status: z.enum(ASYNC_JOB_STATUS_VALUES).describe("Current state of the job (pending, running, done, failed)"),
378
438
  created_at: z.string().describe("ISO-8601 UTC timestamp when the job was created"),
379
439
  error: z.string().optional().describe("Error message if the job ended in `failed`"),
380
- 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 (0 on a fully cached result; only parts still computed fresh are charged), the resolved proxy tier, and the cache-hit flag.")
440
+ 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.")
381
441
  });
382
442
 
383
443
  //#endregion
@@ -425,7 +485,8 @@ function registerScrapeResultTool(server, getClient) {
425
485
  const DESCRIPTION$2 = [
426
486
  "Look up the current lifecycle status of an async scrape job submitted via `scrape_async`.",
427
487
  "Returns the job state (`pending`, `running`, `done`, `failed`), with an `error` message",
428
- "when it failed and a `response_meta.usage` block (credits, resolved proxy tier, cache_hit) once it is",
488
+ "when it failed and a `response_meta.usage` block (credits, billed engine, resolved proxy tier,",
489
+ "screenshot_slices) once it is",
429
490
  "`done`. Poll this until the status is `done`, then call `scrape_result` to fetch",
430
491
  "the page. If you registered a completion webhook on submit you can skip polling and react",
431
492
  "to the delivery instead."
@@ -493,7 +554,7 @@ function registerWhoamiTool(server, getClient) {
493
554
  //#endregion
494
555
  //#region src/version.ts
495
556
  const SERVER_NAME = "crawlbrulee";
496
- const SERVER_VERSION = "0.8.1";
557
+ const SERVER_VERSION = "0.12.0";
497
558
 
498
559
  //#endregion
499
560
  //#region src/server.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlbrulee/mcp",
3
- "version": "0.8.1",
3
+ "version": "0.12.0",
4
4
  "description": "Official MCP server for the crawlbrulee API — scrape and map URLs from MCP-aware agents (Claude Code, Codex, Cursor).",
5
5
  "keywords": [
6
6
  "crawlbrulee",
@@ -55,7 +55,7 @@
55
55
  "prepublishOnly": "pnpm verify"
56
56
  },
57
57
  "dependencies": {
58
- "@crawlbrulee/sdk": "^0.11.1",
58
+ "@crawlbrulee/sdk": "^0.15.0",
59
59
  "@modelcontextprotocol/sdk": "^1.29.0",
60
60
  "zod": "^4.0.0"
61
61
  },