Model Context Protocol (MCP) server and data pipeline for IslamQA.info fatwas (~32k answers, English + Arabic). Fetch and cite from a real corpus instead of quoting from model memory—same grounding mindset as hadith-mcp and quran-mcp.
- Content is scraped from IslamQA.info (English and Arabic pages). This project is not affiliated with IslamQA; respect their terms of use and scholarly context when citing answers.
- Architecture follows patterns from hadith-mcp (FastMCP, SQLite + embeddings, static search UI, deploy units).
| Path | Purpose |
|---|---|
scripts/scrape_islamqa.py |
Discover IDs from sitemaps; incremental scrape → data/answers.json |
scripts/embed_islamqa.py |
OpenAI text-embedding-3-large → data/embeddings.db (incremental, batched) |
scripts/build_db.py |
Merge answers.json + embeddings.db → data/islamqa.db |
scripts/fetch_ext_apps.py |
Vendor MCP ext-apps SDK for show_answer interactive UI |
src/islamqa_mcp/server.py |
FastMCP tools + REST (/api/search, /api/answer/{id}, …) |
src/islamqa_mcp/assets/ |
MCP App HTML + bundled SDK for show_answer |
search/ |
Static search frontend |
site/ |
Landing / setup page |
deploy/ |
systemd + nginx examples |
data/ |
Gitignored — see data/README.md |
uv sync
cp .env.example .env # OPENAI_API_KEY required for embed + semantic searchuv run python scripts/scrape_islamqa.py scrapeDefault is one text per API call (slow). For a full corpus on a capable OpenAI tier, use batching:
# Full run (example: Tier 5 with high TPM/RPM)
uv run python scripts/embed_islamqa.py run --batch-size 48 --sleep 0 --commit-every 50
# Incremental / cautious
uv run python scripts/embed_islamqa.py run --batch-size 1 --sleep 0.12
uv run python scripts/embed_islamqa.py statsuv run python scripts/build_db.py
# Optional: --fresh to delete existing islamqa.db firstuv run islamqa-mcp --config config.yml --transport streamable-httpPoint ISLAMQA_MCP_DB_PATH at your islamqa.db if it is not under ./data/.
fetch_grounding_rules— citation rules (call before citing)search_answers— semantic (default) or keyword searchfetch_answer— by IslamQA answer IDlist_categories— topic listshow_answer— interactive reader (MCP App) + text fallback
GET /api/search?q=&limit=&category=GET /api/answer/{id}GET /api/categoriesGET /api/stats
search/— static search app (e.g.search.islamqa-mcp.org)site/— landing page (e.g.islamqa-mcp.org)
Step-by-step Ubuntu 22.04 setup: deploy/DEPLOY.md (uv, systemd MCP + scrape timer, nginx, certbot).
After scrape → embed → build_db.py, restart islamqa-mcp (the scrape timer does this automatically).
| Variable | Purpose |
|---|---|
OPENAI_API_KEY |
Document embeddings + query vectors for search |
ISLAMQA_MCP_DB_PATH |
Override DB path (default ./data/islamqa.db) |
ISLAMQA_SEARCH_APP_URL |
Citation base URL (default https://search.islamqa-mcp.org) |
GPL-3.0-only — see LICENSE.