Skip to main content

OCR MCP Server

Multi-backend OCR MCP server for LibreChat with support for Marker (local), DeepSeek API, and Mistral API.

Features

  • Multiple Backends: Marker (local, free), DeepSeek API, Mistral API
  • Automatic Fallback: Seamlessly falls back to next backend on failure
  • Flexible Configuration: Environment-based configuration
  • Cost-Effective: Use local Marker for simple docs, APIs for complex handwriting
  • Easy Integration: Works with LibreChat MCP
  • Optional Backends: Enable only the backends you need

Quick Start

Minimal Setup (Marker + Mistral)

# Install
pip install -r requirements.txt

# Configure (only Mistral key required)
echo 'MISTRAL_API_KEY=your-key-here' > .env

# Test
python -m ocr_mcp.server

LibreChat Configuration

mcpServers:
  ocr:
    command: "python"
    args: ["-m", "ocr_mcp.server"]
    env:
      MISTRAL_API_KEY: "your-mistral-key-here"
      ENABLED_BACKENDS: "marker,mistral"
      DEFAULT_BACKEND: "marker"

Configuration

Environment Variables

# API Keys (only required for enabled backends)
MISTRAL_API_KEY=your-mistral-key-here      # Required if mistral enabled
DEEPSEEK_API_KEY=your-deepseek-key-here    # Optional - only if deepseek enabled

# Backend Configuration
ENABLED_BACKENDS=marker,mistral            # Comma-separated list
DEFAULT_BACKEND=marker                     # Default backend to use

# Processing Settings
MAX_FILE_SIZE_MB=50                        # Maximum file size
TIMEOUT_SECONDS=120                        # Processing timeout
API_TIMEOUT=30                             # API call timeout
API_MAX_RETRIES=3                          # API retry attempts
MARKER_BATCH_SIZE=1                        # Marker batch size

Backend Options

Marker Only (No API keys needed):

ENABLED_BACKENDS: "marker"
DEFAULT_BACKEND: "marker"

Marker + Mistral (Recommended):

MISTRAL_API_KEY: "your-key"
ENABLED_BACKENDS: "marker,mistral"
DEFAULT_BACKEND: "marker"

All Backends (When you have DeepSeek key):

MISTRAL_API_KEY: "your-mistral-key"
DEEPSEEK_API_KEY: "your-deepseek-key"
ENABLED_BACKENDS: "marker,deepseek,mistral"
DEFAULT_BACKEND: "marker"

Usage

In LibreChat Assistant

Auto-select backend:

Extract text from this PDF

Specify backend:

Use Mistral to extract text from this handwritten page

Batch processing:

Process all uploaded PDFs with Marker first, use Mistral for pages with tables

Available Tools

  • ocr: Extract text from PDF files or images
    • file_path (required): Path to the file
    • backend (optional): Specific backend to use (marker, deepseek, mistral)

Backend Details

Marker (Local)

  • Pros: Free, fast, CPU-only, no API costs
  • Best for: Text-heavy documents, clean PDFs
  • Limitations: Struggles with handwriting and complex layouts
  • Requirements: No API key needed

Mistral API (Pixtral)

  • Pros: Best OCR accuracy, excellent with complex layouts
  • Best for: Tables, forms, mixed content, handwriting
  • Cost: API usage based
  • Requirements: Valid Mistral API key

DeepSeek API

  • Pros: Excellent handwriting recognition, affordable
  • Best for: Handwritten notes, marked-up documents
  • Cost: API usage based
  • Requirements: Valid DeepSeek API key (optional)

Adding DeepSeek Later

When you're ready to enable DeepSeek:

  1. Get API key from: https://platform.deepseek.com/api_keys
  2. Add to your configuration:
    DEEPSEEK_API_KEY: "your-deepseek-key-here"
    ENABLED_BACKENDS: "marker,deepseek,mistral"
    
  3. Restart LibreChat

The server will automatically detect and use DeepSeek when available.

Troubleshooting

MCP server not appearing

  • Check librechat.yaml indentation (YAML is whitespace-sensitive)
  • Verify API keys are set correctly
  • Check Docker logs: docker-compose logs -f

"Backend not available" error

  • Ensure ENABLED_BACKENDS matches your available API keys
  • DeepSeek will be skipped if no API key is provided
  • Mistral requires a valid API key if enabled
  • Marker requires no extra setup

Slow processing

  • Marker runs locally (fast for simple docs)
  • API calls take 2-5 seconds per page
  • Consider batch processing for large books

Marker installation issues

# Install marker-pdf separately
pip install marker-pdf

# Or install all dependencies
pip install -r requirements.txt

Configuration validation errors

The server will validate your configuration on startup. Common errors:

  • "DeepSeek backend is enabled but DEEPSEEK_API_KEY is not set"

    • Either add the API key, or remove 'deepseek' from ENABLED_BACKENDS
  • "Mistral backend is enabled but MISTRAL_API_KEY is not set"

    • Either add the API key, or remove 'mistral' from ENABLED_BACKENDS

Development

Project Structure

ocr-mcp/
├── ocr_mcp/
│   ├── __init__.py
│   ├── server.py          # Main MCP server
│   ├── config.py          # Configuration management
│   └── backends/
│       ├── __init__.py
│       ├── base.py        # Base backend interface
│       ├── marker.py      # Marker backend
│       ├── deepseek.py    # DeepSeek API backend
│       └── mistral.py     # Mistral API backend
├── pyproject.toml
└── README.md

Running from source

# Install in development mode
pip install -e .

# Run server
python -m ocr_mcp.server

License

MIT License

Contributing

Contributions welcome! Please feel free to submit issues or pull requests.

Metadata

Release files for ocr-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocr-mcp 0.1.0
File Size Uploaded Provenance
ocr_mcp-0.1.0.tar.gz 12.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ocr-mcp 0.1.0
File Interpreter ABI Platform
ocr_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / ocr_mcp-0.1.0.tar.gz

Download URL ocr_mcp-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bf307900ab7df109fd266c995ebdf3ac0d9ff95049dbabced1585b41de77e605
BLAKE2b-256 checksum
How to use checksums
a0d9539e23d4d2349a118d0177ef55bc8a83eafc96667c7be8889291b997e851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / ocr_mcp-0.1.0-py3-none-any.whl

Download URL ocr_mcp-0.1.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e2020d35a1eab23b5fbbdb19e5ba2d2d3229cf2dfc7b58ec44e943039cc4995
BLAKE2b-256 checksum
How to use checksums
96563298f7adcb830b60a1a661426eaedf8c6135a368664255358a8d8113628b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Security for ocr-mcp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page