How droreli/mcpdocsearch works
Project type and purpose
• This is an open-source documentation crawler and search server. It consists of two main pieces:
a. A CLI tool (crawler_cli/) that crawls web pages, cleans HTML, and produces consolidated Markdown files in ./storage/.
b. An MCP server (mcp_server/) that loads those Markdown files, chunks them by headings, generates vector embeddings, caches results, and exposes search/listing operations over the Model Context Protocol (MCP).
File structure
• Top-level:
• crawl.py – entry point to the crawler.
• crawler_cli/ – Python package with modules:
– main.py (Typer CLI definitions),
– crawler.py (crawl4ai integration),
– markdown.py (HTML cleaning & Markdown conversion),
– config.py and utils.py (configuration & helpers).
• mcp_server/ – Python package with modules:
– main.py (server startup),
– app.py (FastMCP app wiring),
– data_loader.py (load/cache .md files and embeddings),
– mcp_tools.py (defines MCP methods: list/search/headings),
– search.py (vector similarity search),
– config.py (server configuration).
• pyproject.toml & uv.lock – dependency and execution management via uv.
• .cursor/mcp.json – Cursor client configuration.
Key architectural insights from README
• Two-stage workflow: Crawl → Store → Load → Chunk → Embed → Serve.
• Caching layer in data_loader.py invalidates on Markdown file changes.
• External libraries: crawl4ai for crawling, BeautifulSoup for HTML cleaning, sentence-transformers & torch for embeddings, fastmcp for MCP protocol, typer for CLI.
a. Main components
• User / Developer
• CLI Layer (crawl.py & crawler_cli package)
• Crawl Engine (crawl4ai)
• HTML Cleaner & Markdown Converter (crawler_cli/markdown.py)
• Storage (local filesystem: ./storage/)
• MCP Server (mcp_server package)
• Cache Store (storage/document_chunks_cache.pkl)
• Embedding Service (sentence-transformers + torch)
• MCP API Layer (fastmcp)
• MCP Client (Cursor or Claude) via stdio transport
b. Relationships & interactions
1. User invokes uv run python crawl.py <URL> → CLI Layer
2. CLI Layer calls Crawl Engine → fetches pages → HTML Cleaner
3. Cleaned HTML → Markdown Converter → writes Markdown to ./storage/
4. User or Cursor client starts MCP Server (uv run python -m mcp_server.main)
5. On startup: Data Loader checks cache file; if stale or missing, reads .md files → splits into chunks → sends text to Embedding Service → collects vectors → writes cache. If cache valid, loads from pickle.
6. MCP Server (FastMCP app) registers tools (list_documents, get_document_headings, search_documentation).
7. MCP Client issues JSON-RPC calls over stdio → MCP Server → responds with document lists, heading trees, or search results (semantic similarity scores + chunk content).
c. Architectural patterns & design principles
• Separation of concerns: Crawling vs. serving/search.
• Layered design: CLI → Engine → Storage → Server → Client.
• Caching pattern: File-based invalidation.
• Microservice-style boundary between crawler tool and search server (communicates via filesystem + caching).
d. Key technologies & libraries
• Python packages: typer, crawl4ai, beautifulsoup4, sentence-transformers, torch, fastmcp.
• Dependency manager: uv & pyproject.toml.
• Protocol: Model Context Protocol (MCP) over stdio.