{
  "markdown": "# Refinery MCP\n\nClean HTML before your agent burns tokens.\n\n[Landing page](https://larelabs.github.io/refinery-mcp/) · [Apify Actor](https://apify.com/larelabs/refinery-html-to-llm-cleaner)\n\n<!-- mcp-name: io.github.LareLabs/refinery-mcp -->\n\nRefinery MCP wraps the [Refinery Apify Actor](https://apify.com/larelabs/refinery-html-to-llm-cleaner) as an MCP server so Claude, Cursor, and other agents can turn raw HTML or URLs into clean LLM-ready text plus `word_count`.\n\n![Agent pipeline: fetch, Refinery MCP, clean text, RAG](https://i.imgur.com/rKLRTc1.png)\n\n```mermaid\nflowchart LR\n  A[Agent needs web context] --> B[Fetch URL or raw HTML]\n  B --> C[Refinery MCP]\n  C --> D[Refinery Apify Actor]\n  D --> E[Clean text + word_count]\n  E --> F[RAG / embeddings / LLM context]\n```\n\n## The Problem\n\nAgents are getting good at fetching web pages. The problem is what they fetch:\n\n```html\n<html>\n  <head>\n    <script>gtag(\"event\", \"page_view\")</script>\n    <style>.nav,.cookie,.footer{display:block}</style>\n  </head>\n  <body>\n    <nav>Home · Pricing · Login · Docs · Blog · Careers</nav>\n    <aside>Subscribe to our newsletter</aside>\n    <article>\n      <h1>How ACME cut support ticket routing time by 63%</h1>\n      <p>ACME routes 40,000 monthly support tickets through an AI triage system.</p>\n      <p>The team reduced retrieval noise by cleaning HTML before chunking.</p>\n    </article>\n    <footer>Legal · Privacy · Cookie settings · LinkedIn · X</footer>\n  </body>\n</html>\n```\n\nThe model does not need most of that. It needs this:\n\n```text\nHow ACME cut support ticket routing time by 63%\n\nACME routes 40,000 monthly support tickets through an AI triage system.\nThe team reduced retrieval noise by cleaning HTML before chunking.\n```\n\n![Before and after: bloated HTML vs clean LLM-ready text and token savings](https://i.imgur.com/RxmHFBz.png)\n\nRefinery MCP gives your agent a tool for that middle step:\n\n```text\nfetch page -> refine HTML -> send clean text to RAG / embeddings / LLM\n```\n\n## Why\n\nAgents can fetch pages, but raw HTML is noisy and expensive:\n\n- scripts, styles, tracking tags\n- nav, footers, cookie banners\n- repeated links and layout markup\n- huge token burn before the model sees the real content\n\nRefinery is the middle step your agent can call before it stuffs web context into a prompt:\n\n```text\nfetch/render -> clean/refine -> chunk/embed/answer\n```\n\nIt is **not a crawler**. Use Firecrawl, Crawl4AI, Playwright, browser automation, or your own fetcher when you need rendering. Use Refinery when you already have a URL or raw HTML and want a cheap cleanup pass before the LLM.\n\n## When To Use It\n\nUse Refinery MCP when:\n\n- your agent already fetched a page but got bloated HTML\n- you want a deterministic cleanup step before RAG ingestion\n- you need `word_count` / token-ish savings before embedding\n- you want to separate crawling from content cleanup\n\nDo not use it as your browser renderer, anti-bot layer, or site crawler.\n\n## Tools\n\n### `clean_url`\n\nFetches a URL through the Refinery Apify Actor and returns dataset rows with clean text and metadata.\n\nExample input:\n\n```json\n{\n  \"url\": \"https://docs.stripe.com/payments\",\n  \"removeScripts\": true,\n  \"removeStyles\": true\n}\n```\n\n### `clean_html`\n\nCleans raw HTML your agent, crawler, or browser session already fetched.\n\nExample input:\n\n```json\n{\n  \"html\": \"<html><body><nav>Home Pricing Login</nav><article><h1>Vendor security update</h1><p>We now support SOC 2 exports for enterprise accounts.</p></article><footer>Legal Privacy Careers</footer></body></html>\",\n  \"extractMentions\": false,\n  \"extractHashtags\": false\n}\n```\n\nExample result:\n\n```json\n{\n  \"text\": \"Vendor security update\\n\\nWe now support SOC 2 exports for enterprise accounts.\",\n  \"word_count\": 10,\n  \"content_type\": \"web\",\n  \"language\": \"en\",\n  \"processing_time_ms\": 44.96,\n  \"success\": true\n}\n```\n\n### `estimate_savings`\n\nLocal helper that compares raw HTML vs cleaned text and estimates token savings. This does not call Apify.\n\nExample output:\n\n```json\n{\n  \"raw_chars\": 168,\n  \"clean_chars\": 41,\n  \"estimated_raw_tokens\": 42,\n  \"estimated_clean_tokens\": 11,\n  \"estimated_token_savings\": 31,\n  \"reduction_pct\": 76\n}\n```\n\n## Install\n\n```bash\nnpx -y @larelabs/refinery-mcp\n```\n\nSet your Apify token:\n\n```bash\nexport APIFY_TOKEN=apify_api_xxx\nexport REFINERY_ACTOR_ID=larelabs/refinery-html-to-llm-cleaner\n```\n\n## Cursor / Claude Desktop config\n\nUse the published package:\n\n```json\n{\n  \"mcpServers\": {\n    \"refinery\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@larelabs/refinery-mcp\"],\n      \"env\": {\n        \"APIFY_TOKEN\": \"apify_api_xxx\",\n        \"REFINERY_ACTOR_ID\": \"larelabs/refinery-html-to-llm-cleaner\"\n      }\n    }\n  }\n}\n```\n\nOr run from source during development:\n\n```bash\ngit clone https://github.com/LareLabs/refinery-mcp\ncd refinery-mcp\nnpm install\nnpm run build\n```\n\n```json\n{\n  \"mcpServers\": {\n    \"refinery\": {\n      \"command\": \"npm\",\n      \"args\": [\"run\", \"dev\", \"--prefix\", \"/absolute/path/to/refinery-mcp\"],\n      \"env\": {\n        \"APIFY_TOKEN\": \"apify_api_xxx\"\n      }\n    }\n  }\n}\n```\n\n## Smoke Test\n\n```bash\nnpm run build\nAPIFY_TOKEN=apify_api_xxx npm run smoke\n```\n\nThe smoke test starts the MCP server over stdio, lists tools, and calls `estimate_savings` without spending Apify credits.\n\n## Example Agent Prompt\n\n```text\nUse Refinery MCP to clean this docs page before summarizing it:\nhttps://docs.stripe.com/payments\n\nReturn the clean text, word_count, and a short summary. Do not summarize raw HTML.\n```\n\nAnother useful prompt:\n\n```text\nI fetched this page HTML with Playwright. Use Refinery MCP clean_html before adding it to my RAG ingestion queue. Return the cleaned text and estimated token savings.\n```\n\n## Roadmap\n\n- Glama listing (`glama.json` added — submit at https://glama.ai/mcp/servers)\n- mcp.so directory PR (pending)\n- Hosted HTTP/SSE MCP transport\n- Batch URL cleanup tool\n- Glama / PulseMCP / FindMCP / mcp.so listings\n- Optional direct REST wrapper for RapidAPI\n- Token savings benchmark page\n\n## License\n\nMIT\n",
  "bytes": 6005,
  "sha": "d13fc340bdafc4a5dbfb34906b6e699e8d05c9869c79cac958da9ede6fd1688c",
  "repo_slug": "larelabs/refinery-mcp",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_larelabs_refinery_mcp_70bb5a18/readme"
}