-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest-client.js
More file actions
79 lines (67 loc) · 2.17 KB
/
Copy pathtest-client.js
File metadata and controls
79 lines (67 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { spawn } = require('child_process');
const path = require('path');
const serverPath = path.join(__dirname, 'src/server/mcpServer.js');
console.log(`Starting server: ${serverPath}`);
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'inherit'] // pipe stdin/stdout, inherit stderr for logs
});
let buffer = '';
server.stdout.on('data', (data) => {
const chunk = data.toString();
buffer += chunk;
if (buffer.includes('\n')) {
const lines = buffer.split('\n');
buffer = lines.pop(); // Keep last incomplete line
for (const line of lines) {
if (!line.trim()) continue;
try {
const msg = JSON.parse(line);
// console.log('Received:', JSON.stringify(msg, null, 2));
// Step 2: Handle Initialize Response
if (msg.id === 1 && msg.result) {
console.log('✅ Initialize successful.');
send({ jsonrpc: '2.0', method: 'notifications/initialized' });
console.log('Sending tools/list request...');
send({ jsonrpc: '2.0', id: 2, method: 'tools/list' });
}
// Step 3: Handle Tools List
if (msg.id === 2 && msg.result) {
console.log(`✅ Tools list received. Count: ${msg.result.tools.length}`);
const researchTool = msg.result.tools.find(t => t.name === 'research');
if (researchTool) {
console.log('✅ Research tool found.');
} else {
console.error('❌ Research tool MISSING!');
process.exit(1);
}
console.log('🎉 End-to-end test PASSED.');
server.kill();
process.exit(0);
}
} catch (e) {
// Ignore non-JSON lines
}
}
}
});
function send(msg) {
const str = JSON.stringify(msg);
// console.log('Sending:', str);
server.stdin.write(str + '\n');
}
// Step 1: Initialize
send({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'test-client', version: '1.0' }
}
});
setTimeout(() => {
console.error('❌ Timeout waiting for response');
server.kill();
process.exit(1);
}, 10000);