Skip to main content
Glama
README.md
<div align="center">

# ๐Ÿ” PaddleOCR-json MCP

**Local OCR for MCP clients, powered by PaddleOCR-json v1.4.1**

[![Python](https://img.shields.io/badge/Python-3.10%2B-3776AB?logo=python&logoColor=white)](https://www.python.org/)
[![MCP](https://img.shields.io/badge/MCP-stdio-5A67D8)](https://modelcontextprotocol.io/)
[![PaddleOCR--json](https://img.shields.io/badge/PaddleOCR--json-v1.4.1-2496ED)](https://github.com/hiroi-sora/PaddleOCR-json/releases/tag/v1.4.1)
[![License](https://img.shields.io/badge/License-Apache--2.0-green.svg)](LICENSE)
[![CI](https://github.com/luffy666code/PaddleOCR-json-MCP/actions/workflows/ci.yml/badge.svg)](https://github.com/luffy666code/PaddleOCR-json-MCP/actions/workflows/ci.yml)

A lightweight **Model Context Protocol (MCP)** wrapper that exposes local
PaddleOCR-json text recognition to any compatible MCP client.

**Image path ยท Base64 ยท local processing ยท reusable engine process**

</div>

---

## โœจ Features

- ๐Ÿ–ผ๏ธ Recognize text from a local image path.
- ๐Ÿงฉ Recognize Base64 or `data:image/...;base64,...` input.
- ๐Ÿ“ Optionally return text boxes and confidence scores.
- โšก Reuse one PaddleOCR-json process across multiple requests.
- ๐Ÿ” Restart once automatically when an OCR request fails.
- ๐Ÿงน Cleanly terminate the child process when the MCP server exits.
- ๐ŸชŸ Windows and ๐Ÿง Linux runtime layouts supported by the wrapper.
- ๐Ÿ”’ OCR runs through a local PaddleOCR-json runtime; no remote OCR API is required.
- ๐Ÿ”Œ Client-agnostic stdio MCP server โ€” no dependency on a specific agent platform.

## ๐Ÿงฐ MCP tools

| Tool | Purpose |
| --- | --- |
| `recognize_image` | OCR a local image file. |
| `recognize_image_base64` | OCR an image supplied as Base64. |
| `paddleocr_status` | Check engine files and current subprocess status without starting OCR. |

`recognize_image` and `recognize_image_base64` accept `include_details=true` to
include bounding boxes in the normalized result.

## ๐Ÿ—๏ธ How it works

```text
MCP client
   โ”‚  JSON-RPC over stdio
   โ–ผ
FastMCP wrapper (main.py)
   โ”‚  line-oriented JSON over stdin/stdout
   โ–ผ
PaddleOCR-json v1.4.1
   โ”‚
   โ””โ”€โ”€ models / native runtime files
```

The wrapper keeps the OCR engine alive for reuse. A single stdout reader feeds
responses through a queue, requests are serialized with a lock, and shutdown
uses terminate โ†’ wait โ†’ kill as a fallback.

## ๐Ÿš€ Quick start

### 1. Clone and install

```bash
git clone https://github.com/luffy666code/PaddleOCR-json-MCP.git
cd PaddleOCR-json-MCP
python -m venv .venv
```

Activate the virtual environment, then install:

```bash
python -m pip install -U pip
python -m pip install -e .
```

### 2. Add the PaddleOCR-json runtime

Download **PaddleOCR-json v1.4.1** from the upstream release page:

https://github.com/hiroi-sora/PaddleOCR-json/releases/tag/v1.4.1

Place the runtime under `engine/`.

**Windows**

```text
engine/
โ”œโ”€โ”€ PaddleOCR-json.exe
โ””โ”€โ”€ models/
```

**Linux**

```text
engine/
โ”œโ”€โ”€ bin/
โ”‚   โ””โ”€โ”€ PaddleOCR-json
โ”œโ”€โ”€ lib/
โ””โ”€โ”€ models/
```

See [`engine/README.md`](engine/README.md) for the expected layout.

### 3. Run the MCP server

```bash
python main.py
```

The server uses **stdio**, so in normal use it is started by your MCP client
rather than run interactively.

## ๐Ÿ”Œ MCP client configuration

A generic source-mode configuration looks like this:

```json
{
  "mcpServers": {
    "paddleocr": {
      "command": "python",
      "args": ["/absolute/path/to/PaddleOCR-json-MCP/main.py"]
    }
  }
}
```

If you build a standalone wrapper, point `command` at the generated executable
instead. The exact configuration file location depends on your MCP client.

> The repository intentionally avoids client-specific placeholder syntax and
> deployment metadata. Keep client/platform adapters outside the reusable core.

## ๐Ÿงช Tool examples

### Local image

```json
{
  "image_path": "C:\\images\\receipt.png",
  "include_details": false
}
```

### Base64 image

```json
{
  "image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
  "include_details": true
}
```

A successful normalized result has the shape:

```json
{
  "code": 100,
  "text": "Hello OCR",
  "count": 1,
  "lines": [
    {
      "text": "Hello OCR",
      "score": 0.99,
      "box": [[10, 12], [120, 12], [120, 38], [10, 38]]
    }
  ]
}
```

## ๐Ÿ“ฆ Build a standalone wrapper

The engine and model files remain external so they can be updated separately
from the Python wrapper.

**Windows**

```bat
scripts\build_windows.bat
```

Output:

```text
dist/paddleocr-mcp.exe
```

**Linux**

```bash
./scripts/build_linux.sh
```

After building, keep the executable next to the `engine/` directory:

```text
runtime/
โ”œโ”€โ”€ paddleocr-mcp.exe   # Windows example
โ””โ”€โ”€ engine/
    โ”œโ”€โ”€ PaddleOCR-json.exe
    โ””โ”€โ”€ models/
```

## ๐Ÿ“ Repository layout

```text
PaddleOCR-json-MCP/
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ engine/
โ”‚   โ””โ”€โ”€ README.md
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ build_windows.bat
โ”‚   โ””โ”€โ”€ build_linux.sh
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/ci.yml
โ”‚   โ””โ”€โ”€ ISSUE_TEMPLATE/bug_report.yml
โ”œโ”€โ”€ CONTRIBUTING.md
โ”œโ”€โ”€ SECURITY.md
โ”œโ”€โ”€ NOTICE
โ””โ”€โ”€ LICENSE
```

Generated `build/`, `dist/`, logs, virtual environments, PaddleOCR-json engine
binaries, and model files are intentionally excluded from Git.

## ๐Ÿ” Privacy & security

The wrapper itself talks to a **local PaddleOCR-json process** and does not
require a cloud OCR API. Images provided by file path stay on the MCP host as
far as this wrapper is concerned. Your MCP client or host may implement its own
logging, telemetry, or file handling, so review that environment separately.

Do not expose this MCP server to untrusted callers without considering local
file access: `recognize_image` can read any image path that the server process
has permission to access.

## ๐Ÿ™ Credits

This repository is an independent community wrapper around:

- [hiroi-sora/PaddleOCR-json](https://github.com/hiroi-sora/PaddleOCR-json)
- [PaddlePaddle/PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
- [FastMCP](https://github.com/jlowin/fastmcp)

PaddleOCR-json v1.4.1 is licensed under the Apache License 2.0. This repository
does not claim to be an official PaddlePaddle or PaddleOCR-json project.

## ๐Ÿ“„ License

Apache License 2.0. See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE).

---

<div align="center">

If this wrapper is useful, consider starring the upstream OCR projects too. โญ

</div>