Skip to main content
Glama

roshan-alefba-mcp

A self-hostable Model Context Protocol server for Roshan AI's OCR service Alefba (الفبا).

Unofficial, community-built. Wraps the public API documented at docs.roshan-ai.ir.


What is this?

Alefba (الفبا) is Roshan AI's high-accuracy OCR / document-understanding service for Persian (fa), Arabic (ar) and English (en). Give it an image or PDF and it returns the text split into pages, paragraphs and lines — each with its bounding box, direction and recognition confidence — and it can tell tables, images and text apart. It also exports the analyzed document as a searchable PDF, Word or Excel file.

This server exposes Alefba to any MCP client (Claude or otherwise) as a set of first-class tools. Alefba is commonly self-hosted, and organizations often run many independent instances (per data-center, tenant, or environment), so named instances are a core concept here: every tool takes an optional instance argument selecting which deployment to talk to.

Related MCP server: OwlOCR MCP

Features

  • All Alefba endpoints as tools, prefixed alefba_ (read, pages, status, download to PDF/Word/Excel, delete, callback).

  • URL input and local-file upload (multipart).

  • Async OCR: queue with wait=false, then poll with alefba_get_result.

  • Many named, self-hosted instances; pick per call via instance.

  • Guardrails: http(s) URL validation, enum/number clamping, list-size limits, and token redaction — tokens are never logged or returned.

  • Transports: stdio (default), sse, streamable-http.

Install

Requires Python 3.10+.

git clone <this-repo>
cd roshan-alefba-mcp
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"      # runtime + test deps (omit [dev] for runtime only)

Run it:

python -m roshan_alefba_mcp --help
python -m roshan_alefba_mcp --transport stdio          # default
python -m roshan_alefba_mcp --transport streamable-http

Configuration

Configuration is read from environment variables. The simplest setup uses the shorthand form, which synthesizes a single instance named default:

Variable

Description

Default

ROSHAN_ALEFBA_BASE_URL

Base URL of the default Alefba instance

https://alefba.roshan-ai.ir

ROSHAN_ALEFBA_TOKEN

API token for the default instance (sent as Authorization: Token <token>)

(none)

For multiple instances, use the nested form (one base_url + token per instance):

Variable

Description

ROSHAN_ALEFBA__INSTANCES__<NAME>__BASE_URL

Base URL for instance <NAME>

ROSHAN_ALEFBA__INSTANCES__<NAME>__TOKEN

Token for instance <NAME>

ROSHAN_ALEFBA__INSTANCES__<NAME>__VERIFY_SSL

Verify TLS for <NAME> (default true)

ROSHAN_ALEFBA__INSTANCES__<NAME>__TIMEOUT

Request timeout in seconds (default 60)

ROSHAN_ALEFBA__DEFAULT_INSTANCE

Instance used when a call omits instance (default default)

ROSHAN_ALEFBA__LOG_LEVEL

Log level (default INFO)

Example (two instances, default = dc1):

export ROSHAN_ALEFBA__INSTANCES__DC1__BASE_URL="https://alefba-dc1.example.ir"
export ROSHAN_ALEFBA__INSTANCES__DC1__TOKEN="token-1"
export ROSHAN_ALEFBA__INSTANCES__DC2__BASE_URL="https://alefba-dc2.example.ir"
export ROSHAN_ALEFBA__INSTANCES__DC2__TOKEN="token-2"
export ROSHAN_ALEFBA__DEFAULT_INSTANCE="dc1"

Call list_instances at any time to see configured instance names and base URLs (never tokens).

Use with an MCP client

Add the server to your client config (example for stdio):

{
  "mcpServers": {
    "roshan-alefba": {
      "command": "python",
      "args": ["-m", "roshan_alefba_mcp", "--transport", "stdio"],
      "env": {
        "ROSHAN_ALEFBA_BASE_URL": "https://alefba.roshan-ai.ir",
        "ROSHAN_ALEFBA_TOKEN": "your-token"
      }
    }
  }
}

Tool reference

All tools accept an optional instance (except list_instances and roshan_alefba_docs). OCR tools also share type (general | ID-card | excel), fix_orientation, word_positions, wait, and priority (1–4).

Tool

Endpoint

Purpose

alefba_read_document

POST /api/read_document/

Read (OCR) a document/image from a URL; sync (wait=true) or async (task_ids).

alefba_read_document_upload

POST /api/read_document/ (multipart)

Upload a local file_path and read it.

alefba_get_result

POST /api/read_document/

Fetch/poll an async result by task_id.

alefba_read_pages

POST /api/read_pages/

Read specific pages given as URLs with @page=N.

alefba_document_status

POST /api/document_status/

Per-document progress (analyzed, processed_pages, all_pages).

alefba_document_pages

POST /api/document_pages/

List a document's page URLs.

alefba_download_word

POST /api/download_word/

Download as Word (.docx); optional save_path.

alefba_download_excel

POST /api/download_excel/

Download as Excel (.xlsx); requires type=excel; optional save_path.

alefba_download_pdf

POST /api/download_pdf/

Download as searchable PDF (quality 0–100, color); optional save_path.

alefba_delete_document

POST /api/delete_document/

Delete a document and its results.

alefba_read_document_callback

POST /api/read_document/

Process and receive the result via a webhook callback_url.

healthcheck

GET /api/healthcheck/

Check an instance is up and ready.

list_instances

(local)

List configured instance names + base URLs (no tokens).

roshan_alefba_docs

(local)

Documentation about Alefba and these tools.

Download tools return the download URL and request payload by default; pass save_path to download the bytes and save them locally (the saved path is returned). box values in OCR results are "left top width height" in pixels.

Architecture

Architecture

The MCP client calls tools registered by build_server(); the ocr, common and docs tool modules validate input (guardrails.py), resolve the target deployment (config.py) and talk to Alefba over an authenticated async HTTP client (client.py).

Self-hosting & scaling

One process can route to many self-hosted Alefba deployments, selected per call by instance:

Self-hosting multi-instance

The server is stateless, so scale it horizontally (more replicas behind a load balancer, or enable the Helm/Kubernetes HPA). Each replica reads the same instance configuration.

Request flow (async OCR + PDF export)

Request flow

  1. alefba_read_document(wait=false) queues the job; Alefba returns {state, task_ids}.

  2. Poll alefba_get_result(task_id) until the full {document_url, pages[...]} result is ready.

  3. alefba_download_pdf(document_url, save_path) exports a searchable PDF.

The diagrams above are generated with the diagrams library. Regenerate them with python assets/diagrams/generate_diagrams.py (requires pip install diagrams and the Graphviz dot binary).

Deployment

Manifests and modules live in deploy/:

See deploy/README.md for details.

Testing

make test        # pytest, HTTP mocked with respx (live tests skipped)
make smoke       # offline: build server, list tools, assert invariants
python examples/inspect_server.py

Live tests against a real Alefba instance are skipped unless ROSHAN_ALEFBA_LIVE=1 and credentials are set.

License

MIT. "Roshan", the Roshan logo, and "Alefba" are trademarks of their respective owner and are used only to identify the upstream service this tool integrates with.

Available Tools

17 tools
alefba_delete_documentA

Delete a previously uploaded document and its results. حذف سند بارگذاری‌شده و نتایج آن. Calls POST /api/delete_document/ and returns {message} confirming deletion. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), instance. Returns: object

alefba_detail_documentC

Fetch full detail for a document (thumbnails, page URLs, pages, type). دریافت جزئیات کامل یک سند. Calls POST /api/detail_document/ and returns {document_url, thumbnail, thumbnails:[...], page_urls:[...], pages:[...], document_type}. May start processing any remaining pages of the document. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), instance. Returns: object

alefba_document_pagesA

List the page URLs that make up a previously uploaded document. فهرست صفحات یک سند بارگذاری‌شده. Calls POST /api/document_pages/ and returns {document_url, pages:[page_url, ...]}. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), instance. Returns: object

alefba_document_statusA

Report processing progress for one or more documents. گزارش وضعیت پردازش اسناد. Calls POST /api/document_status/ and returns a mapping of each URL to {analyzed, processed_pages, all_pages} so you can track async jobs. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_urls (required), instance. Returns: object

alefba_download_excelA

Download the analyzed document as an Excel (.xlsx) file. دریافت سند تحلیل‌شده به صورت فایل اکسل. Calls POST /api/download_excel/. The document must have been processed with type=excel. Returns download info, or the saved path when save_path is provided. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), save_path, instance. Returns: object

alefba_download_originalA

Get a signed link to download a document's ORIGINAL source file. دریافت پیوند دانلود فایل اصلی سند. Calls POST /api/download_original/ and returns {download_link}. The link is signed and short-lived (expires ~30s) and only works for already-processed local files. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), instance. Returns: object

alefba_download_pdfA

Download the analyzed document as a searchable PDF. دریافت سند به صورت پی‌دی‌اف قابل‌جست‌وجو. Calls POST /api/download_pdf/. quality controls image quality (0-100), color toggles colour vs. grayscale, and img_format (png|jpg) sets the embedded image format. Returns download info, or the saved path when save_path is provided. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), quality, color, img_format, +2 more. Returns: object

alefba_download_wordA

Download the analyzed document as a Word (.docx) file. دریافت سند تحلیل‌شده به صورت فایل ورد. Calls POST /api/download_word/. Returns the download endpoint info; when save_path is given the .docx bytes are saved locally and the saved path is returned. The document must have been processed first. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), save_path, instance. Returns: object

alefba_get_resultA

Fetch or poll the result of an async document read. دریافت نتیجه پردازش ناهمگام با شناسه کار. Pass a task_id returned by alefba_read_document(wait=false). If the job is still running you get {state} (e.g. pending); when done you get the full document result. Set wait=true to block server-side until completion. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: task_id (required), wait, instance. Returns: object

alefba_list_documentsA

List documents known to an Alefba instance, page by page. فهرست اسناد موجود در سرویس الفبا. Calls GET /api/list_documents/?page=N and returns {results:[{url, thumbnail, indexed_in_bazz, processed_pages, page_count, analyzed, processed_diff, type, filename}], num_pages}. Use num_pages to iterate; page defaults to 1. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: page, instance. Returns: object

alefba_read_documentA

Read (OCR) a document or image from a URL. استخراج متن از سند یا تصویر با آدرس اینترنتی. By default the call blocks (wait=true) and returns the full structured result {document_url, pages:[{page_url,width,height,angle,text,parts:[...]}]} where each box is 'left top width height' in pixels. Set wait=false to queue the job and get {state, task_ids} back, then poll with alefba_get_result. type is one of general, ID-card, excel; priority is 1 (highest) to 4 (lowest). Pass an optional task_id to fetch a queued result. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), type, fix_orientation, word_positions, +4 more. Returns: object

alefba_read_document_callbackA

Read a document and receive the result via webhook (callback). پردازش سند و دریافت نتیجه از طریق وب‌هوک. Instead of polling, Alefba POSTs the result to callback_url when done. Returns {state:'processing', document_url} immediately. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: document_url (required), callback_url (required), instance. Returns: object

alefba_read_document_uploadA

Upload a local file and read (OCR) it. بارگذاری فایل محلی و استخراج متن آن. Sends the file as multipart form data (field 'document') to Alefba with the same options as alefba_read_document. Returns the structured OCR result, or {state, task_ids} when wait=false. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: file_path (required), type, fix_orientation, word_positions, +3 more. Returns: object

alefba_read_pagesA

Read (OCR) specific pages of documents. استخراج متن از صفحات مشخص اسناد. Each entry in page_urls is a document URL with an @page=N suffix, e.g. https://example.com/doc.pdf@page=2. Returns the same structured result as alefba_read_document (or {state, task_ids} async). Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: page_urls (required), type, fix_orientation, word_positions, +3 more. Returns: object

healthcheckA

Check that an Alefba instance is up and ready. بررسی سلامت سرویس الفبا. Calls Alefba's GET /api/healthcheck/ readiness probe and returns {status, message}, e.g. {"status": "ok", "message": "Server is up and ready"}. Optional name of the configured Alefba instance to target. Omit to use the default instance.

Inputs: instance. Returns: object

list_instancesA

List the configured Alefba instances (names and base URLs only). فهرست نمونه‌های پیکربندی‌شده الفبا. Useful for discovering which 'instance' values the other tools accept. Returns {default_instance, instances:[{name, base_url, verify_ssl}]}. Tokens are NEVER returned.

Inputs: no named parameters. Returns: object

roshan_alefba_docsA

Return documentation about Alefba (الفبا) OCR and these MCP tools. راهنمای سرویس الفبا و ابزارهای این سرور. Use this to learn what the server does, which tools exist, and where to read the official docs (https://docs.roshan-ai.ir) before calling other tools. Pass an optional topic to filter to one tool or doc link.

Inputs: topic. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 17 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose; even the four read-document variants are distinguished by method (URL, callback, upload, pages). Persian and English descriptions reinforce uniqueness.

    Naming Consistency3/5

    Most tools follow 'alefba_verb_noun' (e.g., delete_document), but some use 'alefba_noun_verb' (e.g., document_status) and three tools (healthcheck, list_instances, roshan_alefba_docs) lack the 'alefba_' prefix, breaking the pattern.

    Tool Count4/5

    17 tools cover the full OCR document lifecycle—upload, read, status, download, delete—plus instance management and docs. Slightly above the typical ideal range but justifiable for the feature set.

    Completeness5/5

    The tool surface is comprehensive: multiple read modes, format-specific downloads, async result polling, healthcheck, instance listing, and documentation. No obvious gaps for document processing.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      A macOS-based MCP server that enables high-accuracy text extraction from PDF and image files using the OwlOCR app or Apple's Vision Framework. It supports multi-language OCR and provides asynchronous tools for processing documents directly within MCP clients.
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      An MCP server that lets AI assistants read and visually analyze local documents — PDFs, Excel spreadsheets, CSV files, Word documents, PowerPoint presentations, and images.
      4
      49 npm
      100 PyPI
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A self-hostable MCP server for Roshan AI's Persian speech service, Harf, enabling transcription, forced alignment, real-time streaming, and speaker analysis through natural language.
      -