fetch_grounding_rulesLABSCO SUMMARY
The forgiving name matcher is what makes it usable in conversation.
People do not type canonical slugs. Accepting bukhari, sahih-bukhari, Sahih al-Bukhari and sahih_bukhari as the same collection is the difference between a citation tool that works mid-sentence and one that returns errors until you look up its identifiers. The other well-judged decision is the fallback: when the embedding provider refuses, search degrades to keyword rather than failing, so a quota problem does not become a blank answer. Building the database first is the real cost of entry.
What it is
An MCP server over a local SQLite database of hadith text in Arabic and English, plus the pipeline that builds it from the community hadith-json dataset. The design goal is citation safety: the assistant retrieves from a real corpus and cites it, rather than reconstructing a narration from training data.
What you get
- The grounding rules returned once per session, so the assistant knows how it is expected to quote before it starts —
fetch_grounding_rules - A hadith fetched by global id, or by collection plus number — including a string range like
1-5— with cross references optionally attached; the collection argument accepts canonical slugs, common variants and human names alike —fetch_hadith - Search that defaults to semantic, with
mode=keywordfor SQL substring matching ormode=both; if the embedding provider returns a quota, billing or rate-limit error, it falls back to keyword search rather than failing —search_hadith - Algorithmic similarity matches for a hadith across collections, built from cosine similarity with narrator-aware scoring —
fetch_cross_references - An interactive reader rendered in hosts that support MCP apps, always returning a plain-text fallback with the same citation URLs so other hosts still get a readable answer —
show_hadith - A small REST surface over the same store for non-MCP use —
/api/collections,/api/hadith/{id},/api/search - Optional per-client rate limits and an LRU query cache to hold down cost
Requirements
The database has to be built before the server is useful: clone the hadith-json dataset locally and run the build script against its db/by_book directory. Semantic search additionally needs OPENAI_API_KEY and a database whose rows carry embeddings — the embedding pass is a long, checkpointed run and can be done on a separate machine, with checkpoints replayed afterwards. Keyword search works without either. Install with a virtualenv and pip install -e ".[dev]"; then hadith-mcp --transport stdio for desktop clients or --transport http. HADITH_MCP_DB_PATH overrides the database location and takes precedence over the config file. The pyproject name is hadith-mcp (0.1.0). Upstream attribution to the dataset authors and Sunnah.com is expected if you ship something on top of it.
Setup effort
Build from source — clone the repository, then follow the project's own run instructions
USE CASES
Quoting a narration correctly
Fetch by collection and number and get the actual text with a citation URL, rather than a reconstruction from memory.
Finding narrations on a theme
Search semantically across the corpus, or switch to keyword mode when you want exact wording.
Seeing where else a narration appears
Ask for cross-collection matches for one hadith to find its parallels in other collections.
Reading a result properly in a supporting client
Open the interactive reader with the canonical id from a lookup; hosts without app support still get the readable text and the same links.
5 tools
Listed in project docs. Your client may show a different list.
fetch_hadithsearch_hadithfetch_cross_referencesshow_hadithBEFORE YOU INSTALL
What to know first
Tools you get
5 tools named in the project's documentation. search_hadith uses semantic search, which needs OPENAI_API_KEY and a database with embeddings; without them it silently falls back to keyword search.
Optional
OPENAI_API_KEY in your environment
INSTALLATION
Connect your client
Clone the repository, then follow the project's own run instructions. This one is built from source rather than installed with a single command.
Server setup
git clone https://github.com/ovehbe/hadith-mcp.git
cd hadith-mcp
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env # set OPENAI_API_KEY for embedding stepsClone or unpack hadith-json locally (e.g. as hadith-json-main/) for the database build
python scripts/build_db.py --fresh --skip-embed --skip-cross --skip-provenance --data-dir ./hadith-json-main/db/by_book
python scripts/embed_hadith.py --db-path ./data/hadith.db --checkpoint ./data/embeddings_checkpoint.jsonl --batch-size 1 --commit-every 10 --sleep-between-batches 0.15
python scripts/compute_crossref.py --db-path ./data/hadith.db
hadith-mcp --transport stdioOr: python -m hadith_mcp --transport stdio / fastmcp run hadith_mcp.server:mcp.
The README gives no client configuration. Add a stdio server to your client whose command is hadith-mcp --transport stdio, run from the repository root (or set HADITH_MCP_DB_PATH to data/hadith.db). OPENAI_API_KEY is optional: set it in .env for semantic search; without it, search uses keywords.