agentleFS
mysleekdesignsmysleekdesigns/crawlforge-mcp/CLAUDE.md

crawlforge-mcp

CLAUDE.md2 starsChanged 3 months agoMITView on GitHub

Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed. Tradeoff: These guidelines bias toward caution over speed. For trivial tasks, use judgment. 1. Think Before Coding Don't assume. Don't hide confusion. Surface tradeoffs. Before implementing: State your assumptions explicitly. If uncertain, ask. If multiple interpretations exist, present them - don't pick silently. If a simpler approach exists, say so. Push back when warranted. If something is unclear, stop. Name what's confusing. Ask. 2. Simplicity First…

  • Reads credentials
  • Installs packages

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

29 rules. About 0 are common, 16 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈16

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Don't assume. Don't hide confusion.

    line 10
  2. Distinctive:

    If multiple interpretations exist, present them - don't pick silently.

    line 15
  3. Distinctive:

    If a simpler approach exists, say so.

    line 16
  4. Distinctive:

    If something is unclear, stop.

    line 17
  5. Distinctive:

    No features beyond what was asked.

    line 22
  6. Distinctive:

    No abstractions for single-use code.

    line 23
  7. Distinctive:

    No error handling for impossible scenarios.

    line 25
  8. Distinctive:

    If you write 200 lines and it could be 50, rewrite it.

    line 26
  9. Distinctive:

    Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.

    line 27
  10. Distinctive:

    When editing existing code:

    line 32
  11. Distinctive:

    Don't "improve" adjacent code, comments, or formatting.

    line 34
  12. Distinctive:

    Don't refactor things that aren't broken.

    line 35
  13. Distinctive:

    If you notice unrelated dead code, mention it - don't delete it.

    line 37
  14. Distinctive:

    When your changes create orphans:

    line 38
  15. Very specific:

    Remove imports/variables/functions that YOUR changes made unused.

    line 40
  16. Distinctive:

    Don't remove pre-existing dead code unless asked.

    line 41
  17. Very specific:

    All diagnostic output (Winston logs + status banners) goes to stderr.

    line 126
  18. Very specific:

    Use --expose-gc flag for memory profiling: node --expose-gc server.js

    line 128
  19. Very specific:

    Check cache/ directory for cached responses

    line 129
  20. Very specific:

    Tool Registration: All tools registered via server.registerTool(), wrapped with withAuth() for credit tracking

    line 196
  21. Very specific:

    When adding a new tool to server.js:

    line 272
  22. Very specific:

    Import the tool class from src/tools/

    line 274
  23. Very specific:

    Ensure tool implements execute(params) method

    line 277
  24. Very specific:

    Add to cleanup array in gracefulShutdown if it has destroy() or cleanup() methods

    line 278
  25. Distinctive:

    Update tool count in console log at server startup

    line 279
  26. Very specific:

    Run npm audit locally to check dependencies.

    line 303
  27. Very specific:

    When a phase completes, update docs/PRODUCTION_READINESS.md

    line 338
  28. Very specific:

    Put all documentation md files into the docs/ folder

    line 340
  29. Very specific:

    Every time you finish a phase run the test suites (npm run test:unit and npm test) and fix all failures before pushing

    line 341

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.

Tradeoff: These guidelines bias toward caution over speed. For trivial tasks, use judgment.

  1. Think Before Coding Don't assume. Don't hide confusion. Surface tradeoffs.

Before implementing:

State your assumptions explicitly. If uncertain, ask. If multiple interpretations exist, present them - don't pick silently. If a simpler approach exists, say so. Push back when warranted. If something is unclear, stop. Name what's confusing. Ask.

  1. Simplicity First Minimum code that solves the problem. Nothing speculative.

No features beyond what was asked. No abstractions for single-use code. No "flexibility" or "configurability" that wasn't requested. No error handling for impossible scenarios. If you write 200 lines and it could be 50, rewrite it. Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.

  1. Surgical Changes Touch only what you must. Clean up only your own mess.

When editing existing code:

Don't "improve" adjacent code, comments, or formatting. Don't refactor things that aren't broken. Match existing style, even if you'd do it differently. If you notice unrelated dead code, mention it - don't delete it. When your changes create orphans:

Remove imports/variables/functions that YOUR changes made unused. Don't remove pre-existing dead code unless asked. The test: Every changed line should trace directly to the user's request.

  1. Goal-Driven Execution Define success criteria. Loop until verified.

Transform tasks into verifiable goals:

"Add validation" → "Write tests for invalid inputs, then make them pass" "Fix the bug" → "Write a test that reproduces it, then make it pass" "Refactor X" → "Ensure tests pass before and after" For multi-step tasks, state a brief plan:

  1. [Step] → verify: [check]
  2. [Step] → verify: [check]
  3. [Step] → verify: [check] Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.

These guidelines are working if: fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.

Project Overview

CrawlForge MCP Server - A professional MCP (Model Context Protocol) server providing 31 web scraping, crawling, and content processing tools (6 inline + 25 advanced).

Current Version: 5.6.6

Development Commands

# Install dependencies
npm install

# Setup (required for first run - users only)
npm run setup
# Or provide API key via environment:
export CRAWLFORGE_API_KEY="your_api_key_here"

# Run the server (production)
npm start

# HTTP transport mode
npm run start:http

# Development mode with verbose logging
npm run dev

# Test MCP protocol compliance
npm test

# Unit tests (400+ tests across tests/unit/, no live network)
npm run test:unit
# Phase D regressions live in tests/unit/phaseD-regressions.test.js (agent hard stops, unified scrape, map_site ranking)
# Run a single test file:  node --test tests/unit/phaseD-regressions.test.js
# Note: the script includes --test-force-exit — importing StealthBrowserManager
# (d2-reliability.test.js) leaves a Playwright handle that otherwise hangs the
# runner at exit after all tests pass. When running a single file manually, put
# --test-force-exit BEFORE the file path (after it, the flag is silently ignored).

# Integration tests
npm run test:integration

# Functional tests
node test-tools.js             # Test all tools
node test-real-world.js        # Test real-world usage scenarios

# MCP Protocol tests
node tests/integration/mcp-protocol-compliance.test.js

# CLI (v4.1.0+, requires global install or npx)
crawlforge --help              # Show all subcommands
crawlforge init                # API-key detection + skill install + idempotent MCP-stanza merge (v4.6.0)
crawlforge init --all --yes    # Merge MCP config into Claude Code / Desktop / Cursor non-interactively
crawlforge scrape https://example.com
crawlforge batch --urls urls.txt --format markdown
crawlforge install-skills --target claude-code
# See docs/cli-guide.md for full reference

# Docker
npm run docker:build         # Build Docker image
npm run docker:dev          # Run development container
npm run docker:prod         # Run production container

Debugging Tips

  • All diagnostic output (Winston logs + status banners) goes to stderr; stdout is reserved for the MCP JSON-RPC stream and CLI --json output (enforced in v4.2.4)
  • Set NODE_ENV=development for verbose logging
  • Use --expose-gc flag for memory profiling: node --expose-gc server.js
  • Check cache/ directory for cached responses
  • Review logs/ directory for application logs
  • Memory monitoring auto-enabled in development mode (logs every 60s if >200MB)

High-Level Architecture

Core Infrastructure (src/core/)

  • AuthManager: Authentication, credit tracking, and usage reporting
  • PerformanceManager: Centralized performance monitoring and optimization
  • JobManager: Asynchronous job tracking and management for batch operations
  • WebhookDispatcher: Event notification system for job completion callbacks
  • ActionExecutor: Browser automation engine (Playwright-based)
  • ResearchOrchestrator: Multi-stage research with query expansion and synthesis
  • AgentOrchestrator: Powers the agent tool — NL prompt → autonomous PLAN→GATHER→ACT→DECIDE→SHAPE loop with three orchestrator-enforced hard stops (maxSteps≤10, maxUrls≤20, wall-clock) never delegated to the LLM; degraded no-LLM-key path (D2, v4.6.0)
  • StealthBrowserManager: Stealth mode scraping with anti-detection; Camoufox (Firefox) engine added in v4.0.0. Engine selection goes through the one resolver resolveStealthEngine(requested) → {engine, fallbackWarning}; 'auto' (the default for scrape.escalate_engine and stealth_mode.engine since the 2026-09 stealth review Phase 2) prefers Camoufox and falls back to Chromium with a caller-visible warning when its binary is absent. 'playwright' is the tool layer's public name for Chromium. Camoufox personas are pinned to the installed binary's Firefox major so the UA's rv: and Firefox/ tokens agree — see docs/STEALTH_REVIEW_2026-09.md
  • LocalizationManager: Multi-language content and localization
  • ChangeTracker: Content change tracking over time
  • SnapshotManager: Website snapshots and version history
  • ResourceRegistry: MCP Resources (crawlforge:// URI scheme, 5 resource types) — D1.1, v3.6.0
  • PromptRegistry (src/prompts/): 5 workflow prompts — D1.2, v3.6.0
  • SamplingClient: MCP Sampling with Ollama-API fallback chain — D1.3, v3.6.0
  • ElicitationHelper: MCP Elicitation for user confirmation on expensive operations — D1.4, v3.6.0
  • endpointGuard: Allow-list guard for server's own backend calls — v3.0.18

Tool Layer (src/tools/)

Tools are organized in subdirectories by category:

  • advanced/ - BatchScrapeTool, ScrapeWithActionsTool, BrowserSessionTool
  • agent/ - agent (AgentOrchestrator-driven autonomous tool, v4.6.0)
  • basic/ - fetchUrl, extractText, extractLinks, extractMetadata, scrapeStructured
  • scrape/ - unifiedScrape (single-fetch multi-format scrape tool, v4.6.0)
  • crawl/ - crawlDeep, mapSite
  • extract/ - analyzeContent, extractContent, extractStructured, extractWithLlm, listOllamaModels, processDocument, summarizeContent
  • research/ - deepResearch
  • result/ - readResult (read_result: search/slice/lines/json_path over a stored over-threshold result by result_handle, v5.8.0)
  • search/ - searchWeb (proxied through CrawlForge.dev API), serpRank (real Google organic rank via DataForSEO; adapter in search/adapters/dataforseoSearch.js), redditSearch (Reddit posts/comments/threads via Arctic Shift + PullPush community archives — reddit.com blocks scrapers)
  • templates/ - ScrapeTemplateTool (10 pre-built site templates, v4.0.0)
  • tracking/ - trackChanges
  • llmstxt/ - generateLLMsTxt

Available MCP Tools (31 total)

Basic Tools (server.js inline, 6): fetch_url, extract_text, extract_links, extract_metadata, extract_embedded_state, scrape_structured

Advanced Tools (25): search_web, serp_rank, reddit_search, crawl_deep, map_site, extract_content, process_document, summarize_content, analyze_content, extract_structured, extract_with_llm, list_ollama_models, batch_scrape, get_batch_results, scrape_with_actions, deep_research, track_changes, generate_llms_txt, stealth_mode, localization, scrape_template, scrape, agent, read_result, browser_session

serp_rank (DataForSEO):

  • serp_rank — reports where a target domain ranks in Google's REAL organic results for a keyword (the SERP position Google Custom Search / search_web cannot give). Backed by the DataForSEO Google Organic SERP API (Live Advanced, POST /v3/serp/google/organic/live/advanced, HTTP Basic auth). Credentials via DATAFORSEO_LOGIN / DATAFORSEO_PASSWORD, billed to the user's own DataForSEO account (~US$0.002 per 10 results of depth, so $0.004 at the default depth:20 and $0.02 at depth:100), separate from CrawlForge credits. When unconfigured it returns { configured:false } and charges 0 credits; when configured, Cost: 5. Never fabricates a rank.

reddit_search (community archives, v5.1.0):

  • reddit_search — searches Reddit posts/comments or reads a full comment thread. reddit.com 403-blocks ALL direct access (fetch, browser-UA, stealth — IP/TLS-reputation based), so this never touches reddit.com; it queries the Arctic Shift archive (arctic-shift.photon-reddit.com, near-real-time, comment trees) and PullPush (api.pullpush.io, Pushshift-compatible). Routing: Arctic Shift's keyword search REQUIRES a subreddit/author scope (verified live: HTTP 400 without one), so a scoped search queries it directly, while an unscoped keyword search for posts discovers them with a site-restricted web search and then reads those posts from the archive by ID (source:"web_discovery"). PullPush stopped serving automated clients in August 2026 (429 "does not provide free scraping resources for agents" on every UA; Cloudflare 403 from some IPs) and is no longer tried automatically anywhere — source:"pullpush" still reaches it. An unscoped COMMENT search has no backend and returns a scope-required error. Modes: posts (default), comments, thread (post + nested comment tree by link_id). Free, no Reddit credentials. Cost: 5 — a Reddit-wide search spends the same web search search_web does. REDDIT_SEARCH_TIMEOUT_MS overrides the 30s default.

v4.6.0 additions (Phase D):

  • scrape — single fetch + one cheerio load dispatching a formats array (markdown/html/rawHtml/text/links/metadata/screenshot/json-schema) + onlyMainContent; partial-success via per-format warnings[]. Cost: 2.
  • agent — NL prompt → autonomous research/extract, no URLs required (see AgentOrchestrator above). Cost: 8.
  • map_site gained an optional search= param that ranks discovered URLs (ranked_urls:[{url,score}]); default output unchanged.

MCP Server Entry Point

The main server implementation is in server.js which:

  1. Secure Creator Mode: Loads .env early, validates secret via SHA256 hash comparison
  2. Authentication Flow: AuthManager for API key validation and credit tracking
  3. Tool Registration: All tools registered via server.registerTool(), wrapped with withAuth() for credit tracking
  4. Transport: stdio transport for MCP protocol communication
  5. Graceful Shutdown: Cleans up browser instances, job managers, and other resources

Tool Credit System

Each tool wrapped with withAuth(toolName, handler):

  • Checks credits before execution (skipped in creator mode)
  • Reports usage with credit deduction on success
  • Charges half credits on error
  • Creator mode: Unlimited access for package maintainer

Key Configuration

Critical environment variables defined in src/constants/config.js:

CRAWLFORGE_API_KEY=your_api_key_here
MAX_WORKERS=10
QUEUE_CONCURRENCY=10
CACHE_TTL=3600000
RATE_LIMIT_REQUESTS_PER_SECOND=10
MAX_CRAWL_DEPTH=5
MAX_PAGES_PER_CRAWL=100
RESPECT_ROBOTS_TXT=true
ROBOTS_CACHE_TTL_MS=3600000          # how long a parsed robots.txt stays good for
CRAWLFORGE_BLOCKED_HOSTS=            # comma-separated; extends the permanent opt-out blocklist
CRAWLFORGE_STEALTH_ENGINE=           # which engine `auto` resolves to on THIS deployment:
                                     # chromium|playwright pins it to Chromium; unset or anything
                                     # else keeps the default preference for Camoufox. A caller
                                     # naming an engine always wins. There is no correct global
                                     # value — which engine clears a wall depends on the exit IP
                                     # (residential favours Camoufox, the hosted datacenter IP
                                     # favours Chromium, measured twice).
CRAWLFORGE_STEALTH_PROXIES=          # comma-separated proxy URLs used by the escalation stage,
                                     # stealth_mode, browser_session, scrape_with_actions and the
                                     # deep_research fallback when the caller passes none (a proxy
                                     # passed on the call wins). CrawlForge supplies no proxies, and
                                     # a datacenter one does not defeat these detectors. Distinct
                                     # from the PROXY_ROTATION_* family, which belongs to
                                     # localization. The agent's automatic stealth retry
                                     # (stealth review Phase 3) reads it too.
CRAWLFORGE_IMPIT=                    # `off` skips escalation's impit step (a Chrome TLS handshake with
                                     # the honest UA, tried before the browser; stealth review Phase 7).
                                     # Exit-IP dependent like the engine: it cleared indeed.com from a
                                     # residential IP and nothing from the hosted datacenter IP, so
                                     # render.yaml sets it off there. Measure with scripts/impit-probe.mjs.
CRAWLFORGE_CLEARANCE_JAR=            # `off` disables the clearance jar (stealth review Phase 4):
                                     # cf_clearance/__cf_bm/datadome cookies a stealth render earned
                                     # are replayed to the next stealth context with the same engine,
                                     # UA and proxy. Persisted at ~/.crawlforge/stealth-clearance.json.

Camoufox is an optional dependency and its transitive language-tags@2.1.0 requires Node ≥22. npm silently drops an optional subtree that fails an engine check, so on Node 20 it is simply absent — 'auto' then resolves to Chromium and says so in fallbackWarning. engines.node stays at >=20.16.0 deliberately; bumping it is breaking and is a release decision.

Web Bot Auth (optional, off by default — requests go out unsigned when unset):

CRAWLFORGE_SIGNING_KEY=              # Ed25519 PKCS#8 PEM, or base64 of it. SECRET — never commit.
WEB_BOT_AUTH_DIRECTORY=              # https://www.crawlforge.dev — advertised in Signature-Agent

Generate the pair with node scripts/generate-signing-key.mjs; publish the public half before setting the private one. Procedure and compromise response: docs/policy/KEY_ROTATION.md.

OPENAI_API_KEY / ANTHROPIC_API_KEY are optional. They only affect deep_research: when set, it produces a fully synthesized report internally; when unset, it returns raw evidence for the calling LLM (e.g. Claude Code) to synthesize.

Configuration Files

  • ~/.crawlforge/config.json - User authentication and API key storage
  • .env - Environment variables for development
  • src/constants/config.js - Central configuration with defaults and validation

Adding New Tools

When adding a new tool to server.js:

  1. Import the tool class from src/tools/
  2. Instantiate the tool (with config if needed)
  3. Register with server.registerTool(name, { description, inputSchema }, withAuth(name, handler))
  4. Ensure tool implements execute(params) method
  5. Add to cleanup array in gracefulShutdown if it has destroy() or cleanup() methods
  6. Update tool count in console log at server startup

Sandboxing & Approvals

Key mechanisms for security-conscious future sessions:

  • SSRF (src/utils/ssrfGuard.js enforcing src/utils/ssrfProtection.js): As of v4.8.0 SSRF is actually enforced on the live scraping fetch path (previously ssrfProtection.js was unwired). ssrfGuard injects an undici dispatcher whose connect-time lookup validates every connection — initial request and each redirect hop — and pins the validated IP (closing the DNS-rebinding TOCTOU window). Stage 1 (default) blocks loopback, link-local/cloud-metadata (169.254.169.254), and 0.0.0.0; SSRF_STRICT=true adds full RFC1918/ULA/etc. enforcement. Kill switch SSRF_PROTECTION_ENABLED=false; ALLOWED_DOMAINS allowlist bypass. Wired into every read-scrape site (_fetch.js, _fetchAndParse.js, batchScrape/worker.js, mapSite.js, BFSCrawler.js, extract/template/session/research/llms-txt/robots/sitemap/track-changes fetches) via ssrfGuard()/safeFetch(). http/https only; dangerous ports + path-traversal still rejected by ssrfProtection.js.
  • endpointGuard (src/core/endpointGuard.js): Hard allow-list of {crawlforge.dev, www.crawlforge.dev, api.crawlforge.dev} for the server's own backend calls; HTTPS required; fail-closed. Localhost only in creator mode (v3.0.18).
  • Action allowlist (src/core/ActionExecutor.js): scrape_with_actions accepts only 7 action types: wait, click, type, press, scroll, screenshot, executeJavaScript. executeJavaScript throws unless ALLOW_JAVASCRIPT_EXECUTION=true is set at deploy time (off by default).
  • Elicitation (src/core/ElicitationHelper.js): User confirmation requested for deep_research (>50 URLs), batch_scrape (sync, >25 URLs), crawl_deep (projected >500 pages), extract_structured (schema has >3 required fields, no LLM configured), and credit-low situations. Fail-open if client does not support elicitation.
  • Browser sandboxing: Standard pool retains OS sandbox. Stealth Chromium uses --no-sandbox (deliberate fingerprint-spoofing trade-off); --disable-web-security was removed from it in Phase 1 of the 2026-09 stealth review — a page reads it in one line — but the non-stealth render browser (BrowserProcessor) still carries both flags. Camoufox (Firefox, v4.0.0) is the alternative — see docs/stealth-engines.md.

See docs/sandboxing-and-approvals.md for the full reference.

Security

Security testing and CI/CD pipeline details are in:

  • docs/sandboxing-and-approvals.md — Canonical sandboxing & approvals reference
  • docs/security-audit-report.md — Full security audit
  • .github/workflows/ci.yml — CI pipeline with security checks
  • .github/workflows/security.yml — Daily scheduled security scanning
  • docs/SECURITY.md — Security policy and procedures

Run npm audit locally to check dependencies.

Implementation Patterns

Tool Structure

export class ToolName {
  constructor(config) { this.config = config; }

  async execute(params) {
    return { success: true, data: {...} };
  }

  async destroy() { /* cleanup resources */ }
}

Error Handling Pattern

try {
  const result = await tool.execute(params);
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
} catch (error) {
  return {
    content: [{ type: "text", text: `Operation failed: ${error.message}` }],
    isError: true,
  };
}

Project Management Rules

  • Delegate to a sub agent only for a genuinely independent, parallelizable track — not for work finishable in a few tool calls, and never to verify your own output (Claude 5 models over-delegate when told to parallelize)
  • When a phase completes, update docs/PRODUCTION_READINESS.md
  • Whenever a phase is completed, push all changes to GitHub
  • Put all documentation md files into the docs/ folder
  • Every time you finish a phase run the test suites (npm run test:unit and npm test) and fix all failures before pushing

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.