#!/usr/bin/env node
/**
* Simple MCP client to test the Infinigen MCP server
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const serverPath = join(__dirname, '..', 'dist', 'index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'inherit']
});
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
let messageId = 1;
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: messageId++,
method,
params
};
server.stdin.write(JSON.stringify(request) + '\n');
console.log('📤 Sent:', JSON.stringify(request, null, 2));
}
rl.on('line', (line) => {
if (line.trim()) {
console.log('📥 Received:', line);
try {
const response = JSON.parse(line);
console.log('✅ Parsed:', JSON.stringify(response, null, 2));
} catch (e) {
console.log('⚠️ Not JSON');
}
}
});
server.on('close', (code) => {
console.log(`\nServer exited with code ${code}`);
process.exit(code);
});
// Wait a bit for server to start
setTimeout(() => {
console.log('\n🔧 Testing MCP Server...\n');
// Test 1: Initialize
console.log('Test 1: Initialize');
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
});
setTimeout(() => {
// Test 2: List tools
console.log('\nTest 2: List tools');
sendRequest('tools/list');
}, 1000);
setTimeout(() => {
// Test 3: Call check_infinigen tool
console.log('\nTest 3: Call check_infinigen tool');
sendRequest('tools/call', {
name: 'check_infinigen',
arguments: {}
});
}, 2000);
setTimeout(() => {
console.log('\n✅ Tests complete!');
server.kill();
}, 3000);
}, 500);