ReadPDFx - OCR PDF MCP Server

ReadPDFx - OCR PDF MCP Server

Provides intelligent OCR and PDF processing capabilities that automatically detect whether PDFs contain digital text or scanned images and apply appropriate extraction methods. Supports text extraction, OCR processing, structure analysis, and batch operations.

Category
访问服务器

README

ReadPDFx - OCR PDF MCP Server

Official MCP SDK STDIO Server - MCP Protocol 2025-06-18 Compliant

MCP Protocol Python MCP SDK License

<div align="left" style="display: flex; align-items: center; gap: 20px;"> <img src="./logo.png" alt="Read_PDF Logo" width="100" style="flex-shrink: 0;"> <div> ReadPDFx is a comprehensive MCP (Model Context Protocol) server that provides intelligent OCR and PDF processing capabilities using the official MCP SDK with STDIO transport. It automatically detects whether a PDF contains digital text or scanned images and applies the appropriate processing method. </div> </div>

⚡ Quick Start (STDIO Server)

1. Install Dependencies

pip install -r requirements.txt

2. Validate Installation

# Test imports and tools
python validate_tools.py

3. Client Integration

The server runs via STDIO protocol - configure your MCP client:

Claude Desktop:

{
  "mcpServers": {
    "ocr-pdf": {
      "command": "python",
      "args": ["d:/AI/MCP/python/ocr_pdf_mcp/mcp_server_stdio.py"],
      "env": {}
    }
  }
}

🚀 Features

  • 🎯 Official MCP SDK: Built with official FastMCP framework
  • 📡 STDIO Transport: Standard MCP protocol over STDIO
  • 🧠 Smart PDF Processing: Automatically detects digital vs scanned content
  • 🔧 5 OCR Tools: Text extraction, OCR processing, combined operations
  • 🌐 Universal Client Support: Claude Desktop, LM Studio, Continue.dev, Cursor
  • ⚡ Lightweight: ~200 lines vs 800+ in HTTP implementation
  • 🛡️ Production Ready: Comprehensive error handling and logging
  • 📋 Auto Tool Registration: Decorators handle tool discovery

🔧 Installation

Prerequisites

  • Python 3.8+
  • Tesseract OCR

Windows

# Install Python dependencies
pip install -r requirements.txt

# Install Tesseract
choco install tesseract

macOS

pip install -r requirements.txt
brew install tesseract

Linux

pip install -r requirements.txt
sudo apt-get install tesseract-ocr

📋 Available Tools

1. Smart PDF Processing

Intelligent processing with automatic OCR detection:

{
  "name": "process_pdf_smart",
  "arguments": {
    "pdf_path": "/path/to/document.pdf",
    "language": "eng"
  }
}

2. PDF Text Extraction

Direct text extraction from digital PDFs:

{
  "name": "extract_pdf_text", 
  "arguments": {
    "pdf_path": "/path/to/document.pdf",
    "page_range": "1-5"
  }
}

3. OCR Processing

OCR on image files:

{
  "name": "perform_ocr",
  "arguments": {
    "image_path": "/path/to/image.png",
    "language": "eng"
  }
}

4. PDF Structure Analysis

Analyze document structure and metadata:

{
  "name": "analyze_pdf_structure",
  "arguments": {
    "pdf_path": "/path/to/document.pdf"
  }
}

5. Batch Processing

Process multiple files:

{
  "name": "batch_process_pdfs",
  "arguments": {
    "input_directory": "/path/to/pdfs/",
    "output_directory": "/path/to/output/",
    "file_pattern": "*.pdf"
  }
}

🔌 Client Integration

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "readpdfx": {
      "command": "python",
      "args": ["path/to/readpdfx/run.py"],
      "env": {
        "PYTHONPATH": "path/to/readpdfx"
      }
    }
  }
}

LM Studio

Configure MCP server with:

  • Command: python
  • Args: path/to/readpdfx/run.py
  • URL: http://localhost:8000 (HTTP mode)

Continue.dev

Add to config.json:

{
  "contextProviders": [
    {
      "name": "mcp",
      "params": {
        "command": "python",
        "args": ["path/to/readpdfx/run.py"]
      }
    }
  ]
}

Cursor

Configure in settings.json:

{
  "mcp.servers": {
    "readpdfx": {
      "command": "python",
      "args": ["path/to/readpdfx/run.py"]
    }
  }
}

📁 See client-configs/ for detailed integration guides.

🌐 API Endpoints

MCP Protocol Endpoints

  • POST /mcp/initialize - Initialize MCP session
  • POST /mcp/tools/list - List available tools
  • POST /mcp/tools/call - Call MCP tools
  • GET /mcp/manifest - Get MCP manifest

HTTP Endpoints

  • GET /health - Health check
  • POST /jsonrpc - JSON-RPC 2.0 endpoint
  • GET /docs - API documentation
  • GET /tools - Tools discovery

🔧 Configuration

Environment Variables

MCP_SERVER_HOST=localhost      # Server host
MCP_SERVER_PORT=8000           # Server port  
TESSERACT_CMD=/usr/bin/tesseract  # Tesseract path
PYTHONPATH=.                   # Python path

Config Files

  • mcp.json - MCP Protocol configuration
  • mcp-config.yaml - YAML configuration
  • pyproject.toml - Python project config
  • package.json - Node.js compatibility

🐳 Docker & Kubernetes

Docker Deployment

Quick Start with Docker

# Build and run with Docker
docker build -t ocr-pdf-mcp .
docker run -p 8000:8000 -v ./pdf-test:/app/pdf-test:ro ocr-pdf-mcp

# Or use Docker Compose
docker-compose up -d

Automated Docker Deployment

# Linux/macOS
./scripts/docker-deploy.sh run

# Windows
scripts\docker-deploy.bat run

Available Docker commands:

  • build - Build Docker image only
  • run - Build and run container (default)
  • start - Start container (assumes image exists)
  • stop - Stop running container
  • logs - Show container logs
  • clean - Stop container and remove image
  • status - Show container status

Kubernetes Deployment

Deploy to Kubernetes

# Quick deployment
./scripts/k8s-deploy.sh deploy

# Manual deployment
kubectl apply -f k8s/ -n ocr-pdf-mcp

Kubernetes Resources

  • Deployment: k8s/deployment.yaml - Main application deployment
  • Service: k8s/deployment.yaml - Service exposure
  • Ingress: k8s/ingress.yaml - External access
  • ConfigMap: k8s/configmap.yaml - Configuration management
  • HPA: k8s/hpa.yaml - Horizontal Pod Autoscaler

Kubernetes Commands

# Scale deployment
kubectl scale deployment ocr-pdf-mcp --replicas=5 -n ocr-pdf-mcp

# Port forward for local access
kubectl port-forward svc/ocr-pdf-mcp-service 8000:80 -n ocr-pdf-mcp

# View logs
kubectl logs -f deployment/ocr-pdf-mcp -n ocr-pdf-mcp

# Check status
kubectl get pods,svc,ingress -n ocr-pdf-mcp

Production Considerations

Multi-stage Build

Use Dockerfile.prod for optimized production builds:

docker build -f Dockerfile.prod -t ocr-pdf-mcp:prod .

Environment Variables

# Docker
docker run -e LOG_LEVEL=INFO -e CORS_ORIGINS="*" ocr-pdf-mcp

# Kubernetes - update ConfigMap
kubectl edit configmap ocr-pdf-mcp-config -n ocr-pdf-mcp

Persistent Storage

# Add to deployment.yaml
volumeMounts:
- name: pdf-storage
  mountPath: /app/pdf-test
volumes:
- name: pdf-storage
  persistentVolumeClaim:
    claimName: pdf-storage-pvc

🧪 Testing

Run Tests

python test_mcp_server.py

Manual Testing

# Health check
curl http://localhost:8000/health

# List tools  
curl -X POST http://localhost:8000/mcp/tools/list \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'

# Call tool
curl -X POST http://localhost:8000/mcp/tools/call \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0", 
    "method": "tools/call",
    "params": {
      "name": "process_pdf_smart",
      "arguments": {"pdf_path": "/path/to/test.pdf"}
    },
    "id": 1
  }'

📊 Performance

  • Startup Time: < 2 seconds
  • Memory Usage: ~50MB base
  • Throughput: 10+ PDFs/minute
  • Concurrent Requests: Up to 100
  • File Size Limit: 100MB per file

🛠️ Development

Development Mode

python run_server.py --dev --port 8000

Project Structure

readpdfx/
├── run.py                 # Simple production runner
├── run_server.py          # Advanced runner with options  
├── mcp_server.py          # Core MCP server
├── mcp_tools.py           # MCP tools implementation
├── mcp_types.py           # MCP Protocol types
├── mcp_server_runner.py   # HTTP server runner
├── client-configs/        # Client integration guides
├── backup/                # Legacy files
└── tests/                 # Test files

Adding New Tools

  1. Define tool schema in mcp_tools.py
  2. Implement tool handler method
  3. Register tool in MCPToolsRegistry
  4. Update tests and documentation

🐛 Troubleshooting

Common Issues

Server won't start

# Check port availability
netstat -an | grep 8000

# Try different port
python run_server.py --port 8001

OCR not working

# Check Tesseract installation
tesseract --version

# Install language data
tesseract --list-langs

Permission errors

  • Ensure read access to PDF files
  • Check write permissions for output directory
  • Run with appropriate user privileges

Connection timeout

  • Verify server is running: curl http://localhost:8000/health
  • Check firewall settings
  • Try HTTP instead of direct MCP connection

Debug Mode

python run_server.py --dev

📈 Monitoring

Health Check

curl http://localhost:8000/health

Metrics (Future)

  • Request count and latency
  • Tool usage statistics
  • Error rates and types
  • Resource utilization

🤝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/new-tool
  3. Make changes and add tests
  4. Submit pull request

Development Setup

git clone https://github.com/irev/mcp-readpdfx.git
cd readpdfx
pip install -r requirements-dev.txt
python test_mcp_server.py

📄 License

MIT License - see LICENSE file.

🔗 Links

  • Repository: https://github.com/irev/mcp-readpdfx
  • Issues: https://github.com/irev/mcp-readpdfx/issues
  • Documentation: https://github.com/irev/mcp-readpdfx#readme
  • MCP Protocol: Model Context Protocol Specification

🏆 Acknowledgments

  • MCP Protocol Team for the specification
  • FastAPI for the web framework
  • Tesseract OCR for text recognition
  • PyPDF2 and pdfplumber for PDF processing

Made with ❤️ for the MCP community

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选