This tutorial uses the id-document-ocr API. See the docs, live demo, and pricing.
You are building an onboarding or support agent, and at some point a customer sends a photo of their ID. The agent needs an answer to two questions: is the document usable, and is the person old enough. It does not need the name, the date of birth or the document number to answer them. Yet whatever a tool returns lands in the conversation, and from there in the model provider's request, in your logs and in saved transcripts. This guide adds an ID verification tool to an AI agent through MCP that returns a verdict, not personal data, unless the task really needs the identity.
The tool is parse_id, now part of our open source AI Engine MCP server. It calls the ID Document OCR API. Every session below was run in Claude Code on 4 December 2026 on public specimens: the French ID card (front and back photos) and a South Korean passport.
The Rule: Return What the Decision Needs
Data minimisation (GDPR article 5) says to process only the personal data a purpose needs. For an agent, the place to apply it is the tool output, because the model reads all of it. parse_id has two levels:
detail="verdict"(default):next_step, document type, country,is_expired,age_18_or_over, the fields checked by the machine-readable zone (MRZ), and anything missing or inconsistent. No name, no birth date, no document number.detail="identity": adds names, dates, nationality and sex, for tasks like filling a form. The document number is masked except its last 4 characters.
The age is computed inside the tool from the birth date, against min_age (18 by default). The agent learns "over 18: yes" without learning the date.
Install
Create a free RapidAPI account, subscribe to the ID Document OCR 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 also removes backgrounds, reads text and checks images for nudity; each tool needs a subscription to its own API, and the others keep working without it.
Session 1: Valid and Adult, Without the Name
A folder with id_front.jpg and id_back.jpg. The question:
> A customer uploaded id_front.jpg and id_back.jpg to open an account. Is the ID valid and is the customer an adult?The agent called the tool with the default level. This is the full tool result it received:
{
"next_step": "accept",
"document_type": "id_card",
"country": "FRA",
"sides": 2,
"status": "ok",
"is_expired": false,
"age_18_or_over": true,
"checked_by_mrz": [
"birth_date",
"document_number",
"expiry_date",
"first_name",
"last_name",
"nationality",
"sex"
],
"missing_critical_fields": [],
"mismatched_fields": [],
"consistency_issues": []
}And the start and end of its answer:
Yes on both counts. The ID passes the check and the holder is 18 or older.
I asked only for the yes/no result, so no personal details (name, date of birth, ID number) came into this conversation. If you need them to fill in the account form, I can run it again and ask for them.The agent never opened the images and never saw the customer's name. It still gave a complete answer, because the decision did not depend on the identity. Without being asked, it also offered to run the identity level if the form needed it.
Session 2: An Expired Passport
> Same check for passport.jpg, a new customer: can we open the account?{
"next_step": "ask for a document that is not expired",
"document_type": "passport",
"country": "KOR",
"sides": 1,
"status": "ok",
"is_expired": true,
"age_18_or_over": true,
"checked_by_mrz": [
"birth_date",
"document_number",
"expiry_date",
"first_name",
"last_name",
"nationality",
"sex"
],
"missing_critical_fields": [],
"mismatched_fields": [],
"consistency_issues": []
}Not yet. The passport is expired, so ask the customer for a document that is still valid.
I ran the check without personal details, so I didn't see the name, birth date or document number. If you need them, for example to fill in the account form, I can run it again with the identity details turned on.next_step is there so the agent does not have to combine the verdict, the expiry and the age itself. One field, one instruction, and the agent turned it into a message the operator can act on.
Session 3: Filling a Form Needs the Identity
> Fill form.json with the customer's details from id_front.jpg and id_back.jpg.This time the agent chose detail="identity" by itself, because the task needs the names. The tool call:
{
"images": [
"id_front.jpg",
"id_back.jpg"
],
"detail": "identity"
}The identity part of the result:
{
"fields": {
"last_name": {
"value": "MARTIN",
"status": "mrz_confirmed"
},
"first_name": {
"value": "MAELYS GAELLE MARIE",
"status": "mrz_confirmed"
},
"birth_date": {
"value": "1990-07-13",
"status": "mrz_confirmed"
},
"expiry_date": {
"value": "2030-02-11",
"status": "mrz_confirmed"
},
"nationality": {
"value": "FRA",
"status": "mrz_confirmed"
},
"sex": {
"value": "F",
"status": "mrz_confirmed"
},
"document_number": {
"value": "*****PFW4",
"status": "mrz_confirmed"
}
}
}It wrote the form and explained its choices:
I filled in `form.json` from the two sides of the customer's French ID card:
All four values match the machine-readable code on the back of the card. The card is valid until 2030-02-11, and the customer is over 18.
A few things you may want to change:
- **Names:** `first_name` holds all three given names, and names are in capitals without accents, as the code prints them. If the form wants only the first given name or normal capitalisation, I can change it.
- **Nationality:** it's the 3-letter code `FRA`. I can write "French" or `FR` instead if the form needs that.
- I didn't use `passport.jpg`, since you only mentioned the two ID card images.Even here the document number reached the conversation only as *****PFW4. If your form needs the full number, read it in your own backend code from the API, not through the chat.

How the Tool Works
The whole tool is one function in server.py. The docstring matters as much as the code: it is what the model reads to decide how to call the tool, and it says plainly that the output enters the conversation and when to ask for the identity.
def _age(birth, today):
b = date.fromisoformat(birth)
return today.year - b.year - ((today.month, today.day) < (b.month, b.day))
def _mask(number):
return None if not number else "*" * max(len(number) - 4, 0) + number[-4:]
@mcp.tool()
def parse_id(images: list[str], detail: str = "verdict", min_age: int = 18) -> dict:
"""Read and check an ID document: passport, ID card, driving licence or residence permit.
Privacy: everything this tool returns enters the conversation. With detail="verdict"
(default) it returns no name, no date of birth and no document number, only what is needed
to decide: document type, country, expired or not, holder old enough or not, and what to fix.
Use detail="identity" only when the user needs names and dates, for example to fill a form.
The document number is always masked except its last 4 characters.
Args:
images: 1 to 6 local paths or public URLs of ONE document (front, back, extra shots, PDF).
detail: "verdict" (default, no personal data) or "identity" (adds names and dates).
min_age: Age the holder must have reached today. Default 18.
"""
if not 1 <= len(images) <= 6:
raise ToolError("Send 1 to 6 images of the same document.")
if detail not in ("verdict", "identity"):
raise ToolError('detail must be "verdict" or "identity"')
url = f"https://{ID_HOST}/parse-id"
if all(_is_url(i) for i in images):
r = requests.post(url, headers=_headers(ID_HOST), json={"image_urls": images}, timeout=TIMEOUT)
elif any(_is_url(i) for i in images):
raise ToolError("Use either local files or URLs in one call, not both.")
else:
paths = [_local(i) for i in images]
if sum(p.stat().st_size for p in paths) > MAX_BODY:
raise ToolError("Files are over 4.5 MB in total: resize photos to about 1600 px "
"on the long side, or pass public URLs instead.")
files = [("images", (p.name, p.read_bytes())) for p in paths]
r = requests.post(url, headers=_headers(ID_HOST), files=files, timeout=TIMEOUT)
if r.status_code != 200:
raise ToolError(f"parse-id failed with HTTP {r.status_code}: {r.text[:300]}")
res = r.json()["result"]
f, v = res["fields"], res["verdict"]
birth = (f.get("birth_date") or {}).get("value")
old_enough = None if not birth else _age(birth, date.today()) >= min_age
if v["missing_critical_fields"] or "unread_field" in v["consistency_issues"]:
next_step = "ask for new photos of every side: some fields could not be read"
elif "multiple_documents" in v["consistency_issues"]:
next_step = "ask for one document at a time"
elif v["is_expired"]:
next_step = "ask for a document that is not expired"
elif old_enough is False:
next_step = f"holder is under {min_age}"
elif v["status"] != "ok":
next_step = "send to a person for manual review"
else:
next_step = "accept"
out = {
"next_step": next_step,
"document_type": res.get("document_type"),
"country": res.get("country"),
"sides": res.get("sides"),
"status": v["status"],
"is_expired": v["is_expired"],
f"age_{min_age}_or_over": old_enough,
"checked_by_mrz": sorted(k for k, x in f.items() if x["status"] in ("mrz_confirmed", "mrz_only")),
"missing_critical_fields": v["missing_critical_fields"],
"mismatched_fields": v["mismatched_fields"],
"consistency_issues": v["consistency_issues"],
}
if detail == "identity":
keep = ("last_name", "first_name", "birth_date", "expiry_date", "nationality", "sex")
out["fields"] = {k: {"value": f[k]["value"], "status": f[k]["status"]} for k in keep if k in f}
if "document_number" in f:
out["fields"]["document_number"] = {"value": _mask(f["document_number"]["value"]),
"status": f["document_number"]["status"]}
return outChoices worth copying in your own tools:
- Private by default, explicit to open. The agent has to pass
detail="identity", which shows up in the tool call, so you can see in the transcript when personal data was requested and why. - Compute inside, return the answer.
age_18_or_overinstead of the birth date,checked_by_mrzas a list of field names instead of values. - Never return what no task needs. Personal numbers and addresses are not returned at any level.
- Errors the agent can act on. Raw 12 megapixel phone photos are too big for one call, and the error says what to do.
Test It Without an Assistant
The MCP Python SDK can start the server and call the tool directly, which is how we test it before every release:
import asyncio
import os
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
SERVER = StdioServerParameters(command="ai-engine-mcp", env={**os.environ})
async def main():
async with stdio_client(SERVER) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
for images in (["front_glare.jpg", "back_blur.jpg"], ["front_raw.jpg", "back_raw.jpg"]):
result = await session.call_tool("parse_id", {"images": images})
print(images, "error" if result.is_error else "")
print(result.content[0].text)
asyncio.run(main())['front_glare.jpg', 'back_blur.jpg']
{
"next_step": "ask for new photos of every side: some fields could not be read",
"document_type": "id_card",
"country": "FRA",
"sides": 2,
"status": "review",
"is_expired": false,
"age_18_or_over": true,
"checked_by_mrz": [],
"missing_critical_fields": [
"document_number"
],
"mismatched_fields": [],
"consistency_issues": []
}
['front_raw.jpg', 'back_raw.jpg'] error
Error executing tool parse_id: Files are over 4.5 MB in total: resize photos to about 1600 px on the long side, or pass public URLs instead.The first call is a front with glare and a blurry back: the tool asks for new photos. The second sends the raw phone photos (3.1 and 3.2 MB) and gets a clear error before anything is uploaded.
Production Tips
- Pass local paths, not public URLs, for real IDs. The tool accepts both, but an ID on a public URL is an ID anyone can download.
- Allow only the tools the agent needs. In Claude Code,
--allowedTools mcp__ai-engine__parse_idkeeps a support agent from using the image editing tools. - Mind transcript retention. Even masked, identity results are personal data. Keep agent transcripts for as short a time as your process allows.
- Add a face check for remote onboarding. A document check tells you the document is usable, not that the person sending it is its holder. Our selfie to ID verification guide covers that step.
Next Step
Get a key on the ID Document OCR API page, add the server with the command above and ask your assistant to check the French specimen below. To go further without an agent, the age verification tutorial and the hotel check-in tutorial use the same API in plain Python.
Sources
- AI Engine MCP server on GitHub (MIT)
- Model Context Protocol
- GDPR, Regulation (EU) 2016/679, article 5 (data minimisation)
- Specimens on Wikimedia Commons: French ID card front and back, South Korean passport
Frequently Asked Questions
- Is there an MCP server for ID document verification?
- Yes. The open source AI Engine MCP server on GitHub includes a parse_id tool that reads and checks passports, ID cards, driving licences and residence permits through the ID Document OCR API. It works in Claude Code, Claude Desktop, Cursor and any MCP client, with one RapidAPI key.
- Does the AI model see the customer's personal data?
- Only if the task needs it. Everything a tool returns enters the conversation, so parse_id returns a verdict by default: document type, country, expired or not, age over a threshold, fields checked by the MRZ and a next step, with no name, birth date or document number. The names and dates are returned only with detail="identity", for example to fill a form, and the document number is always masked except its last 4 characters.
- Does the agent look at the ID image itself?
- No. The tool takes file paths, sends the files to the ID Document OCR API and returns JSON. In our sessions the agent never opened the images. The API does not store the images it receives.
- How do I check that a customer is over 21 with an MCP tool?
- Call parse_id with min_age=21. The result contains age_21_or_over (true or false), computed inside the tool from the birth date, so the birth date itself does not have to enter the conversation.



