# MCP Server Installation & Testing Guide
## ๐ง Installation Steps
### 1. Install Dependencies (with Official MCP SDK)
```bash
# Install required packages
pip install "mcp[cli]>=1.2.0" httpx PyMuPDF pdf2image pytesseract Pillow python-dotenv
# Or use requirements.txt
pip install -r requirements.txt
```
### 2. Install Tesseract OCR
**Windows:**
- Download from: https://github.com/UB-Mannheim/tesseract/wiki
- Default install path: `C:\Program Files\Tesseract-OCR\tesseract.exe`
**Linux:**
```bash
sudo apt-get install tesseract-ocr tesseract-ocr-eng
```
**macOS:**
```bash
brew install tesseract
```
### 3. Test the New MCP Server
#### Option A: Test STDIO Server (Recommended)
```bash
# Test directly
python ocr_mcp_server.py
# Should show logging output and wait for STDIO input
```
#### Option B: Test with Mock MCP Client
```bash
# Install MCP CLI tools
pip install "mcp[cli]"
# Test tools list
echo '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}' | python ocr_mcp_server.py
```
## ๐ฏ Client Configuration
### Claude Desktop
Update `~/Library/Application Support/Claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"ocr-pdf": {
"command": "python",
"args": [
"/absolute/path/to/ocr_pdf_mcp/ocr_mcp_server.py"
],
"env": {
"PYTHONPATH": "/absolute/path/to/ocr_pdf_mcp"
}
}
}
}
```
### LM Studio
1. Go to **Settings** โ **Extensions** โ **MCP Servers**
2. Add new server:
- **Name**: `ocr-pdf`
- **Command**: `python`
- **Arguments**: `/absolute/path/to/ocr_pdf_mcp/ocr_mcp_server.py`
- **Environment**: `PYTHONPATH=/absolute/path/to/ocr_pdf_mcp`
## ๐ Available Tools
1. **process_pdf_smart** - Intelligent PDF processing (digital text + OCR fallback)
2. **extract_pdf_text** - Digital text extraction only
3. **perform_ocr** - OCR on images/scanned documents
4. **analyze_pdf_structure** - PDF metadata and structure analysis
5. **batch_process_pdfs** - Process multiple PDFs in directory
## ๐งช Testing Examples
### Test with Claude Desktop
After configuring, test with these prompts:
- "Extract text from this PDF file: /path/to/document.pdf"
- "Process all PDFs in directory: /path/to/pdfs/"
- "Analyze the structure of this PDF: /path/to/file.pdf"
### Direct Function Test
```python
# Test the functions directly
from ocr_pdf_mcp.pdf_text_extractor import extract_text_from_pdf
result = extract_text_from_pdf("test.pdf")
print(result)
```
## ๐ Migration from HTTP Server
If you were using the old HTTP server (`run.py`), here are the changes:
### Before (HTTP Server):
- Complex FastAPI implementation
- HTTP endpoints: `/mcp/initialize`, `/mcp/tools/list`, etc.
- Required web client for testing
### After (STDIO Server):
- Simple FastMCP implementation
- Direct STDIO communication
- Works with all MCP clients (Claude Desktop, LM Studio, etc.)
- Much smaller codebase (~200 lines vs 800+ lines)
### Configuration Changes:
```json
// OLD (HTTP)
{
"command": "python",
"args": ["run.py"],
"env": {
"MCP_SERVER_HOST": "localhost",
"MCP_SERVER_PORT": "8000"
}
}
// NEW (STDIO)
{
"command": "python",
"args": ["ocr_mcp_server.py"],
"env": {
"PYTHONPATH": "/path/to/project"
}
}
```
## ๐ Troubleshooting
### Common Issues:
1. **"Module not found" errors**
- Check PYTHONPATH is set correctly
- Ensure all dependencies are installed
2. **Tesseract not found**
- Install Tesseract OCR
- Update path in `ocr_pdf_mcp/config.py`
3. **Permission errors**
- Ensure Python has read access to PDF files
- Check file paths are absolute
4. **MCP client not detecting server**
- Restart MCP client after configuration
- Check file paths are absolute
- Verify Python environment has all dependencies
### Debug Mode:
```bash
# Run with debug logging
PYTHONPATH=. python ocr_mcp_server.py --debug
```
## โ
Verification Checklist
- [ ] Dependencies installed (`pip install "mcp[cli]" httpx ...`)
- [ ] Tesseract OCR installed and accessible
- [ ] `ocr_mcp_server.py` runs without errors
- [ ] Client configuration updated with absolute paths
- [ ] Client restarted after configuration
- [ ] Test PDFs accessible from server
## ๐ Performance Notes
- **STDIO server**: Much faster startup (~1-2 seconds)
- **HTTP server**: Slower startup (~5-10 seconds)
- **Memory usage**: STDIO uses ~50% less memory
- **Tool response time**: Similar performance for actual processing
The new STDIO implementation is the **official MCP standard** and provides better compatibility with all MCP clients.