#!/usr/bin/env node
/**
* Simple test script for the SeedDream 4.0 FAL MCP Server
* This script helps verify that the server is working correctly
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Test messages to send to the server
const testMessages = [
// List available tools
{
jsonrpc: "2.0",
id: 1,
method: "tools/list"
},
// Test image generation (commented out to avoid API calls during testing)
/*
{
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "generate_image",
arguments: {
prompt: "a cute robot in a futuristic garden",
image_size: "square_1280",
num_images: 1,
enable_safety_checker: true
}
}
}
*/
];
async function testServer() {
console.log('Testing SeedDream 4.0 FAL MCP Server...\n');
// Check if build exists
const serverPath = join(__dirname, 'build', 'index.js');
try {
// Start the server process
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
FAL_KEY: process.env.FAL_KEY || 'test-key-for-listing-tools'
}
});
let responseCount = 0;
let responses = [];
// Handle server output
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
lines.forEach(line => {
try {
const response = JSON.parse(line);
responses.push(response);
responseCount++;
console.log(`Response ${responseCount}:`);
console.log(JSON.stringify(response, null, 2));
console.log('---\n');
// If we've received all expected responses, close the server
if (responseCount >= testMessages.length) {
server.kill();
}
} catch (e) {
// Ignore non-JSON output
}
});
});
// Handle server errors
server.stderr.on('data', (data) => {
const message = data.toString();
if (message.includes('running on stdio')) {
console.log('ā
SeedDream 4.0 server started successfully\n');
// Send test messages
testMessages.forEach((message, index) => {
console.log(`Sending test message ${index + 1}:`);
console.log(JSON.stringify(message, null, 2));
console.log('');
server.stdin.write(JSON.stringify(message) + '\n');
});
} else if (!message.includes('SeedDream')) {
console.error('Server stderr:', message);
}
});
// Handle server exit
server.on('close', (code) => {
console.log(`\nServer exited with code ${code}`);
if (responses.length > 0) {
console.log('\nā
Test completed successfully!');
console.log(`Received ${responses.length} response(s) from the server.`);
// Check if tools are listed correctly
const toolsResponse = responses.find(r => r.result && r.result.tools);
if (toolsResponse) {
const tools = toolsResponse.result.tools;
console.log(`\nš Available tools: ${tools.map(t => t.name).join(', ')}`);
// Verify SeedDream 4.0 specific features
const generateImageTool = tools.find(t => t.name === 'generate_image');
if (generateImageTool) {
console.log('\nš SeedDream 4.0 Features Detected:');
const schema = generateImageTool.inputSchema;
if (schema.properties.image_size) {
console.log(' ā
Flexible image sizing support');
}
if (schema.properties.max_images) {
console.log(' ā
Multi-image generation support');
}
if (schema.properties.enable_safety_checker) {
console.log(' ā
Safety checker support');
}
if (schema.properties.sync_mode) {
console.log(' ā
Sync mode support');
}
}
}
} else {
console.log('\nā No responses received from server');
}
});
// Handle server startup errors
server.on('error', (error) => {
console.error('ā Failed to start server:', error.message);
if (error.code === 'ENOENT') {
console.log('\nš” Make sure to build the server first:');
console.log(' npm run build');
}
});
// Timeout after 10 seconds
setTimeout(() => {
if (!server.killed) {
console.log('\nā° Test timeout - killing server');
server.kill();
}
}, 10000);
} catch (error) {
console.error('ā Test failed:', error.message);
process.exit(1);
}
}
// Run the test
testServer().catch(console.error);