# MCP for developers: Hadith takhrij with MCP: find a hadith across collections

Source: https://qurangallery.com/docs/mcp/hadith-takhrij

> Locate a hadith in the primary collections with its isnad and printed page using the Quran Gallery MCP tools and the takhrij_hadith prompt. No grading.

_Takhrīj_ (تخريج الحديث) here means locating where a hadith is recorded, with its chains of transmission (_isnād_, إسناد) and the exact printed pages. It does **not** mean grading it. The server never calls a hadith ṣaḥīḥ, ḥasan or ḍaʿīf, and gives no rulings; see [Grounding rules](https://qurangallery.com/docs/mcp/grounding-rules).

## The ready-made prompt

Your client lists a prompt called `takhrij_hadith`, with one argument, `text`: the wording of the hadith. In clients that show MCP prompts, pick it and paste the wording. The prompt tells the model to find the hadith across the collections, report each isnād, and answer in your language without grading. Without prompt support, use the steps below.

## Steps by hand

1. **Search the primary collections.** Call `shamela_search_library` with the Arabic wording and `scope: "hadith-primary"` ([scopes](https://qurangallery.com/docs/mcp/scopes)). Read `matchedIn` and `relaxedToTokens`: only `body` with an exact phrase shows that the wording is printed there ([Reading a result](https://qurangallery.com/docs/mcp/reading-results)).
2. **Find every collection that records it.** Use `shamela_lookup_hadith` (`mode: 'search'`) with the wording to list the collections carrying it, and `shamela_lookup_hadith` (`mode: 'sources'`) with the hadith's shared key to list the books that record the same hadith.
3. **Read the chains.** `shamela_lookup_rijal` (`mode: 'isnad'`) returns the chain or chains printed on one page, with narrator names resolved. `shamela_lookup_rijal` (`mode: 'isnad_search'`) searches the indexed chains across ten hadith books.
4. **Identify the narrators.** `shamela_lookup_rijal` (`mode: 'narrators'`) finds a narrator by name and `shamela_lookup_rijal` (`mode: 'narrator'`) returns the dossier (lineage, death year, ṭabaqa). Where a dossier quotes critics' gradings, they are the critics' words, and are to be reported as quoted.
5. **Open the page.** `shamela_read` (`unit: 'page'`) returns the full page with the footnotes, and the passage's `sourceUrl` links to it in the Maktabah reader.
6. **Cite each collection** as in [Grounding rules](https://qurangallery.com/docs/mcp/grounding-rules): book, edition, volume and page, main text or footnote.

## What a good answer contains

- Each collection and page where the hadith is printed, with its isnād as printed.
- Wording differences between collections, quoted exactly.
- Which hits are in the author's text and which are in an editor's footnote.
- A statement of what was searched, so a miss is read as a miss in that scope only.

It does not contain a verdict on authenticity. For that, consult a qualified scholar and the books themselves.

## Example

Ask your assistant: _Use takhrij_hadith for «إنما الأعمال بالنيات»._ In the primary collections the search finds, among others, Ṣaḥīḥ al-Bukhārī (ط السلطانية, 1/6), and a footnote in Sunan Abī Dāwūd (3/526) that quotes al-Khaṭṭābī's commentary on it. The first is the author's text; the second is not Abu Dawud's own wording.

## Next steps

- [Open Quran Gallery MCP](https://qurangallery.com/mcp)
- [Search the main text or the footnotes of a Shamela book](https://qurangallery.com/docs/mcp/search-main-text-or-footnotes)
- [How Arabic search behaves in Shamela MCP](https://qurangallery.com/docs/mcp/arabic-search-behaviour)
- [MCP server for Islamic texts: what it does](https://qurangallery.com/docs/mcp/overview)
