# MCP for developers: Check your own OCR or TEI text against a printed edition

Source: https://qurangallery.com/docs/mcp/check-your-own-ocr-or-tei-text

> An OCR or TEI text of a classical book: check its passages against a printed edition with shamela_verify_quote. What the check can and cannot do.

If you have an OCR or TEI text of a classical book, you can check passages from it against a printed edition with `shamela_verify_quote`. The tool does not read your file, and it is not an OCR engine. It checks whether a passage's words are printed on a page of a book in the Shamela library, and where.

## What the check can and cannot do

- **It covers the Shamela library only.** A printed edition the library does not hold cannot be checked against.
- **It does not read your file.** You send it one passage at a time, as text.
- **It is not an OCR engine.** It does not read scanned images or correct recognition errors.
- **Not found is about the scope.** It means no page in the searched scope carries those words in that order. It never means the passage is false.
- **It is not a ruling.** A found passage shows where the words are printed. It does not show that the passage is authentic or soundly attributed.

## Check 20 passages

1. Choose 20 passages from your text, each with at least three Arabic words, and save them in `passages.txt`, one per line.
2. Find the edition's `bookId` with `shamela_find`. If it finds no match, that is not proof the library lacks the book.
3. Run the script below. It calls `shamela_verify_quote` once per passage and waits between calls.
4. Read each result: `verdict`, then `exact`, `matchedIn`, `volume`, `printedPage` and `sourceUrl`. The `sourceUrl` opens the page in the Maktabah reader.

## The script

The keyless limit is 10 calls a minute and 200 a day per IP address, so the script waits 7 seconds between calls. Twenty passages take about 140 seconds. For more passages, use a free key: see [MCP API key and bearer token setup](https://qurangallery.com/docs/mcp/bearer-token-setup).

```python
import json
import time
import urllib.request

URL = "https://qurangallery.com/mcp/shamela"
HEADERS = {"Content-Type": "application/json", "Accept": "application/json"}
BOOK_ID = 1681  # replace with your edition's bookId from shamela_find
passages = [line.strip() for line in open("passages.txt", encoding="utf-8") if line.strip()]

for n, quote in enumerate(passages, start=1):
    args = {"quote": quote, "bookId": BOOK_ID, "limit": 1}
    body = {"jsonrpc": "2.0", "id": n, "method": "tools/call", "params": {"name": "shamela_verify_quote", "arguments": args}}
    req = urllib.request.Request(URL, json.dumps(body).encode("utf-8"), HEADERS)
    with urllib.request.urlopen(req, timeout=40) as resp:
        reply = json.load(resp)["result"]
    data = reply.get("structuredContent") or json.loads(reply["content"][0]["text"])
    m = (data["matches"] or [{}])[0]
    print(n, data["verdict"], m.get("exact"), m.get("matchedIn"), m.get("volume"), m.get("printedPage"))
    time.sleep(7)  # keyless limit: 10 calls a minute
```

A tool error, such as a passage under three Arabic words or a bad `bookId`, names the fix; the script stops on it, so correct the passage and run again. If the server refuses calls for rate limits, wait a minute and run the script again.

## What a reply looks like

Two passages from a test run, printed by the script above. The first was typed with diacritics; the second was typed without them.

```text
1 found True body 1 6
2 found False body 1 6
```

Both are found on printed page 6 of volume 1 in book 1681 (`صحيح البخاري - ط السلطانية`). The second has `exact` set to `false`, because the page carries 30 more diacritic marks than the typed passage and its punctuation differs; the `differences` field says so. Found with `exact` false means the same words in another spelling, not a miss. Your OCR text may come out `exact: false` for the same reasons, so read `differences` before you decide.

## When a passage is not found

This reply is for a passage searched in the `hadith-primary` scope, which holds no page with those words in that order. The `normalisation` list is shortened here.

```json
{
	"verdict": "not_found",
	"matches": [],
	"searched": { "scope": "hadith-primary", "normalisation": ["…"] },
	"note": "Not found in the searched scope: the \"hadith-primary\" scope (The eight primary hadith collections, edition-pinned). This says only that no page there carries these words in this order; it does not mean the quotation is false, and it may be in a book, edition or wording outside that scope. Try another scope or a bookId, or a shorter distinctive part of the wording. This is not a ruling on the quotation."
}
```

For your own text, widen the scope, give a `bookId`, or search a shorter part of the passage that has no OCR error in it. A not-found result is a statement about the scope that was searched, not about your text.

## Formats and sources people ask about

We do not integrate with any of these projects, and the server does not read their files. Each row gives one fact from the project's own page, with the date we read it, and what our server does for someone who uses that tool.

| Format or project | What its own page says | Source, read 2 December 2026 | What our server does |
| --- | --- | --- | --- |
| OpenITI | "a multi-institutional effort to construct the first machine-actionable scholarly corpus of premodern Islamicate texts", published as versioned releases on GitHub and Zenodo | [openiti.org](https://openiti.org/); [release README](https://raw.githubusercontent.com/OpenITI/RELEASE/master/README.md) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| TEI/XML | "an international and interdisciplinary standard used by libraries, museums, publishers, and academics to represent all kinds of literary and linguistic texts" | [TEI on GitHub](https://github.com/TEIC/TEI) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| Kraken | "a turn-key OCR system optimized for historical and non-Latin script material" | [kraken on GitHub](https://github.com/mittagessen/kraken) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| eScriptorium | "A Digital Text Production Pipeline for Print and Handwritten Texts using machine learning techniques" | [eScriptorium](https://escriptorium.inria.fr/) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| Transkribus | describes itself as "the operating system for written heritage", built and owned by a community of stakeholders | [transkribus.org](https://www.transkribus.org/) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| PyMuPDF | "a layout-aware document engine for AI and a feature-rich Python toolkit for extracting, rendering and editing PDFs and other documents" | [PyMuPDF documentation](https://pymupdf.readthedocs.io/en/latest/) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| CAMeL Tools | "A suite of Arabic natural language processing tools developed by the CAMeL Lab at New York University Abu Dhabi" | [CAMeL Tools on GitHub](https://github.com/CAMeL-Lab/camel_tools) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |
| Hugging Face vectors | "The Hugging Face Hub hosts Git-based repositories, which are version-controlled folders that can contain all your files." | [Hub documentation](https://huggingface.co/docs/hub/index) | Nothing with the file itself; check a passage with `shamela_verify_quote`. |

## Next steps

- [Verify an AI-quoted passage against the printed page](https://qurangallery.com/docs/mcp/verify-a-quotation)
- [Hosted MCP server or your own RAG or OpenITI corpus?](https://qurangallery.com/docs/mcp/vs-own-rag-and-openiti)
- [MCP API key and bearer token setup](https://qurangallery.com/docs/mcp/bearer-token-setup)
- [Limits and errors](https://qurangallery.com/docs/mcp/limits-and-errors)
