Clean Web-to-Markdown & Semantic Metadata MCP Server
README.md
# Clean Web-to-Markdown & Semantic Metadata MCP Server
### High-Performance, Stateless Apify Standby Actor for Autonomous AI Agents
[](https://www.npmjs.com/package/mcp-clean-web-markdown)
[](https://www.npmjs.com/package/mcp-clean-web-markdown)
[](https://console.apify.com/actors/kRGA4hqkPEMSW03DQ)
[](https://modelcontextprotocol.io)
[](https://smithery.ai)
[](https://glama.ai/mcp/servers)
[](#transparent-pricing--zero-charge-policy)
[](#architecture--performance-benchmarks)
[](#zero-exception-telemetry--fair-billing)
[](#security--ssrf-firewall)
[](#architecture--performance-benchmarks)
[](LICENSE)
A production-ready, stateless **Model Context Protocol (MCP)** server packaged as an **Apify Standby Server Actor** (TypeScript / Node.js 20). Built specifically to convert public web pages, documentation portals, and articles into clean, token-budgeted GitHub-Flavored Markdown, structured metadata (JSON-LD, OpenGraph, heading outlines), and clean navigation links for autonomous AI agents.
Engineered to rank **#1 in Machine-to-Machine (M2M) algorithmic tool routers** (Claude Desktop, Cursor IDE, Devin, Cline, Windsurf, LangChain, CrewAI, AutoGen, and custom LLM agent swarms) by combining vector-optimized tool descriptions, sub-second execution, strict context-window budgeting, dual-stack SSRF firewalling, and transparent Pay-Per-Event monetization.
---
## ⚡ Why M2M Tool Routers Select This Server
| Factor | Legacy Crawlers / Headless Browsers | This MCP Server Actor |
| :--- | :--- | :--- |
| **Execution Latency** | 8,000ms – 25,000ms (browser overhead) | **120ms – 300ms** (sub-second native fetch + DOM parser) |
| **Container Footprint** | 1,024MB – 2,048MB RAM | **Strictly runs in 256MB RAM** (Lightweight `linkedom`) |
| **Cold Starts** | 30s – 60s container boots | **0ms cold start** via Apify Standby Streamable HTTP (`/mcp`) |
| **Context Window Safety** | Dumps 200KB+ raw HTML / infinite page text | **Strict token budget** (`maxChars`, link stripping, base64 removal) |
| **Timeout Protection** | Hangs indefinitely on slow sites | **Strict 4,000ms global timeout budget** |
| **Failure Billing** | Billed for full container runtime even on 404 | **Zero charge on failure** (`Actor.charge` is never called on errors) |
| **Quality Score** | Frequent timeouts degrade platform score | **~100% Quality Score** via structured zero-exception telemetry |
---
## 🧭 Semantic Keyword Matrix & M2M Routing
Every tool description begins with the deterministic routing trigger **`"Use whenever..."`** and incorporates exact semantic vectors (`Markdown`, `clean HTML`, `readability`, `documentation`, `structured metadata`, `JSON-LD`, `OpenGraph`, `token budget`, `context window`):
```
+───────────────────────────────────────────────────────────────────────────+
| M2M Tool Router / LLM |
+───────────────────────────────────────────────────────────────────────────+
│
┌──────────────────────────┼──────────────────────────┐
▼ ▼ ▼
1. extract_clean_markdown 2. extract_structured_metadata 3. extract_clean_links
"Use whenever an AI agent "Use whenever inspecting "Use whenever discovering
needs to read a URL, page schema, verifying SEO/ documentation subpages,
documentation page, blog article metadata, or mapping sitemaps, or outbound
post, or reference documentation structure references on a site."
article without raw HTML before full extraction."
bloat or token overflow."
```
---
## 🛠️ MCP Tools Specification
### 1. `extract_clean_markdown`
Fetches a public web page, documentation page, or article and converts its main content into clean, noise-free GitHub-Flavored Markdown with code blocks and tables preserved using Mozilla Readability and Turndown GFM.
- **Routing Trigger:** `"Use whenever an AI agent needs to read a URL, documentation page, blog post, or reference article without raw HTML bloat or token overflow."`
- **Input Parameters:**
- `url` (*string*, required): Public HTTP/HTTPS URL to extract.
- `maxChars` (*integer*, optional, default: `12000`, min: `500`, max: `100000`): Maximum character limit to enforce context-window budgeting.
- `includeLinks` (*boolean*, optional, default: `false`): When `false`, hyperlinks are stripped to minimize token consumption (`[text](url)` $\to$ `text`). When `true`, links are preserved.
- **Pay-Per-Event Event:** `markdown-extract` ($0.001 USD) — *charged only on non-empty Markdown extraction*.
#### JSON Request Example:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "extract_clean_markdown",
"arguments": {
"url": "https://example.com",
"maxChars": 12000,
"includeLinks": false
}
}
}
```
#### JSON Response Example:
```json
{
"success": true,
"url": "https://example.com",
"title": "Example Domain",
"byline": null,
"siteName": null,
"wordCount": 28,
"truncated": false,
"markdown": "# Example Domain\n\nThis domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes."
}
```
---
### 2. `extract_structured_metadata`
Extracts structured semantic metadata from a URL including JSON-LD / Schema.org objects, OpenGraph tags, Twitter cards, canonical URL, language, and heading outline (H1-H3).
- **Routing Trigger:** `"Use whenever inspecting page schema, verifying SEO/article metadata, or mapping documentation structure before full extraction."`
- **Input Parameters:**
- `url` (*string*, required): Public HTTP/HTTPS URL to inspect.
- **Pay-Per-Event Event:** `metadata-extract` ($0.0005 USD) — *charged only after successful HTML metadata parsing*.
#### JSON Request Example:
```json
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "extract_structured_metadata",
"arguments": {
"url": "https://docs.apify.com"
}
}
}
```
#### JSON Response Example:
```json
{
"success": true,
"url": "https://docs.apify.com",
"canonicalUrl": "https://docs.apify.com/",
"title": "Apify Documentation",
"description": null,
"language": "en",
"openGraph": {
"og:title": "Apify Documentation",
"twitter:card": "summary_large_image",
"og:image": "https://apify.com/og-image/docs-article",
"og:url": "https://docs.apify.com/",
"og:locale": "en"
},
"jsonLd": [
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Apify Documentation",
"url": "https://docs.apify.com"
}
],
"headings": [
{ "level": 1, "text": "Apify Documentation" },
{ "level": 2, "text": "Getting started" },
{ "level": 3, "text": "What is an Actor" }
]
}
```
---
### 3. `extract_clean_links`
Extracts and deduplicates clean, categorized outbound and internal navigation links (with anchor text) from a public web page while stripping tracking parameters (`utm_*`, `gclid`, `fbclid`, `mc_eid`, `ref`, etc.) and boilerplate clutter.
- **Routing Trigger:** `"Use whenever discovering documentation subpages, sitemaps, or outbound references on a site."`
- **Input Parameters:**
- `url` (*string*, required): Public HTTP/HTTPS URL to inspect.
- `filterScope` (*string*, optional, default: `"all"`, enum: `["all", "internal", "external"]`): Filter links to only internal subdomains/paths or outbound domains.
- `limit` (*integer*, optional, default: `50`, min: `1`, max: `200`): Maximum unique links to return.
- **Pay-Per-Event Event:** `links-extract` ($0.0005 USD) — *charged only after successful link extraction*.
#### JSON Request Example:
```json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "extract_clean_links",
"arguments": {
"url": "https://docs.apify.com",
"filterScope": "internal",
"limit": 3
}
}
}
```
#### JSON Response Example:
```json
{
"success": true,
"url": "https://docs.apify.com",
"totalFound": 68,
"links": [
{
"href": "https://docs.apify.com/",
"text": "Skip to main content",
"isInternal": true
},
{
"href": "https://docs.apify.com/get-started",
"text": "Get started",
"isInternal": true
},
{
"href": "https://docs.apify.com/actors",
"text": "Actors",
"isInternal": true
}
]
}
```
---
## 🛡️ Security & SSRF Firewall (`src/security/ssrf.ts`)
Autonomous agents frequently evaluate untrusted URLs. To prevent Server-Side Request Forgery (SSRF) and cloud infrastructure exploitation, every request passes through a multi-tier firewall:
1. **Protocol Whitelisting:** Rejects all non-web schemes (`file://`, `ftp://`, `gopher://`, `data:`, `javascript:`).
2. **DNS Pre-Validation & IP Inspection:**
- Pre-resolves target hostnames asynchronously using Node.js `dns/promises`.
- Inspects dual-stack addresses (IPv4 & IPv6, including IPv4-mapped IPv6 `::ffff:...`).
- Blocks:
- **Loopback:** `127.0.0.0/8`, `::1`
- **Private LAN (RFC 1918):** `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`
- **Cloud Metadata (Link-Local):** `169.254.0.0/16`, `fe80::/10`
- **Carrier-Grade NAT & Multicast:** `100.64.0.0/10`, `224.0.0.0/4`, `ff00::/8`
- **Internal hostnames:** `*.internal`, `*.local`, `*.localhost`, `*.lan`, `metadata.google.internal`
3. **Safe Redirect Verification:** Follows HTTP 301/302/303/307/308 redirects manually (`redirect: 'manual'`), executing full SSRF validation before every consecutive hop (maximum 5 hops).
4. **Hard 4,000ms Global Timeout Budget:** Prevents target tarpits from exhausting container concurrency.
5. **Memory Cap:** Enforces a 5MB response size limit to protect the 256MB container.
---
## 💰 Transparent Pricing & Zero-Charge Policy
Apify's Pay-Per-Event (PPE) model allows agents to pay purely for successfully parsed content rather than paying idle server runtime.
| Event Name | Action | Price (USD) | Charging Guarantee |
| :--- | :--- | :--- | :--- |
| `markdown-extract` | Clean GFM Markdown extraction | **$0.001** | Charged **only** when non-empty Markdown is returned. |
| `metadata-extract` | JSON-LD, OpenGraph & Outline | **$0.0005** | Charged **only** when HTML metadata is parsed. |
| `links-extract` | Deduplicated Navigation Links | **$0.0005** | Charged **only** when clean links are extracted. |
### 🔒 Zero-Charge Guarantee on Failures
If target sites return **HTTP 403, 404, 429, 500**, DNS resolution fails (`NXDOMAIN`), requests time out (>4,000ms), or an address is blocked by the SSRF firewall:
- The server returns an informative structured failure JSON object:
```json
{
"success": false,
"url": "http://127.0.0.1:8080/admin",
"errorCode": "SSRF_BLOCKED",
"reason": "Restricted IPv4 address in 'loopback' range (127.0.0.1)"
}
```
- **`Actor.charge()` is strictly NOT called.**
- No unhandled exceptions are thrown to maintain a 100% platform Quality Score.
---
## 🚀 Client Configuration & Integration
### Option 1: Direct Local / NPM Execution (Stdio)
Add to your `claude_desktop_config.json` or Cursor MCP settings:
```json
{
"mcpServers": {
"clean-web-markdown": {
"command": "npx",
"args": ["-y", "mcp-clean-web-markdown"]
}
}
}
```
Or install via Smithery CLI:
```bash
npx -y @smithery/cli install mcp-clean-web-markdown --client claude
```
---
### Option 2: Hosted Apify Standby Server (Streamable HTTP)
Connect directly to the persistent, 0ms-cold-start cloud container:
```json
{
"mcpServers": {
"clean-web-markdown": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-streamable-http",
"https://meanusarcanus--mcp-clean-web-markdown.apify.actor/mcp",
"--header",
"Authorization: Bearer YOUR_APIFY_API_TOKEN"
]
}
}
}
```
### Direct HTTP / Curl Usage (Streamable HTTP)
```bash
curl -X POST https://meanusarcanus--mcp-clean-web-markdown.apify.actor/mcp \
-H "Authorization: Bearer YOUR_APIFY_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "extract_clean_markdown",
"arguments": {
"url": "https://docs.apify.com"
}
}
}'
```
---
## 💻 Local Development & Testing
```bash
# Clone the repository
git clone https://github.com/meanusarcanus/mcp-clean-web-markdown.git
cd mcp-clean-web-markdown
# Install dependencies
npm install
# Run automated Vitest test suite (21 unit & integration tests)
npm test
# Build production TypeScript output
npm run build
# Start local server with stdio or HTTP
npx -y mcp-clean-web-markdown
# or HTTP mode on port 8080:
PORT=8080 npm start
```
### Health Check:
```bash
curl http://localhost:8080/health
```
---
## 📄 License
Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues