Labsco
ovehbe logo

hadith-mcp

β˜… 1

from ovehbe

Model Context Protocol server for searchable, citation-safe hadith text.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedPaid serviceNeeds API keys

hadith-mcp

Model Context Protocol (MCP) server and data pipeline for serving canonical hadith text (Arabic and English) to assistants in a citation-safe wayβ€”similar in spirit to quran-mcp: fetch from a real corpus instead of quoting from model memory.

This repository provides a FastMCP server over data/hadith.db plus a data pipeline to build that database: normalized SQLite, OpenAI embeddings (text-embedding-3-large), cross-collection references (cosine similarity + narrator-aware scoring), and provenance-style tags (e.g. muttafaq-style links between Sahih al-Bukhari and Sahih Muslim).

Data sources and credits

  • Hadith text comes from the community hadith-json dataset (scraped from Sunnah.com), which aligns with the broader sunnah-com / Quran Foundation ecosystemβ€”the same family of sources behind quran-mcp.
  • Architecture and patterns are inspired by quran-mcp (FastMCP, grounding mindset, tooling layout).

If you ship a product or paper, keep upstream attribution visible (dataset authors, Sunnah.com, and the scholarly collections themselves).

Repository layout

PathPurpose
scripts/build_db.pyLoad hadith-json db/by_book JSON β†’ SQLite schema, optional embed, cross-ref, provenance
scripts/embed_hadith.pyResume-only embedding for rows with embedding IS NULL (slow, checkpoint-friendly)
scripts/merge_embedding_checkpoints.pyReplay JSONL embedding checkpoints into hadith.db after crashes or restores
scripts/compute_crossref.pyRecompute cross_references + provenance only (does not re-import JSON; safe after embed)
scripts/fetch_ext_apps.pyVendor / refresh @modelcontextprotocol/ext-apps as a classic script (sets window.__hadithMcpSdk) used by the interactive reader
scripts/generate_search_sitemap.pyRegenerate search/sitemap.xml (index) + search/sitemaps/*.xml (~50k ?id= URLs) from data/hadith.db for SEO after DB changes
src/hadith_mcp/pipeline/Loaders, schema, embed, cross-reference, provenance logic
src/hadith_mcp/server.pyFastMCP app: MCP tools + a small REST surface (/api/collections, /api/hadith/{id}, /api/hadith/{slug}/{n}, /api/search) reusing the same store and embedding index
src/hadith_mcp/assets/hadith_app.htmlSelf-contained MCP App UI template (inline CSS + app logic, system fonts only) served at ui://hadith.html for the show_hadith tool
src/hadith_mcp/assets/ext-apps.bundle.jsVendored ext-apps SDK (zero external imports) inlined into hadith_app.html at resource-render time
search/Static search frontend (HTML/CSS/JS) deployed standalone (e.g. search.hadith-mcp.org)
site/Static landing page for the main domain
config.ymlOptional default DB path (overridden by HADITH_MCP_DB_PATH)

Large reference trees hadith-json-main/ and quran-mcp-master/ are listed in .gitignore. Clone or unpack hadith-json locally (for example as hadith-json-main/) or pass --data-dir to build_db.py.