{"slug": "zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii", "title": "Zero-Scraping RAG Preprocessing: HTML-to-Markdown, Typed Tables, Chunking & Luhn PII Redaction via Edge MCP", "summary": "A developer built doc-to-llm-markdown-mcp, a zero-dependency, stateless JavaScript MCP server that performs RAG pre-ingestion chores—HTML-to-Markdown conversion with boilerplate stripping, typed table-to-JSON parsing, heading-aware semantic chunking, and Luhn-based PII redaction—on caller-supplied text only. The engine runs on a free Cloudflare Worker with roughly 1ms cold starts and is also published as a Standby/Batch MCP Actor on the Apify Store, exposing REST routes and JSON-RPC 2.0 endpoints for use in Claude and Cursor.", "body_md": "Most RAG pipelines waste time and tokens on the exact same pre-ingestion chores: stripping `<nav>` and `<script>` boilerplate out of HTML, turning messy CSV/Markdown/HTML tables into typed JSON, slicing documents into token-budgeted chunks without losing heading context, and scrubbing emails or payment card numbers before text ever hits an LLM prompt or vector database.\n\nToo often, teams solve those four problems by spinning up a headless browser container, shipping 40 MB of transitive dependencies, or asking an LLM to clean its own input (burning both latency and tokens nondeterministically).\n\nWe built **`doc-to-llm-markdown-mcp`** as a **zero-scraping, zero-dependency, stateless Web-Standards JS engine** that runs identically on a free Cloudflare Worker (~1ms cold start, zero auth, zero caller data stored) and on Apify Store as a Standby/Batch MCP Actor (`quantforge_data/doc-to-llm-markdown-mcp`).\n\n`2025-03-26`)` https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/mcp`\n\n```\nclaude mcp add --transport http doc-to-llm https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/mcp\n```\n\n`.cursor/mcp.json`)\n\n```\n{\n  \"mcpServers\": {\n    \"quantforge-doc-to-llm\": {\n      \"url\": \"https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/mcp\"\n    }\n  }\n}\n```\n\nOr test directly with `curl` via either the REST routes (`/v1/*`) or JSON-RPC 2.0 (`/mcp`).\n\nEvery single function in `doc-to-llm-markdown-mcp` operates **exclusively on caller-supplied text**:\n\n`fetch()` calls`TextEncoder`, `URL`, `crypto.subtle.digest('SHA-256', ...)`).` 10ms` CPU budget on Cloudflare Workers Free Tier).`pii_stored: false`)` html_to_llm_markdown` (`POST /v1/html-to-markdown`)\nRemoves `<head>`, `<script>`, `<style>`, `<noscript>`, `<svg>`, `<iframe>`, `<template>`—plus `<nav>`, `<header>`, `<footer>`, `<aside>` when `strip_nav: true`—while preserving `<pre>` code blocks using sentinel placeholders so whitespace normalization never corrupts code indentation. HTML `<table>` elements are extracted both inline as Markdown pipe tables and separately as structured JSON objects.\n\n```\ncurl -sS -X POST \"https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/v1/html-to-markdown\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"html\": \"<nav>Skip Me</nav><article><h1>Q4 Engineering Update</h1><p>Deterministic <strong>RAG</strong> preprocessing.</p><table><tr><th>Metric</th><th>Value</th></tr><tr><td>Cold Start</td><td>1ms</td></tr></table></article>\",\n    \"strip_nav\": true,\n    \"include_links\": true\n  }'\n```\n\nKey fields returned under `data`:\n\n`title`, `markdown`, `headings` (`[{ level, text }]`), `tables`, `links` (deduplicated)`stats`: `input_bytes`, `output_bytes`, `compression_ratio`, `estimated_tokens`, `headings_count`, `tables_count`, `links_count`, `content_sha256`\n`table_to_structured_json` (`POST /v1/table-to-json`)\nAuto-detects `csv`, `tsv`, `markdown`, or `html` (`format: \"auto\"`), parses quoted RFC 4180 CSV fields cleanly, deduplicates duplicate column headers (`price`, `price_2`), infers scalar types (` integer`, `number`, `boolean`, `null`, `string`), and emits per-column completeness statistics (` null_count`, `completeness_ratio`).\n\n```\ncurl -sS -X POST \"https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/v1/table-to-json\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"content\": \"| service | price_per_1k | pii_excluded |\\n| --- | --- | --- |\\n| doc-to-llm | 2.00 | true |\\n| rss-digest | 1.00 | true |\",\n    \"format\": \"auto\",\n    \"infer_types\": true\n  }'\n```\n\n`rag_semantic_chunker` (`POST /v1/rag-chunk`)\nNaive fixed-character splitting destroys Markdown section hierarchy and leaves vector chunks orphaned from the heading they belong to. `rag_semantic_chunker` maintains a live heading stack (`#`..`######`), splits at heading boundaries when `preserve_headings: true`, attaches `heading_path` breadcrumbs to every chunk, carries configurable `overlap_tokens` across paragraph boundaries, hard-splits oversized paragraphs on word boundaries, and computes a deterministic WebCrypto `sha256` per chunk for vector-DB deduplication.\n\n```\ncurl -sS -X POST \"https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/v1/rag-chunk\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"text\": \"# Ingestion Guide\\n\\n## Deduplication\\n\\nStore each chunk SHA-256 hash so re-indexing skips unchanged sections.\\n\\n## Redaction\\n\\nRun PII redaction before generating embeddings.\",\n    \"max_tokens\": 64,\n    \"overlap_tokens\": 8,\n    \"preserve_headings\": true\n  }'\n```\n\n`pii_redactor_audit` (`POST /v1/redact-pii`)\nBefore text reaches a third-party embedding API or LLM context window, `pii_redactor_audit` deterministically redacts 5 categories (`email`, `phone`, `ssn`, `credit_card`, `ipv4`) using either `[REDACTED_EMAIL]` (`placeholder_style: \"bracket\"`) or `***` (`placeholder_style: \"mask\"`).\n\nOne subtle detail that cuts false positives dramatically: **credit card candidates (`13–19` digits with optional spaces/hyphens) are verified with the Luhn checksum algorithm** before redacting. That way a random 16-digit internal order ID or tracking number isn't mangled, while actual payment card numbers are caught.\n\nEqually important: the audit output returns **only** `redacted_text`, `pii_detected`, `total_redactions`, `counts_by_category`, and `redacted_sha256`—it **never echoes the raw matched PII values back into logs**.\n\n```\ncurl -sS -X POST \"https://doc-to-llm-markdown-mcp.ryu-7f5.workers.dev/v1/redact-pii\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"text\": \"Contact ops@example.com or 415-555-0199 from 198.51.100.42 (test card 4111-1111-1111-1111, order 9999-8888-7777-6661).\",\n    \"placeholder_style\": \"bracket\"\n  }'\n```\n\nResponse shape:\n\n```\n{\n  \"ok\": true,\n  \"data\": {\n    \"redacted_text\": \"Contact [REDACTED_EMAIL] or [REDACTED_PHONE] from [REDACTED_IPV4] (test card [REDACTED_CREDIT_CARD], order 9999-8888-7777-6661).\",\n    \"pii_detected\": true,\n    \"total_redactions\": 4,\n    \"counts_by_category\": {\n      \"email\": 1,\n      \"phone\": 1,\n      \"ssn\": 0,\n      \"credit_card\": 1,\n      \"ipv4\": 1\n    },\n    \"redacted_sha256\": \"...\"\n  }\n}\n```\n\nThe exact same zero-dependency engine runs in two places:\n\n`quantforge_data/doc-to-llm-markdown-mcp`)` 256 MB`, `LIMITED_PERMISSIONS` Standby MCP & Batch Actor (`$0.002 / call`, i.e., `$2.00 / 1,000 calls` with BRONZE/SILVER/GOLD volume discounts) when you need Apify Dataset persistence, scheduled jobs, n8n/Make connectors, or audit logs.\nIf you test `doc-to-llm-markdown-mcp` against gnarly HTML tables or Markdown edge cases in your RAG pipeline, drop an example in the comments—we'd love to harden the parser against real-world inputs.", "url": "https://wpnews.pro/news/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii", "canonical_source": "https://dev.to/quantforgedata/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii-redaction-via-41p4", "published_at": "2026-12-06 18:09:38+00:00", "updated_at": "2026-12-06 18:14:32.952981+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "developer-tools", "ai-tools"], "entities": ["doc-to-llm-markdown-mcp", "Cloudflare Workers", "Apify", "Claude", "Cursor", "quantforge_data"], "also_reported_by": [], "takeaway": "doc-to-llm-markdown-mcp exposes HTML-to-Markdown, table-to-JSON, heading-aware chunking and Luhn PII redaction as stateless MCP/REST endpoints on a Cloudflare Worker with ~1ms cold starts and no stored caller data.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii", "markdown": "https://wpnews.pro/news/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii.md", "text": "https://wpnews.pro/news/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii.txt", "jsonld": "https://wpnews.pro/news/zero-scraping-rag-preprocessing-html-to-markdown-typed-tables-chunking-luhn-pii.jsonld"}}