🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

alfanous3-mcp

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alfanous3-mcp

An MCP (Model Context Protocol) server that exposes the Alfanous Quranic search engine as tools and resources for AI assistants.

pipPyPI
Version
1.9.4
Weekly downloads
91
21.33%
Maintainers
1
Weekly downloads
 
Created

Alfanous MCP Server

An MCP (Model Context Protocol) server that exposes the Alfanous Quranic search engine as a set of tools and resources for AI assistants, enabling them to search, explore, and retrieve information from the Holy Qur'an.

Features

  • Search Quranic verses with full support for Arabic text, Buckwalter transliteration, boolean operators, phrase search, wildcards, fuzzy matching, field filters, and facets.
  • Search translations across many languages (English, French, Urdu, and more).
  • Retrieve metadata – chapter names, available translations, recitations, search field descriptions, and API defaults.
  • Query auto-completion – get suggestions while typing a search query.
  • AI query-translation guide as an MCP resource (quran://ai-rules) that helps AI assistants convert natural-language questions into Alfanous query syntax.

Installation

Prerequisites

  • Install the Alfanous core library and build the indexes:

    pip install alfanous3 pystemmer
    # or from source:
    pip install pyparsing whoosh pystemmer
    cd /path/to/alfanous && make build
    
  • Install the MCP Python SDK:

    pip install mcp
    

Running the Server

stdio transport (default – works with Claude Desktop and most MCP clients)

python -m alfanous_mcp.mcp_server

Streamable-HTTP transport (for testing/development)

python -m alfanous_mcp.mcp_server --transport streamable-http

Configuring Claude Desktop

Add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "alfanous": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "alfanous_mcp.mcp_server"],
      "tools": [
        "search_quran",
        "search_translations",
        "get_quran_info",
        "search_quran_by_themes",
        "search_quran_by_stats",
        "search_quran_by_position",
        "suggest_query",
        "correct_query",
        "search_by_word_linguistics"
      ]
    }
  }
}

Tools

search_quran

Search for verses in the Holy Qur'an.

ParameterTypeDefaultDescription
querystring(required)Arabic text or Buckwalter transliteration
unitstring"aya""aya", "word", or "translation"
pageint1Page number
perpageint10Results per page (1–100)
sortedbystring"relevance""relevance", "score", "mushaf", "tanzil", "ayalength"
fuzzyboolfalseEnable fuzzy search (see Fuzzy Search)
fuzzy_maxdistint1Levenshtein edit distance — 1, 2, or 3 (only used when fuzzy=true)
derivation_levelint/str0Morphological breadth — 0/"word" (exact), 1/"stem", 2/"lemma", 3/"root" (see Derivation-Level Search)
viewstring"normal""minimal", "normal", "full", "statistic", "linguistic"
highlightstring"bold""bold", "css", "html", "bbcode"
translationstringnullTranslation identifier to include alongside each verse
facetsstringnullComma-separated facet fields
field_filterstringnullField filter expression (e.g. "sura_number:2")

search_translations

Search within Quranic translation texts (English, French, Urdu, etc.).

ParameterTypeDefaultDescription
querystring(required)Query in any language
translationstringnullTranslation ID (e.g. "en.pickthall"); omit to search all
pageint1Page number
perpageint10Results per page (1–100)
sortedbystring"relevance""relevance", "score", "mushaf", "tanzil", "ayalength"
fuzzyboolfalseEnable fuzzy search (see Fuzzy Search)
fuzzy_maxdistint1Levenshtein edit distance — 1, 2, or 3 (only used when fuzzy=true)
highlightstring"bold""bold", "css", "html", "bbcode"
facetsstringnullComma-separated facet fields
field_filterstringnullField filter expression

get_quran_info

Retrieve Qur'an metadata.

category valueDescription
"chapters" / "surates"Chapter names and numbers
"translations"Available translation identifiers
"recitations"Available recitation identifiers
"defaults"Default search parameter values
"domains"Valid values for each parameter
"fields"Available search fields
"flags"All supported API flags
"help_messages"Human-readable help for parameters
"hints"Search tips and examples
"ai_query_translation_rules"Full query-syntax guide for AI
"all"Everything at once

suggest_query

Get auto-completion suggestions for a partial query.

ParameterTypeDefaultDescription
querystring(required)Partial search string
unitstring"aya""aya", "word", or "translation"

Control how broadly the search expands morphologically using the derivation_level parameter of search_quran (or unit="word").

LevelValueIndex fieldHow it works
0"word"ayaExact match only (default)
1"stem"aya_stemCorpus-derived stem — words sharing the same morphological stem
2"lemma"aya_lemmaCorpus lemma — all inflections of the same lexeme
3"root"aya_rootTrilateral root — all words from the same Arabic root
# Stem-level: رحيم → corpus stem → matches words with same stem
search_quran(query="رحيم", derivation_level=1)

# Lemma-level: all words sharing the lemma of رَحِيمٌ
search_quran(query="رحيم", derivation_level="lemma")

# Root-level: all words from root رحم
search_quran(query="رحم", derivation_level=3)

Derivation syntax can also be embedded directly in the query string:

PatternField searchedExample
>wordaya_stem>رحيم
>>wordaya_lemma>>رحيم
>>>wordaya_root>>>رحم

Word Search (unit="word")

When unit="word" the engine searches individual word child documents, each carrying full morphological annotation. The derivation_level parameter works here too:

LevelField searchedDescription
0word, normalizedExact word match
1word_stemCorpus-derived stem (QStandardAnalyzer)
2word_lemmaNormalized lemma (QStandardAnalyzer)
3rootExact root value
# Find all word-level matches for "الله"
search_quran(query="الله", unit="word")

# All words sharing the lemma of رحيم
search_quran(query="رحيم", unit="word", derivation_level=2)

# All words from root رحم
search_quran(query="رحم", unit="word", derivation_level=3)

For morphological filtering use the search_by_word_linguistics action:

# All nouns from root قول
do({"action": "search_by_word_linguistics", "root": "قول", "type": "اسم"})

# All active-voice past-tense verbs from root كتب
do({"action": "search_by_word_linguistics", "root": "كتب", "pos": "V",
    "voice": "مبني للمعلوم", "aspect": "فعل ماضي"})

When fuzzy=true the engine uses three complementary strategies simultaneously:

#StrategyFieldDescription
1Exactaya_Fully-vocalized Quranic text — precise, statistical matching
2Normalised / stemmedayaText indexed with stop-word removal, synonym expansion (index time), and Arabic stemming via Snowball / pystemmer. Handles morphological variants (كَتَبَ / كِتَاب / مَكْتُوب).
3Levenshtein distanceaya_acFinds indexed terms within fuzzy_maxdist edit operations of each query term. Handles typos and minor spelling variants.

Results from all three strategies are OR-combined, so the result set is always a superset of the exact-only results.

Choosing fuzzy_maxdist

ValueTypical use
1 (default)Single-character typos (insertion / deletion / substitution)
2Longer words or noisier input
3Maximum tolerance — recall increases significantly

Example (via an AI assistant prompt):

"Search for verses about رحمن with fuzzy matching and edit distance 1"

search_quran(query="رحمن", fuzzy=True, fuzzy_maxdist=1)

Resources

quran://ai-rules

A plain-text guide that teaches AI assistants how to translate natural-language questions about the Qur'an into Alfanous query syntax. Covers all operators, field names, Arabic-specific features (synonyms, antonyms, root derivations), and over 100 practical examples.

Query Syntax Quick Reference

PatternExampleMeaning
Arabic wordاللهVerses containing "الله"
BuckwalterAllhSame, using transliteration
ANDالله رحمةBoth words present
ORالله OR رحمنEither word
NOTالله NOT عذابFirst without second
Phrase"بسم الله"Exact phrase
Wildcardرحم*Words starting with رحم
Field filtersura_number:2Surah 2 only
Stem derivation>رحيمaya_stem (corpus-derived stem)
Lemma derivation>>رحيمaya_lemma (all inflections of same lexeme)
Root derivation>>>ملكaya_root (all words from same root)
Fuzzyfuzzy=true parameterBroad approximate match

License

LGPL v3 or later – see the root LICENSE file.

Keywords

quran search mcp model-context-protocol alfanous

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts