This tutorial uses the OCR Wizard API. See the docs, live demo, and pricing.
Your agent has to work with scans: a case file, a signed contract, a pile of receipts. Recent models can look at a page image and read it, so why add an OCR tool? We ran the test on 6 December 2026, in Claude Code, on a 62-page scanned court opinion. Both setups answered right. With the tool, questions cost about half as much and came back faster, and when the task needs to know where the words are on the page, the agent needed half the steps. This guide adds an OCR MCP server to your agent and shows each test with its numbers.
The tools are extract_text and extract_pdf_text, part of our open source AI Engine MCP server. They call the OCR Wizard API. The document is the 1890 opinion of the Supreme Court of California in Colton v. Stanford, a public domain scan. We removed its old text layer so that it is images only, like a fresh office scan.
What the Two Tools Return
extract_pdf_text(pdf_path, first_page, last_page): the text of the whole PDF in one call. The tool splits the file into 10-page parts and reads them in parallel, then saves the text next to the PDF asname.ocr.txt, with a=== page N ===line before each page. A later call on the same file reuses it. For a long document the tool returns the path of that file and the agent searches it.extract_text(image, include_words): the text of an image. Withinclude_words=True, every word comes with its box: four corner points in pixels of that image.
Two words of page 51 of the scan, as extract_text returned them (611 x 1098 pixel image):
{"text": "$", "box": [{"x": 321, "y": 137}, {"x": 330, "y": 137}, {"x": 330, "y": 155}, {"x": 321, "y": 155}]},
{"text": "175,000", "box": [{"x": 332, "y": 137}, {"x": 397, "y": 137}, {"x": 397, "y": 155}, {"x": 332, "y": 155}]}The dollar sign and the number are two words. An amount is the union of their boxes: x from 321 to 397, y from 137 to 155.
Install
Create a free RapidAPI account, subscribe to the OCR Wizard API (there is a free plan) and copy your key. In Claude Code:
claude mcp add ai-engine -e RAPIDAPI_KEY=your_key -- \
uvx --from "git+https://github.com/ai-engine-dev/api-examples#subdirectory=mcp-server" ai-engine-mcpFor Claude Desktop and Cursor, the JSON block is in the MCP server setup guide. The same server removes backgrounds, checks images for nudity and checks ID documents; each tool needs a subscription to its own API, and the others keep working without it.
Session 1: Questions on a 62-Page Scan
A folder with colton_scan.pdf (62 pages, 4 MB, no text layer). The prompt:
> colton_scan.pdf is a scanned court opinion (62 pages, images only). Answer these three questions and give the PDF page number for each answer:
1. On what date was the opinion filed?
2. How much had Mrs. Colton been allowed to draw for her own use?
3. What did the court decide, which judge wrote the opinion, and which judges concurred?With the MCP server, the agent made one extract_pdf_text call (62 pages in about 5 seconds), got back the path of colton_scan.ocr.txt, then searched that file. Its answer, shortened (formatting removed, side sentences cut):
1. Filing date: The opinion was filed January 2, 1890. It appears in the header of PDF page 9 (Colton v. Stanford et al., No. 11,983, Supreme Court of California, In Bank).
2. Amount Mrs. Colton was allowed to draw: About $175,000. The text says that from October 1878 to the time of the settlement she "had been allowed to draw about $175,000 for her own use, and to pay off the debts of the estate." The sentence starts at the bottom of PDF page 50, and the figure itself is on PDF page 51.
3. Decision, author and concurring judges (PDF page 54):
- Decision: The court affirmed the judgment and the order denying a new trial.
- Author: Paterson, J. His name is the signature at the end of the opinion.
- Concurring: McFarland, J.; Sharpstein, J.; Works, J.; and Beatty, C. J.
- Not participating: Fox, J. did not hear the argument, and Thornton, J. considered himself disqualified.All three answers and page numbers are right; we checked each one against the scan. Then a new session asked two other questions about the same PDF: which case the opinion cites from "2 Johns & Hemmings, 467", and the case number. The text file was already there, so the tool returned it without any OCR call. We ran the same prompts in Claude Code without the MCP server, where the agent reads the PDF page images itself. Same model (Claude Sonnet 5.5), and the run summaries give the cost:
| Claude reads the images | With extract_pdf_text | |
|---|---|---|
| First 3 questions (2 runs each) | 30 s, 32 s, all right | 21 s, 22 s, all right, cost about 55% lower |
| 2 follow-up questions, new session (1 run each) | 21 s, cited case spelled "Samuels" | 14 s, "Samels" as printed, cost about 38% lower |
Without the tool, the agent loads page images in batches and reads them; on the follow-up it read pages 1 to 33 before it found both answers. With the tool, the OCR text is read once and kept, and every later question is a text search. The follow-up shows the other reason to want text: the scan prints "Higgins vs. Samels". Reading the image, the model wrote "Samuels" and presented it as the opinion's exact words. That was one run, but it is the kind of slip you only catch by checking the page.
Session 2: Highlight Every Amount, With and Without the Tool
The second task needs positions. We gave page 51 as an image and this prompt:
> page51.jpg is a scanned page from a court opinion. Find every dollar amount written with a $ sign on it. Then:
1. Save page51_marked.png: the same image with a semi-transparent yellow box over each amount.
2. Save boxes.json: a JSON list with one [x0, y0, x1, y1] box per amount, in pixels of the original image.The page has six such amounts: $175,000, $25,000, $9,000, $18,000, $25,000 and $7,000. We ran the task four times in headless Claude Code with the same model (Claude Sonnet 5.5): twice without the MCP server, twice with it. Both setups could read files, write files and run Python with Pillow; no other command was allowed. We then measured each box against the true position of its amount.
| Without the tool (2 runs) | With extract_text (2 runs) | |
|---|---|---|
| Amounts found | 6 of 6, 6 of 6 | 6 of 6, 6 of 6 |
| Worst amount covered by its box | 80%, 93% | 100%, 100% |
| Agent steps | 24, 31 | 12, 14 |
| Time | 52 s, 63 s | 23 s, 38 s |
| Output tokens | 5,746, 7,926 | 2,387, 3,605 |
| Same boxes on both runs | No (up to 11 px apart) | Yes (1 px apart on one box) |
The model found all six amounts by itself. The cost was in placing the boxes. Without the tool, each run tried to call a local OCR program (not allowed here), then drew grids or crops of the page, looked at them, moved its boxes and looked again. One run drew 4 grid and check images before it was satisfied. Even then, its box on $7,000 left a fifth of the amount outside. With the tool, the agent made one extract_text call with include_words=True, merged each "$" with the number after it and drew the boxes. The run summaries put the cost of the two tool runs about 35% below the two runs without it.

For a highlight, 80% coverage is good enough to read. For redaction it is not: the uncovered part of a number is still on the page. The same goes for any task you want to repeat and audit, like marking the cited passage in a review or cropping every total from a batch of receipts. Word positions give the same boxes on every run.
How the Tool Works
extract_text sends the file to OCR Wizard and keeps only what an agent needs: the text, the language and, on request, each word with its four corners.
@mcp.tool()
def extract_text(image: str, include_words: bool = False) -> dict:
"""Read the text in an image (photo, screenshot, receipt, scanned page).
Args:
image: Local file path or public http(s) URL of the image.
include_words: Also return every word with its bounding box (pixel coordinates).
"""
body = _post(OCR_HOST, "ocr", image, "url")["body"]
result = {"text": body.get("fullText", ""), "language": body.get("detectedLanguage")}
if include_words:
result["words"] = [{"text": w["text"], "box": w["boundingPoly"]}
for w in body.get("annotations", [])]
return resultWords are off by default because they are large: page 51 has 506 words, and each one carries four points. The agent asks for them only when the task needs positions. This is the code the agent wrote in session 2 once it had the boxes, unedited except line breaks:
import json
from PIL import Image, ImageDraw
b = [[321, 137, 397, 155], [261, 295, 326, 313], [344, 315, 399, 332],
[45, 335, 112, 352], [46, 354, 111, 372], [44, 415, 101, 433]]
b = [[x0 - 2, y0 - 2, x1 + 2, y1 + 2] for x0, y0, x1, y1 in b]
im = Image.open("page51.jpg").convert("RGBA")
o = Image.new("RGBA", im.size, (0, 0, 0, 0))
d = ImageDraw.Draw(o)
for x in b:
d.rectangle(x, fill=(255, 255, 0, 110))
Image.alpha_composite(im, o).convert("RGB").save("page51_marked.png")
json.dump(b, open("boxes.json", "w"))The 2-pixel padding is the agent's own choice. It is why the boxes cover each amount in full.
Production Tips
- Name the tool in the prompt or in CLAUDE.md. In session 2, even the runs with the MCP server first tried a local OCR program. A line like "use extract_text for text and word positions in images" saves those steps.
- Send the image you will draw on. Boxes are in pixels of the file you send. If you render a PDF page to draw on it, OCR that rendered image, or scale the points.
- Keep the text file.
name.ocr.txtis plain text with page markers: commit it next to the case file, search it with any tool, or index it for RAG. It is tied to the exact PDF, and a changed PDF is read again. - Pass local paths for confidential documents. The tools accept public URLs too, but a contract on a public URL is a contract anyone can download.
- Best for: positions (highlight, redact, crop), repeatable text you store or search, and agents whose model does not read images at all.
Next Step
Get a key on the OCR Wizard API page, add the server with the command above and ask your assistant to mark something on one of your own scans. To build the same thing in plain Python, the searchable PDF tutorial turns a scan into a searchable file, and the RAG on scanned PDFs tutorial answers questions with page citations and highlights the quote on the page.
Sources
Frequently Asked Questions
- Is there an MCP server for OCR?
- Yes. The open source AI Engine MCP server on GitHub has two OCR tools: extract_text reads an image and can return the pixel box of every word, and extract_pdf_text reads a whole scanned or digital PDF in one call and saves the text next to it. They call the OCR Wizard API and work in Claude Code, Claude Desktop, Cursor and any MCP client.
- Claude can read images. Why give it an OCR tool?
- Cost, speed, exact text and positions. On a 62-page scan, three questions cost about half as much with extract_pdf_text as when Claude Code read the page images itself, and took 21 to 22 seconds instead of 30 to 32. Asked to highlight six amounts on a page, the agent took 12 to 14 steps with extract_text and covered every amount fully; without it, 24 to 31 steps and one box covered only 80% of its amount.
- Can an MCP tool read a long scanned PDF in one call?
- Yes. extract_pdf_text splits the PDF into 10-page parts, reads them in parallel and returns the whole text: 62 scanned pages in about 5 seconds. The text is saved next to the PDF as name.ocr.txt, so a later question on the same file needs no new OCR.
- What coordinates does extract_text return?
- Pixel coordinates of the image you send, as four corner points per word, with the origin at the top left. Draw on that same image, or scale the points if you render the page at another size.



