scrapeunblocker-mcp 0.2.2 → 0.2.3

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 (2) hide show
  1. package/dist/index.js +16 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
6
  import { z } from "zod";
7
7
  import { APIError, ScrapeUnblockerClient } from "scrapeunblocker";
8
- var VERSION = "0.2.2";
8
+ var VERSION = "0.2.3";
9
9
  var DEFAULT_BASE_URL = "https://api.scrapeunblocker.com";
10
10
  var API_KEY_HEADER = "x-scrapeunblocker-key";
11
11
  function resolveApiKey() {
@@ -45,16 +45,17 @@ ${page}` : `${head}
45
45
 
46
46
  The target sent no page body.`;
47
47
  }
48
- function isNoDataExtracted(status, body) {
49
- if (status !== 422 || !body) return false;
50
- try {
51
- return JSON.parse(body)?.error === "no_data_extracted";
52
- } catch {
53
- return false;
54
- }
48
+ function noDataExtractedHtml(raw) {
49
+ if (!raw || raw.data_extracted !== false) return null;
50
+ return typeof raw.html === "string" ? raw.html : "";
55
51
  }
56
- function noDataExtractedText(url) {
57
- return `No structured data could be extracted from ${url}: the page loaded, but nothing on it matched a structured shape. This call was not billed. To get the page itself, call fetch_html for the same URL.`;
52
+ function noDataExtractedText(url, html) {
53
+ const head = `No structured data could be extracted from ${url}: the page loaded, but nothing on it matched a structured shape. The call was billed like fetch_html, so the rendered page is returned instead.`;
54
+ return html.trim() ? `${head}
55
+
56
+ The rendered HTML follows:
57
+
58
+ ${html}` : head;
58
59
  }
59
60
  function errorResult(url, err) {
60
61
  if (err instanceof APIError) {
@@ -62,9 +63,6 @@ function errorResult(url, err) {
62
63
  if (gone !== null) {
63
64
  return { content: [{ type: "text", text: targetGoneText(url, gone, err.body ?? "") }] };
64
65
  }
65
- if (isNoDataExtracted(err.statusCode, err.body)) {
66
- return { content: [{ type: "text", text: noDataExtractedText(url) }] };
67
- }
68
66
  }
69
67
  return { content: [{ type: "text", text: errorText(err) }], isError: true };
70
68
  }
@@ -292,7 +290,7 @@ server.registerTool(
292
290
  "fetch_parsed",
293
291
  {
294
292
  title: "Fetch AI-parsed page data",
295
- description: "Fetch a web page through ScrapeUnblocker and return AI-parsed structured JSON instead of raw HTML (e.g. product details, article content). Best for extracting fields from product, listing or article pages without writing your own HTML parsing. If the page holds no structured data, the result says so (that call is not billed) - use fetch_html for the page itself.",
293
+ description: "Fetch a web page through ScrapeUnblocker and return AI-parsed structured JSON instead of raw HTML (e.g. product details, article content). Best for extracting fields from product, listing or article pages without writing your own HTML parsing. If the page holds no structured data, the result says so and returns the rendered HTML instead (billed like fetch_html).",
296
294
  inputSchema: {
297
295
  url: z.string().url().describe("The absolute URL to fetch and parse."),
298
296
  proxy_country: z.string().length(2).optional().describe("Optional ISO country code to route through, e.g. 'US'."),
@@ -307,6 +305,10 @@ server.registerTool(
307
305
  proxyCountry: args.proxy_country,
308
306
  rulesHint: args.rules_hint
309
307
  });
308
+ const noDataHtml = noDataExtractedHtml(parsed.raw);
309
+ if (noDataHtml !== null) {
310
+ return { content: [{ type: "text", text: noDataExtractedText(args.url, noDataHtml) }] };
311
+ }
310
312
  return {
311
313
  content: [{ type: "text", text: JSON.stringify(parsed, null, 2) }]
312
314
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scrapeunblocker-mcp",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "mcpName": "com.scrapeunblocker/scrapeunblocker-mcp",
5
5
  "description": "Model Context Protocol (MCP) server for ScrapeUnblocker - lets Claude fetch any web page's HTML (or AI-parsed JSON) through the ScrapeUnblocker anti-bot API, using your own API key.",
6
6
  "keywords": [