#!/usr/bin/env node
// Test the MCP upscale_image tool
import { spawn } from 'child_process';
import readline from 'readline';
// Create a test for the MCP server
const mcpProcess = spawn('node', ['src/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, COMFYUI_HOST: 'comfyui', COMFYUI_PORT: '8188' }
});
const rl = readline.createInterface({
input: mcpProcess.stdout,
output: process.stdout,
terminal: false
});
let requestId = 1;
// Handle MCP server output
rl.on('line', (line) => {
try {
const response = JSON.parse(line);
console.log('Response:', JSON.stringify(response, null, 2));
if (response.result && response.result.content) {
response.result.content.forEach(item => {
if (item.type === 'text') {
console.log('Result:', item.text);
} else if (item.type === 'image') {
console.log('Image data received (base64 length):', item.data.length);
}
});
}
} catch (e) {
// Not JSON, just log it
if (line.trim()) console.log('Server:', line);
}
});
mcpProcess.stderr.on('data', (data) => {
const msg = data.toString();
if (msg.includes('running on stdio')) {
console.log('MCP server started, sending initialize...');
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'test-client', version: '1.0.0' }
});
}
});
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: requestId++,
method,
params
};
console.log('Sending:', method);
mcpProcess.stdin.write(JSON.stringify(request) + '\n');
}
// Test sequence
setTimeout(() => {
console.log('\n=== Testing upscale_image tool ===');
sendRequest('tools/call', {
name: 'upscale_image',
arguments: {
image_path: 'flux_output_00001_.png',
model: 'ultrasharp',
scale_factor: 1.0
}
});
}, 1000);
// Test with AnimeSharp after a delay
setTimeout(() => {
console.log('\n=== Testing with AnimeSharp model ===');
sendRequest('tools/call', {
name: 'upscale_image',
arguments: {
image_path: 'bg_removed_00001_.png',
model: 'animesharp',
scale_factor: 1.0
}
});
}, 15000);
// Exit after tests
setTimeout(() => {
console.log('\nTests completed, exiting...');
mcpProcess.kill();
process.exit(0);
}, 30000);