Skip to content

Result schema, IDs and retries for Shamela MCP tools

What each Shamela MCP tool returns, how book and page IDs work, whether results are safe to retry, and how to validate structured JSON output.

On this page

Every Shamela MCP tool returns a machine-readable tool result: a structuredContent object that its published JSON schema (outputSchema) describes, plus the same JSON as text. This page lists the fields each tool returns, explains the book and page IDs in a result, and says what a client can rely on when it retries a call. The server publishes no stability promise for IDs; what follows was observed on 2026-12-02.

The server serves classical Arabic books from the Shamela library with a citation to the printed volume and page where the book has one. It also looks up Quran verses in Arabic (Hafs from Asim) and the tafsir on a verse (shamela_lookup_quran, shamela_lookup_tafsir). It does not serve Quran translations, grade hadith or give rulings.

Search matches the words of the query and ignores diacritics and common spelling variants; root expansion is an option. It is not semantic or vector search.

What a tool result contains

Every tool call returns an MCP result with three parts:

PartTypeMeaning
structuredContentobjectThe machine-readable result. Its shape is the tool’s outputSchema.
contentarrayThe same result as JSON text, and sometimes a short readable summary.
isErrorbooleantrue for a tool error such as an invalid scope or a query with no Arabic words; omitted on success.

All 15 tools publish an outputSchema in tools/list. The same listing marks every tool readOnlyHint: true, idempotentHint: true and destructiveHint: false; the retry section uses those annotations.

The tables below name the top-level fields of structuredContent and, where the schema names them, the fields of one item in the main array. A tool may add a field for one mode only; the schema marks it with that mode. An array whose items are an open object is not expanded here: read its fields from the response description in tools/list or from the JSON itself.

Search tools

shamela_search_library

FieldTypeMeaning
passagesarrayPassages, best evidence first; empty when nothing in the scope matched.
relaxedToTokensbooleantrue when a looser word search answered instead of the exact phrase.
scopestringThe scope searched, as sent.
booksSearchedinteger or nullBooks in that scope, or null when the library did not say.
totalMatchesinteger or nullMatching pages before the limit, or null on the fallback pass.
notestringA caveat when the result needs one; carry it with the passages.

Each item in passages:

FieldTypeMeaning
bookstringTitle including the printing.
authorstringAuthor name.
authorDiedinteger or nullHijri death year, or null.
bookIdintegerShamela’s book id.
printedPagestring or nullVolume and page as that printing paginates it, or null.
pageIdintegerShamela’s page id.
arabicstringThe passage, verbatim, markup removed; at most 1,600 characters.
matchedInstringbody, footnote, both or unknown.
matchQualitystringHow the library matched, for example exact_phrase.
editionstringThe printing’s label; omitted when the library records none.
editorstringThe editor; omitted when the library records none.
publisherstringThe publisher; omitted when the library records none.
sourceUrlstringThe same page in the Quran Gallery Maktabah reader.

search returns one field, results: up to 10 pages, empty when no page carries the words. Each item has id (string, the bookId:pageId form), title (string, book, author and volume/page) and url (string, the Maktabah reader page).

FieldTypeMeaning
total_hitsnumberEvery match in scope, not just the rows returned.
returnednumberRows in results on this call.
offsetnumberOffset this page started at.
has_morebooleanTrue when another page exists.
next_offsetnumberOffset of the next page; absent on the last page.
querystringThe query as received.
normalized_tokensarrayThe query after Arabic folding, as searched.
scope_countnumberBooks in the resolved scope; -1 when unscoped.
deadline_hitbooleanTrue when a time limit stopped the call; its zero is not a finding.
resultsarrayMatching pages; the schema for this build does not name their fields.
truncatedbooleanTrue when rows were dropped.
notesarrayCaveats about how the call was answered.

The schema also names mode-specific fields such as paging_ceiling, zero_hit_terms, respelled_terms, coverage, probes and edition_groups; they are absent when they do not apply.

shamela_find

FieldTypeMeaning
statusstring or nullexact, ambiguous or not_found for a work lookup.
matchobjectThe single catalogue entry when status is exact.
candidatesarrayEntries carrying the requested title.
available_editionsarrayPrintings that exist when the requested edition does not.
reasonstring or nullno_title_match, author_mismatch or edition_not_found.
resultsarrayBook, heading or author rows, depending on kind.
total_hitsnumberEvery match in scope.
notesarrayGuidance on reading the result.

The candidates, available_editions and same_author_books items name book_id, book_name, work, edition, author_id, author_name, work_group_id, book_date, citable and downloaded.

shamela_survey_topic

FieldTypeMeaning
total_hitsintegerExact number of matching pages.
total_countedintegerHits folded into the distribution.
books_matchedintegerBooks with at least one match.
by_categoryarrayname and count, top 15 categories.
by_bookarraybook_id, book_name, author_name and count, top 15 books.
accuracy_notestringThe accuracy caveat for a morphological count.

shamela_read

FieldTypeMeaning
book_idinteger or nullCatalogue book id.
book_namestring or nullCatalogue title.
page_idinteger or nullPage id that was read.
printed_pagestring or nullPrinted page label as Shamela renders it.
partstring or nullVolume label, or null for a single-volume book.
bodystring or nullThe main text (matn), or one part of it.
footstring or nullFootnotes, the editor’s words.
commentstring or nullThe user annotation stored with the page; usually empty.
body_partnumber or nullWhich part of the body this is.
body_total_partsnumber or nullHow many parts the body has.
body_has_moreboolean or nullTrue when another body part follows.
prev_page_idnumber or nullPrevious existing page id, because ids have gaps.
next_page_idnumber or nullNext existing page id.
containing_titlesarraytitle_id, title_text and page_id for each enclosing heading.
pagesarrayFor a range or section: page_id, printed_page, part, body, foot and comment.

Citation and verification

shamela_verify_quote

FieldTypeMeaning
verdictstringfound or not_found; not_found applies to the searched scope only.
matchesarrayUp to the limit, best first; empty when not_found.
searchedobjectThe scope, book id or whole-library flag that was searched.
elsewherearrayUp to three pages in other books with the same words, after a not_found.
closestobjectAfter a not_found, the page sharing most of the quoted words; never a match.
notestringCaveats to carry with the verdict.

Each item in matches names docId (bookId:pageId), bookId, pageId, book, author, volume, printedPage, edition, matchedIn, exact, differences, snippet and sourceUrl.

shamela_cite

FieldTypeMeaning
formattedstring or nullThe citation in the requested style.
stylestring or nullshamela, short, full, bibtex or ris.
page_resolvedboolean or nullTrue when the page and printed number were found.
componentsobjectThe parts the citation was built from, including auto_numbered.
notesarrayMissing citation fields and fallbacks; never fill them in.
statusstring or nullok, book_not_downloaded, no_printed_pagination, part_not_found or page_not_in_part.
book_idinteger or nullBook id for a printed-page lookup.
page_idsarrayEvery page id carrying the printed page, in reading order.
matchesarraypage_id, part, page and printed_page per page id.

Hadith and narrators

shamela_lookup_hadith

FieldTypeMeaning
querystringThe query as received.
total_text_matchesnumberEvery page matching the text in the searched shelves.
books_searchednumberBooks the text search covered.
searchedstringhadith_shelves or whole_library.
matchesarrayMatching pages, key-bearing first.
takhrijarrayPer hadith key: hadith_key, index_entries and books.
resultsarrayFor a sources lookup: book_id, book_name, author_name, page_id and downloaded.

shamela_lookup_rijal

FieldTypeMeaning
querystringThe name searched.
total_matchesintegerNarrators matching, before paging.
returnedintegerRows in this response.
resultsarrayNarrators or chains, depending on the mode.
narrator_idintegerNarrator id for one narrator.
namestringShort name.
full_namestringFull name.
death_yearnumber or nullHijri death year.
grade_ibn_hajarstring or nullThe grading attributed to Ibn Hajar, when the register has one.
grade_dhahabistring or nullThe grading attributed to al-Dhahabi, when the register has one.
tabaqastring or nullGeneration, per Taqrib al-Tahdhib.
jarh_tadilarrayCritics’ verdicts, grouped by critic, each with book and page.
notestring or nullA note on the narrator record.

Quran and tafsir

shamela_lookup_quran

FieldTypeMeaning
total_hitsnumberEvery match in scope.
returnednumberRows in this response.
querystringThe query as received.
resultsarrayVerses in mushaf order; the schema for this build does not name their fields.
aya_idintegerCumulative verse id, 1 to 6236, for an aya lookup.
surahintegerSurah number, 1 to 114.
surah_namestringArabic surah name.
ayaintegerVerse number within the surah.
bodystringThe verse in standard Egyptian spelling, Hafs from Asim.
versesarrayaya_id, surah, surah_name, aya, body, amiri and majma.

shamela_lookup_tafsir

FieldTypeMeaning
aya_idintegerVerse id, 1 to 6236.
surahintegerSurah number.
ayaintegerVerse number within the surah.
totalsobjectCount of books in each coverage status.
booksarrayOne row per tafsir book, with the coverage status.
sourcesarrayThe commentary texts read for a texts lookup.
remaining_book_idsarrayIndexed sources not read in this call.

Each item in books names book_id, book_name, author_name, downloaded, status, page_id and printed_page. Each item in sources names book_id, book_name, status, page_id, printed_page, text, foot, text_has_more and note.

Catalogue and server brief

shamela_get_details

FieldTypeMeaning
book_idinteger or nullCatalogue book id.
book_namestring or nullCatalogue title.
categorystring or nullCategory name.
book_type_labelstring or nullBook type in Arabic, such as printed or manuscript.
book_datenumber or nullShamela’s Hijri book date, usually the author’s death year.
printednumber or null1 when page numbers follow a printed edition.
downloadedboolean or nullTrue when the text is installed on this server.
content_statusstring or nullreadable, downloaded_no_pages or not_downloaded.
authorsarrayauthor_id, author_name, death_year and role.
editionstring or nullEdition from the front matter; never invented.
editorstring or nullEditor from the front matter.
publisherstring or nullPublisher from the front matter.
same_grouparrayOther entries of the same work: book_id, book_name, downloaded and printed.
author_idinteger or nullAuthor id for an author lookup.
author_namestring or nullAuthor name for an author lookup.
booksarrayThe author’s books: book_id, book_name, book_date and downloaded.

shamela_get_brief

FieldTypeMeaning
server_versionstringThis build’s version.
capabilitiesarrayArguments and response fields this build supports.
brief_hashstringDigest of the other fields; re-fetch only when it changes.
limitsobjectNumeric server limits by name.
tool_aliasesobjectRetired tool names mapped to their replacement.
trapsarrayid, tools, risk, detect and act for each known trap.

Identifiers

A result uses three identifier forms:

FormWhere it appearsMeaning
bookId or book_idPage, passage and catalogue resultsShamela’s catalogue id for one printing.
pageId or page_idPage and passage resultsShamela’s id for one page record.
bookId:pageIdsearch results, shamela_verify_quote docIdThe same pair in one string, ready for fetch.

A live shamela_search_library result on 2026-12-02 carried this entry:

{
	"book": "صحيح البخاري - ط السلطانية",
	"bookId": 1681,
	"pageId": 10,
	"printedPage": "1/ 6",
	"sourceUrl": "https://qurangallery.com/maktabah/book/1681/00#p10"
}

The pair 1681:10 addresses that page for fetch; shamela_read takes book_id: 1681 and page_id: 10 separately. The printedPage value is the printing’s own label, while pageId is Shamela’s internal record. Where a book has no printed pagination, printedPage is null and the page id is Shamela’s own auto-numbered address, not a printing’s page; Edition, editor and publisher explains how to read and cite that difference.

The IDs are identifiers of convenience, not a contract. As observed on 2026-12-02, a book id and page id stayed the same across calls. No stability guarantee is published; keep in mind an id may change without notice. Keep the printed citation next to the id, so a reader can still find the page if the number changes. shamela_get_brief returns a brief_hash; check it when you need to know whether the server’s capabilities changed.

Safe to retry

Every tool in the live list is annotated readOnlyHint: true and idempotentHint: true, with destructiveHint: false. A retry cannot write anything, and repeating the same call returns the same result unless the catalogue changed between calls. That makes a retry after a network failure safe; it does not make a different query return the first query’s answer.

A refused call spends nothing. If the per-minute limit refuses a call, the daily count is untouched (Rate limits and error codes).

A rate-limit refusal is HTTP 429 with a JSON-RPC error whose code is -32004 and whose id is null. The retry-after header gives the number of seconds to wait. For the keyless per-minute limit the message names the limit and suggests a free key:

Keyless limit reached: 10 tool calls a minute per IP. A free API key raises it to 60 a minute: …

Wait for retry-after, then retry once. If the call still fails, stop and report the limit rather than sending a loop.

A tool error arrives as a normal result with isError: true; retrying it unchanged fails the same way. Fix the argument first, for example by sending a valid scope.

No timeout value for a whole tool call is published. In the code, each request to the library server has a 15-second internal limit (apps/mcp/src/lib/server/shamela/client.ts:13), but one tool call can make several such requests. Set your own client-side timeout and treat an expired call as retryable.

Validate a result

The outputSchema in tools/list is a JSON Schema, so the jsonschema package can check a saved structuredContent against it (pip install jsonschema, preferably in a virtual environment):

import json
from jsonschema import Draft202012Validator

schema = json.load(open("schema.json"))  # the tool's outputSchema from tools/list
result = json.load(open("result.json"))  # a saved structuredContent

errors = list(Draft202012Validator(schema).iter_errors(result))
print("valid" if not errors else f"{len(errors)} errors")
for error in errors:
    print(error.message)

Run against the saved shamela_search_library reply from 2026-12-02 with that tool’s outputSchema, it printed:

valid

The schemas in this build publish no required list, so validation checks types and structure, not that a field is present.

Next steps

Questions

What fields does a search result have?

`search` returns `results` of `id`, `title` and `url`; `shamela_search_library` returns `passages` with book, author, printed page, edition and source URL. The tables above list the rest.

Are the IDs stable?

No stability guarantee is published. As observed on 2026-12-02 the same book and page kept the same IDs across calls; keep the printed citation with the ID in case an ID changes.

Is it safe to retry a call?

Yes. Every tool is read-only and idempotent, and a refused call spends nothing. After a 429, wait for the `retry-after` header before calling again.

Is there a `comment` field in the result?

Not in search or citation results. `shamela_read` names `comment` for the user annotation stored with a page, which is usually empty.

Where is the result schema?

Each tool publishes an `outputSchema` in `tools/list`; the client already receives it. `shamela_get_brief` returns a hash of the server capabilities so a client can tell when they change.

Edit this page on GitHub