#!/usr/bin/env pwsh
<#
.SYNOPSIS
Build OCR-MCP as MCPB package for distribution
.DESCRIPTION
Creates a complete MCPB package with all dependencies, models, and configuration
for easy installation and distribution.
.PARAMETER OutputDir
Output directory for the MCPB package (default: dist/)
.PARAMETER Version
Package version (default: from pyproject.toml)
.PARAMETER IncludeModels
Include pre-downloaded models in package (increases size significantly)
.PARAMETER Compress
Create compressed .mcpb archive
.EXAMPLE
.\build-mcpb.ps1 -OutputDir "C:\packages" -IncludeModels -Compress
.EXAMPLE
.\build-mcpb.ps1 -Version "1.0.0"
#>
param(
[string]$OutputDir = "dist",
[string]$Version,
[switch]$IncludeModels,
[switch]$Compress
)
# Configuration
$PackageName = "ocr-mcp"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectRoot = Split-Path -Parent $ScriptDir
# Ensure output directory exists
if (!(Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
}
Write-Host "🏗️ Building OCR-MCP MCPB Package..." -ForegroundColor Green
Write-Host "Output Directory: $OutputDir" -ForegroundColor Cyan
# Get version from pyproject.toml if not specified
if (!$Version) {
$PyProjectPath = Join-Path $ProjectRoot "pyproject.toml"
if (Test-Path $PyProjectPath) {
$PyProjectContent = Get-Content $PyProjectPath -Raw
if ($PyProjectContent -match 'version\s*=\s*"([^"]+)"') {
$Version = $matches[1]
}
}
if (!$Version) {
$Version = "1.0.0"
}
}
Write-Host "Package Version: $Version" -ForegroundColor Cyan
# Package directory
$PackageDir = Join-Path $OutputDir "$PackageName-$Version"
$McpbDir = Join-Path $PackageDir "mcpb"
# Clean previous build
if (Test-Path $PackageDir) {
Remove-Item $PackageDir -Recurse -Force
}
# Create package structure
Write-Host "Creating package structure..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path $McpbDir -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $McpbDir "src") -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $McpbDir "assets") -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $McpbDir "assets\prompts") -Force | Out-Null
# Copy MCPB files
Write-Host "Copying MCPB manifest and assets..." -ForegroundColor Yellow
Copy-Item (Join-Path $ProjectRoot "mcp-server\manifest.json") $McpbDir
Copy-Item (Join-Path $ProjectRoot "mcp-server\assets\*") (Join-Path $McpbDir "assets") -Recurse -Force
# Copy source code
Write-Host "Copying source code..." -ForegroundColor Yellow
$SrcDir = Join-Path $ProjectRoot "src"
$McpbSrcDir = Join-Path $McpbDir "src"
Copy-Item $SrcDir $McpbSrcDir -Recurse -Force
# Copy pyproject.toml and requirements
Write-Host "Copying Python dependencies..." -ForegroundColor Yellow
Copy-Item (Join-Path $ProjectRoot "pyproject.toml") $PackageDir
Copy-Item (Join-Path $ProjectRoot "requirements.txt") $PackageDir
# Create installation script
$InstallScript = @"
#!/usr/bin/env pwsh
<#
OCR-MCP Installation Script
This script installs OCR-MCP as an MCP server.
#>
param(
[string]`$InstallDir = "`$env:USERPROFILE\.mcp\servers\ocr-mcp",
[switch]`$Force
)
Write-Host "Installing OCR-MCP..." -ForegroundColor Green
# Check if already installed
if ((Test-Path `$InstallDir) -and -not `$Force) {
Write-Host "OCR-MCP is already installed at: `$InstallDir" -ForegroundColor Yellow
Write-Host "Use -Force to reinstall" -ForegroundColor Yellow
exit 0
}
# Create installation directory
if (Test-Path `$InstallDir) {
Remove-Item `$InstallDir -Recurse -Force
}
New-Item -ItemType Directory -Path `$InstallDir -Force | Out-Null
# Copy files
Write-Host "Copying files..." -ForegroundColor Yellow
Copy-Item "mcpb\*" `$InstallDir -Recurse -Force
Copy-Item "pyproject.toml" `$InstallDir
Copy-Item "requirements.txt" `$InstallDir
# Install dependencies
Write-Host "Installing Python dependencies..." -ForegroundColor Yellow
Push-Location `$InstallDir
try {
& python -m pip install -e .
} finally {
Pop-Location
}
Write-Host "OCR-MCP installed successfully!" -ForegroundColor Green
Write-Host "Installation directory: `$InstallDir" -ForegroundColor Cyan
"@
$InstallScript | Out-File (Join-Path $PackageDir "install.ps1") -Encoding UTF8
# Create README for package
$PackageReadme = @"
# OCR-MCP v$Version
Professional Document Processing Suite with 7 State-of-the-Art OCR Engines.
## Installation
Run the installation script:
```powershell
.\install.ps1
```
Or install manually:
```powershell
pip install -e .
```
## Configuration
Add to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"ocr-mcp": {
"command": "python",
"args": ["-m", "ocr_mcp.server"]
}
}
}
```
## Features
- 7 Advanced OCR Backends (Mistral OCR 3, DeepSeek-OCR, Florence-2, DOTS.OCR, PP-OCRv5, Qwen-Image-Layered, Tesseract)
- Direct Scanner Integration (WIA/TWAIN)
- Document Processing (PDF, CBZ, Images)
- Batch Processing with Progress Tracking
- Quality Assessment and Backend Comparison
- Web Interface for Professional Workflows
For full documentation, visit: https://github.com/sandraschi/ocr-mcp
"@
$PackageReadme | Out-File (Join-Path $PackageDir "README.md") -Encoding UTF8
# Optional: Include models (significantly increases package size)
if ($IncludeModels) {
Write-Host "Including pre-downloaded models..." -ForegroundColor Yellow
# This would require downloading models, which is complex
# For now, just note it in the manifest
}
# Create compressed archive if requested
if ($Compress) {
Write-Host "Creating compressed package..." -ForegroundColor Yellow
$ArchiveName = "$PackageName-$Version.mcpb"
$ArchivePath = Join-Path $OutputDir $ArchiveName
# Use 7zip if available, otherwise built-in Compress-Archive
try {
& 7z a $ArchivePath $PackageDir | Out-Null
Write-Host "Created compressed package: $ArchivePath" -ForegroundColor Green
} catch {
Compress-Archive -Path $PackageDir -DestinationPath $ArchivePath -CompressionLevel Optimal
Write-Host "Created compressed package: $ArchivePath" -ForegroundColor Green
}
}
Write-Host "✅ OCR-MCP MCPB package created successfully!" -ForegroundColor Green
Write-Host "Package location: $PackageDir" -ForegroundColor Cyan
if ($Compress) {
Write-Host "Compressed archive: $(Join-Path $OutputDir "$PackageName-$Version.mcpb")" -ForegroundColor Cyan
}
Write-Host "" -ForegroundColor White
Write-Host "To install on another system:" -ForegroundColor White
Write-Host "1. Copy the package directory to the target system" -ForegroundColor White
Write-Host "2. Run: .\install.ps1" -ForegroundColor White
Write-Host "3. Add to claude_desktop_config.json" -ForegroundColor White