#!/usr/bin/env node
/**
* Test OCR functionality with real image
*/
import { spawn } from 'child_process';
import { config } from 'dotenv';
config();
const server = spawn('node', ['dist/index.js'], {
env: { ...process.env },
stdio: ['pipe', 'pipe', 'pipe']
});
// Test with a public image containing text (using a Google Drive hosted image from Saptiva docs)
const request = {
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'saptiva_ocr',
arguments: {
image_url: 'https://drive.google.com/uc?export=download&id=1-EeTL10DJorpJsCnG5DCfS_7fx60pnGY',
prompt: 'Extract and describe all text content from this image.'
}
}
};
console.log('Testing OCR with SVG logo image...\n');
let buffer = '';
server.stdout.on('data', (data) => {
buffer += data.toString();
try {
const response = JSON.parse(buffer);
if (response.error) {
console.log('❌ Error:', response.error.message);
} else if (response.result) {
const content = response.result.content?.[0]?.text;
if (response.result.isError) {
console.log('❌ Tool Error:', content);
} else {
console.log('✅ OCR Result:');
console.log(content);
}
}
server.kill();
process.exit(0);
} catch {
// Incomplete
}
});
server.stderr.on('data', (data) => {
const msg = data.toString().trim();
if (msg && !msg.includes('running on stdio') && !msg.includes('injecting')) {
console.error('Server:', msg);
}
});
setTimeout(() => {
server.stdin.write(JSON.stringify(request) + '\n');
}, 1000);
setTimeout(() => {
console.log('Timeout');
server.kill();
process.exit(1);
}, 30000);