test-bridge.jsโข2.85 kB
#!/usr/bin/env node
// Test script for the MCP bridge
const { spawn } = require('child_process');
const path = require('path');
async function testMcpBridge() {
console.log('๐งช Testing MCP Bridge...\n');
// Set environment variables
process.env.MCP_SERVER_URL = 'http://localhost:5000';
process.env.MCP_USERNAME = 'admin';
process.env.MCP_PASSWORD = 'password123';
// Start the bridge
const bridge = spawn('node', ['mcp-bridge.js'], {
cwd: __dirname,
stdio: ['pipe', 'pipe', 'pipe']
});
// Test messages
const testMessages = [
{
jsonrpc: "2.0",
id: "1",
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "Test Client",
version: "1.0.0"
}
}
},
{
jsonrpc: "2.0",
id: "2",
method: "tools/list"
},
{
jsonrpc: "2.0",
id: "3",
method: "tools/call",
params: {
name: "echo",
arguments: {
message: "Hello from MCP bridge test!"
}
}
}
];
let responseCount = 0;
bridge.stdout.on('data', (data) => {
const responses = data.toString().trim().split('\n');
responses.forEach(response => {
if (response.trim()) {
try {
const parsed = JSON.parse(response);
console.log(`๐จ Response ${++responseCount}:`);
console.log(JSON.stringify(parsed, null, 2));
console.log('');
} catch (e) {
console.log(`๐จ Raw response: ${response}`);
}
}
});
// End test after all responses
if (responseCount >= testMessages.length) {
bridge.kill();
}
});
bridge.stderr.on('data', (data) => {
console.error(`โ Bridge error: ${data}`);
});
bridge.on('close', (code) => {
console.log(`๐ Bridge test completed with code ${code}`);
});
// Send test messages with delay
for (let i = 0; i < testMessages.length; i++) {
setTimeout(() => {
const message = JSON.stringify(testMessages[i]) + '\n';
console.log(`๐ค Sending message ${i + 1}: ${testMessages[i].method}`);
bridge.stdin.write(message);
}, i * 1000);
}
// Timeout after 10 seconds
setTimeout(() => {
console.log('โฐ Test timeout - killing bridge');
bridge.kill();
}, 10000);
}
if (require.main === module) {
testMcpBridge().catch(console.error);
}