Crawl Ai Rag
    Crawl Ai Rag

    Crawl Ai Rag

    Web Crawling and RAG Capabilities for AI Agents and AI Coding Assistants

    4.3

    GitHub Stats

    Stars

    1268

    Forks

    419

    Release Date

    6/19/2025

    about three weeks ago

    Detailed Description

    a powerful implementation of the model context protocol (mcp) integrated with crawl4ai and supabase for providing ai agents and ai coding assistants with advanced web crawling and rag capabilities.

    with this mcp server, you can scrape anything and then use that knowledge anywhere for rag.

    the primary goal is to bring this mcp server into archon as i evolve it to be more of a knowledge engine for ai coding assistants to build ai agents. this first version of the crawl4ai/rag mcp server will be improved upon greatly soon, especially making it more configurable so you can use different embedding models and run everything locally with ollama.

    consider this github repository a testbed, hence why i haven't been super actively address issues and pull requests yet. i certainly will though as i bring this into archon v2!

    overview

    this mcp server provides tools that enable ai agents to crawl websites, store content in a vector database (supabase), and perform rag over the crawled content. it follows the best practices for building mcp servers based on the mem0 mcp server template i provided on my channel previously.

    the server includes several advanced rag strategies that can be enabled to enhance retrieval quality:

    • contextual embeddings for enriched semantic understanding
    • hybrid search combining vector and keyword search
    • agentic rag for specialized code example extraction
    • reranking for improved result relevance using cross-encoder models
    • knowledge graph for ai hallucination detection and repository code analysis

    see the configuration section below for details on how to enable and configure these strategies.

    vision

    the crawl4ai rag mcp server is just the beginning. here's where we're headed:

    1. integration with archon: building this system directly into archon to create a comprehensive knowledge engine for ai coding assistants to build better ai agents.

    2. multiple embedding models: expanding beyond openai to support a variety of embedding models, including the ability to run everything locally with ollama for complete control and privacy.

    3. advanced rag strategies: implementing sophisticated retrieval techniques like contextual retrieval, late chunking, and others to move beyond basic "naive lookups" and significantly enhance the power and precision of the rag system, especially as it integrates with archon.

    4. enhanced chunking strategy: implementing a context 7-inspired chunking approach that focuses on examples and creates distinct, semantically meaningful sections for each chunk, improving retrieval precision.

    5. performance optimization: increasing crawling and indexing speed to make it more realistic to "quickly" index new documentation to then leverage it within the same prompt in an ai coding assistant.

    features

    • smart url detection: automatically detects and handles different url types (regular webpages, sitemaps, text files)
    • recursive crawling: follows internal links to discover content
    • parallel processing: efficiently crawls multiple pages simultaneously
    • content chunking: intelligently splits content by headers and size for better processing
    • vector search: performs rag over crawled content, optionally filtering by data source for precision
    • source retrieval: retrieve sources available for filtering to guide the rag process

    tools

    the server provides essential web crawling and search tools:

    core tools (always available)

    1. crawl_single_page: quickly crawl a single web page and store its content in the vector database
    2. smart_crawl_url: intelligently crawl a full website based on the type of url provided (sitemap, llms-full.txt, or a regular webpage that needs to be crawled recursively)
    3. get_available_sources: get a list of all available sources (domains) in the database
    4. perform_rag_query: search for relevant content using semantic search with optional source filtering

    conditional tools

    1. search_code_examples (requires use_agentic_rag=true): search specifically for code examples and their summaries from crawled documentation. this tool provides targeted code snippet retrieval for ai coding assistants.

    knowledge graph tools (requires use_knowledge_graph=true, see below)

    1. parse_github_repository: parse a github repository into a neo4j knowledge graph, extracting classes, methods, functions, and their relationships for hallucination detection
    2. check_ai_script_hallucinations: analyze python scripts for ai hallucinations by validating imports, method calls, and class usage against the knowledge graph
    3. query_knowledge_graph: explore and query the neo4j knowledge graph with commands like repos, classes, methods, and custom cypher queries

    prerequisites

    installation

    using docker (recommended)

    1. clone this repository:

      git clone https://github.com/coleam00/mcp-crawl4ai-rag.git
      cd mcp-crawl4ai-rag
      
    2. build the docker image:

      docker build -t mcp/crawl4ai-rag --build-arg port=8051 .
      
    3. create a .env file based on the configuration section below

    using uv directly (no docker)

    1. clone this repository:

      git clone https://github.com/coleam00/mcp-crawl4ai-rag.git
      cd mcp-crawl4ai-rag
      
    2. install uv if you don't have it:

      pip install uv
      
    3. create and activate a virtual environment:

      uv venv
      .venv\scripts\activate
      # on mac/linux: source .venv/bin/activate
      
    4. install dependencies:

      uv pip install -e .
      crawl4ai-setup
      
    5. create a .env file based on the configuration section below

    database setup

    before running the server, you need to set up the database with the pgvector extension:

    1. go to the sql editor in your supabase dashboard (create a new project first if necessary)

    2. create a new query and paste the contents of crawled_pages.sql

    3. run the query to create the necessary tables and functions

    knowledge graph setup (optional)

    to enable ai hallucination detection and repository analysis features, you need to set up neo4j.

    also, the knowledge graph implementation isn't fully compatible with docker yet, so i would recommend right now running directly through uv if you want to use the hallucination detection within the mcp server!

    for installing neo4j:

    local ai package (recommended)

    the easiest way to get neo4j running locally is with the local ai package - a curated collection of local ai services including neo4j:

    1. clone the local ai package:

      git clone https://github.com/coleam00/local-ai-packaged.git
      cd local-ai-packaged
      
    2. start neo4j: follow the instructions in the local ai package repository to start neo4j with docker compose

    3. default connection details:

      • uri: bolt://localhost:7687
      • username: neo4j
      • password: check the local ai package documentation for the default password

    manual neo4j installation

    alternatively, install neo4j directly:

    1. install neo4j desktop: download from neo4j.com/download

    2. create a new database:

      • open neo4j desktop
      • create a new project and database
      • set a password for the neo4j user
      • start the database
    3. note your connection details:

      • uri: bolt://localhost:7687 (default)
      • username: neo4j (default)
      • password: whatever you set during creation

    configuration

    create a .env file in the project root with the following variables:

    # mcp server configuration
    host=0.0.0.0
    port=8051
    transport=sse
    
    # openai api configuration
    openai_api_key=your_openai_api_key
    
    # llm for summaries and contextual embeddings
    model_choice=gpt-4.1-nano
    
    # rag strategies (set to "true" or "false", default to "false")
    use_contextual_embeddings=false
    use_hybrid_search=false
    use_agentic_rag=false
    use_reranking=false
    use_knowledge_graph=false
    
    # supabase configuration
    supabase_url=your_supabase_project_url
    supabase_service_key=your_supabase_service_key
    
    # neo4j configuration (required for knowledge graph functionality)
    neo4j_uri=bolt://localhost:7687
    neo4j_user=neo4j
    neo4j_password=your_neo4j_password
    

    rag strategy options

    the crawl4ai rag mcp server supports four powerful rag strategies that can be enabled independently:

    1. use_contextual_embeddings

    when enabled, this strategy enhances each chunk's embedding with additional context from the entire document. the system passes both the full document and the specific chunk to an llm (configured via model_choice) to generate enriched context that gets embedded alongside the chunk content.

    • when to use: enable this when you need high-precision retrieval where context matters, such as technical documentation where terms might have different meanings in different sections.
    • trade-offs: slower indexing due to llm calls for each chunk, but significantly better retrieval accuracy.
    • cost: additional llm api calls during indexing.

    2. use_hybrid_search

    combines traditional keyword search with semantic vector search to provide more comprehensive results. the system performs both searches in parallel and intelligently merges results, prioritizing documents that appear in both result sets.

    • when to use: enable this when users might search using specific technical terms, function names, or when exact keyword matches are important alongside semantic understanding.
    • trade-offs: slightly slower search queries but more robust results, especially for technical content.
    • cost: no additional api costs, just computational overhead.

    3. use_agentic_rag

    enables specialized code example extraction and storage. when crawling documentation, the system identifies code blocks (≥300 characters), extracts them with surrounding context, generates summaries, and stores them in a separate vector database table specifically designed for code search.

    • when to use: essential for ai coding assistants that need to find specific code examples, implementation patterns, or usage examples from documentation.
    • trade-offs: significantly slower crawling due to code extraction and summarization, requires more storage space.
    • cost: additional llm api calls for summarizing each code example.
    • benefits: provides a dedicated search_code_examples tool that ai agents can use to find specific code implementations.

    4. use_reranking

    applies cross-encoder reranking to search results after initial retrieval. uses a lightweight cross-encoder model (cross-encoder/ms-marco-minilm-l-6-v2) to score each result against the original query, then reorders results by relevance.

    • when to use: enable this when search precision is critical and you need the most relevant results at the top. particularly useful for complex queries where semantic similarity alone might not capture query intent.
    • trade-offs: adds ~100-200ms to search queries depending on result count, but significantly improves result ordering.
    • cost: no additional api costs - uses a local model that runs on cpu.
    • benefits: better result relevance, especially for complex queries. works with both regular rag search and code example search.

    5. use_knowledge_graph

    enables ai hallucination detection and repository analysis using neo4j knowledge graphs. when enabled, the system can parse github repositories into a graph database and validate ai-generated code against real repository structures. (not fully compatible with docker yet, i'd recommend running through uv)

    • when to use: enable this for ai coding assistants that need to validate generated code against real implementations, or when you want to detect when ai models hallucinate non-existent methods, classes, or incorrect usage patterns.
    • trade-offs: requires neo4j setup and additional dependencies. repository parsing can be slow for large codebases, and validation requires repositories to be pre-indexed.
    • cost: no additional api costs for validation, but requires neo4j infrastructure (can use free local installation or cloud auradb).
    • benefits: provides three powerful tools: parse_github_repository for indexing codebases, check_ai_script_hallucinations for validating ai-generated code, and query_knowledge_graph for exploring indexed repositories.

    you can now tell the ai coding assistant to add a python github repository to the knowledge graph like:

    "add https://github.com/pydantic/pydantic-ai.git to the knowledge graph"

    make sure the repo url ends with .git.

    you can also have the ai coding assistant check for hallucinations with scripts it just created, or you can manually run the command:

    python knowledge_graphs/ai_hallucination_detector.py [full path to your script to analyze]
    

    recommended configurations

    for general documentation rag:

    use_contextual_embeddings=false
    use_hybrid_search=true
    use_agentic_rag=false
    use_reranking=true
    

    for ai coding assistant with code examples:

    use_contextual_embeddings=true
    use_hybrid_search=true
    use_agentic_rag=true
    use_reranking=true
    use_knowledge_graph=false
    

    for ai coding assistant with hallucination detection:

    use_contextual_embeddings=true
    use_hybrid_search=true
    use_agentic_rag=true
    use_reranking=true
    use_knowledge_graph=true
    

    for fast, basic rag:

    use_contextual_embeddings=false
    use_hybrid_search=true
    use_agentic_rag=false
    use_reranking=false
    use_knowledge_graph=false
    

    running the server

    using docker

    docker run --env-file .env -p 8051:8051 mcp/crawl4ai-rag
    

    using python

    uv run src/crawl4ai_mcp.py
    

    the server will start and listen on the configured host and port.

    integration with mcp clients

    sse configuration

    once you have the server running with sse transport, you can connect to it using this configuration:

    {
      "mcpservers": {
        "crawl4ai-rag": {
          "transport": "sse",
          "url": "http://localhost:8051/sse"
        }
      }
    }
    

    note for windsurf users: use serverurl instead of url in your configuration:

    {
      "mcpservers": {
        "crawl4ai-rag": {
          "transport": "sse",
          "serverurl": "http://localhost:8051/sse"
        }
      }
    }
    

    note for docker users: use host.docker.internal instead of localhost if your client is running in a different container. this will apply if you are using this mcp server within n8n!

    note for claude code users:

    claude mcp add-json crawl4ai-rag '{"type":"http","url":"http://localhost:8051/sse"}' --scope user
    

    stdio configuration

    add this server to your mcp configuration for claude desktop, windsurf, or any other mcp client:

    {
      "mcpservers": {
        "crawl4ai-rag": {
          "command": "python",
          "args": ["path/to/crawl4ai-mcp/src/crawl4ai_mcp.py"],
          "env": {
            "transport": "stdio",
            "openai_api_key": "your_openai_api_key",
            "supabase_url": "your_supabase_url",
            "supabase_service_key": "your_supabase_service_key",
            "use_knowledge_graph": "false",
            "neo4j_uri": "bolt://localhost:7687",
            "neo4j_user": "neo4j",
            "neo4j_password": "your_neo4j_password"
          }
        }
      }
    }
    

    docker with stdio configuration

    {
      "mcpservers": {
        "crawl4ai-rag": {
          "command": "docker",
          "args": ["run", "--rm", "-i",
                   "-e", "transport",
                   "-e", "openai_api_key",
                   "-e", "supabase_url",
                   "-e", "supabase_service_key",
                   "-e", "use_knowledge_graph",
                   "-e", "neo4j_uri",
                   "-e", "neo4j_user",
                   "-e", "neo4j_password",
                   "mcp/crawl4ai"],
          "env": {
            "transport": "stdio",
            "openai_api_key": "your_openai_api_key",
            "supabase_url": "your_supabase_url",
            "supabase_service_key": "your_supabase_service_key",
            "use_knowledge_graph": "false",
            "neo4j_uri": "bolt://localhost:7687",
            "neo4j_user": "neo4j",
            "neo4j_password": "your_neo4j_password"
          }
        }
      }
    }
    

    knowledge graph architecture

    the knowledge graph system stores repository code structure in neo4j with the following components:

    core components (knowledge_graphs/ folder):

    • parse_repo_into_neo4j.py: clones and analyzes github repositories, extracting python classes, methods, functions, and imports into neo4j nodes and relationships
    • ai_script_analyzer.py: parses python scripts using ast to extract imports, class instantiations, method calls, and function usage
    • knowledge_graph_validator.py: validates ai-generated code against the knowledge graph to detect hallucinations (non-existent methods, incorrect parameters, etc.)
    • hallucination_reporter.py: generates comprehensive reports about detected hallucinations with confidence scores and recommendations
    • query_knowledge_graph.py: interactive cli tool for exploring the knowledge graph (functionality now integrated into mcp tools)

    knowledge graph schema:

    the neo4j database stores code structure as:

    nodes:

    • repository: github repositories
    • file: python files within repositories
    • class: python classes with methods and attributes
    • method: class methods with parameter information
    • function: standalone functions
    • attribute: class attributes

    relationships:

    • repository -[:contains]-> file
    • file -[:defines]-> class
    • file -[:defines]-> function
    • class -[:has_method]-> method
    • class -[:has_attribute]-> attribute

    workflow:

    1. repository parsing: use parse_github_repository tool to clone and analyze open-source repositories
    2. code validation: use check_ai_script_hallucinations tool to validate ai-generated python scripts
    3. knowledge exploration: use query_knowledge_graph tool to explore available repositories, classes, and methods

    building your own server

    this implementation provides a foundation for building more complex mcp servers with web crawling capabilities. to build your own:

    1. add your own tools by creating methods with the @mcp.tool() decorator
    2. create your own lifespan function to add your own dependencies
    3. modify the utils.py file for any helper functions you need
    4. extend the crawling capabilities by adding more specialized crawlers

    Star History

    Star History

    May 3May 9May 15May 21May 27Jun 2Jun 8Jun 14Jun 20Jul 103006009001,200
    Powered by MSeeP Analytics

    About the Project

    This app has not been claimed by its owner yet.

    Claim Ownership

    Receive Updates

    Security Updates

    Get notified about trust rating changes

    to receive email notifications.