crawlforge-mcp-server 5.6.4 → 5.6.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crawlforge-mcp-server",
3
- "version": "5.6.4",
3
+ "version": "5.6.5",
4
4
  "mcpName": "io.github.mysleekdesigns/crawlforge-mcp-server",
5
5
  "description": "CrawlForge MCP Server - Professional Model Context Protocol server with 29 web scraping, crawling, deep-research, and autonomous-extraction tools. Returns clean Markdown and structured JSON for Claude, Cursor, and any MCP client. Defaults to local Ollama for LLM extraction (no API key needed); OpenAI/Anthropic available as opt-in. Includes a unified multi-format scrape tool, an autonomous agent, pre-built site templates, and Camoufox stealth browsing.",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -106,7 +106,7 @@ const taskStore = createTaskStore({ logger });
106
106
  // Create the server
107
107
  const server = new McpServer({
108
108
  name: "crawlforge",
109
- version: "5.6.4",
109
+ version: "5.6.5",
110
110
  description: "Production-ready MCP server with 29 web scraping, crawling, and content processing tools. Features MCP Resources (crawlforge://), Prompts, Sampling fallback, Elicitation, stealth browsing, deep research, structured extraction, embedded JavaScript state extraction, real Google SERP rank tracking, Reddit search via community archives, change tracking, local-LLM extraction via Ollama, unified multi-format scrape, and autonomous agent tool.",
111
111
  homepage: "https://www.crawlforge.dev",
112
112
  icon: "https://www.crawlforge.dev/icon.png",
@@ -10,6 +10,7 @@ import { load } from 'cheerio';
10
10
 
11
11
  // Import existing tool for content extraction
12
12
  import ExtractContentTool from '../extract/extractContent.js';
13
+ import { elementText } from '../../utils/elementText.js';
13
14
 
14
15
  // Recording / replay helpers
15
16
  import {
@@ -798,12 +799,15 @@ export class ScrapeWithActionsTool extends EventEmitter {
798
799
  try {
799
800
  const elements = $(selector);
800
801
 
802
+ // elementText keeps table structure (one line per row, cells joined
803
+ // by " | "); cheerio's .text() ran CoinMarketCap's history table into
804
+ // "DateOpen*HighLowClose**…" (2026-09-04).
801
805
  if (elements.length === 0) {
802
806
  extracted[key] = null;
803
807
  } else if (elements.length === 1) {
804
- extracted[key] = elements.text().trim();
808
+ extracted[key] = elementText($, elements.get(0));
805
809
  } else {
806
- extracted[key] = elements.map((_, el) => $(el).text().trim()).get();
810
+ extracted[key] = elements.map((_, el) => elementText($, el)).get();
807
811
  }
808
812
  } catch (error) {
809
813
  extracted[key] = { error: `Invalid selector: ${selector}` };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * elementText — the text of a cheerio-matched element with table structure kept.
3
+ *
4
+ * cheerio's .text() runs every descendant's text together. For a table that
5
+ * is one string per row with no cell boundaries: scrape_with_actions'
6
+ * extractionOptions.selectors returned CoinMarketCap's historical-data table
7
+ * as "DateOpen*HighLowClose**VolumeMarket CapSep 03, 2026$77,300.17…"
8
+ * (2026-09-04). Here a table, a row group or a row renders one line per row
9
+ * with cells joined by " | " (the convention _mainContent.js uses for the text
10
+ * of a recovered table), an element that wraps a table renders each table that
11
+ * way in place, and anything else is .text().trim(), unchanged.
12
+ *
13
+ * batchScrape/worker.js extractStructuredData and scrapeStructured read
14
+ * matched elements with the same .text().trim() and have the same gap; they
15
+ * do not use this yet.
16
+ */
17
+
18
+ const ROW_GROUPS = new Set(['table', 'thead', 'tbody', 'tfoot']);
19
+
20
+ function tagOf(el) {
21
+ return String(el?.name || el?.tagName || '').toLowerCase();
22
+ }
23
+
24
+ function cellText($, cell) {
25
+ return $(cell).text().replace(/\s+/g, ' ').trim();
26
+ }
27
+
28
+ function rowText($, row) {
29
+ return $(row).children('td, th').map((_, cell) => cellText($, cell)).get().join(' | ');
30
+ }
31
+
32
+ /**
33
+ * One line per row, cells joined by " | ". `el` is a table or one of its row
34
+ * groups; rows of a table nested inside a cell belong to that table, not to
35
+ * this one, so they are skipped here (their cell already carries their text).
36
+ */
37
+ function tableText($, el) {
38
+ const table = tagOf(el) === 'table' ? el : $(el).closest('table').get(0);
39
+ return $(el).find('tr')
40
+ .filter((_, row) => $(row).closest('table').get(0) === table)
41
+ .map((_, row) => rowText($, row)).get()
42
+ .filter((line) => line.length > 0)
43
+ .join('\n');
44
+ }
45
+
46
+ /**
47
+ * @param {import('cheerio').CheerioAPI} $
48
+ * @param {object} el - a cheerio/domhandler element
49
+ * @returns {string}
50
+ */
51
+ export function elementText($, el) {
52
+ const tag = tagOf(el);
53
+ if (tag === 'tr') return rowText($, el);
54
+ if (ROW_GROUPS.has(tag)) return tableText($, el);
55
+
56
+ const $el = $(el);
57
+ if ($el.find('table').length === 0) return $el.text().trim();
58
+
59
+ // A wrapper around one or more tables: swap each outermost table for its
60
+ // line-per-row text (as a text node, so cell content is never re-parsed as
61
+ // markup), then read the wrapper as lines.
62
+ const $clone = $el.clone();
63
+ $clone.find('table')
64
+ .filter((_, table) => $(table).parents('table').length === 0)
65
+ .each((_, table) => {
66
+ $(table).replaceWith($('<div></div>').text(`\n${tableText($, table)}\n`));
67
+ });
68
+ return $clone.text().split('\n').map((line) => line.trim()).filter(Boolean).join('\n');
69
+ }
70
+
71
+ export default elementText;