-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
82 lines (69 loc) · 2.14 KB
/
test.js
File metadata and controls
82 lines (69 loc) · 2.14 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
80
81
82
#!/usr/bin/env node
// Simple test script to verify MCP server connection handling
const { spawn } = require('child_process');
const path = require('path');
console.log('Testing MCP server connection handling...');
// Start the MCP server
const serverProcess = spawn('node', ['cjs/scripts/serve.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: process.cwd()
});
let serverOutput = '';
let serverError = '';
serverProcess.stdout.on('data', (data) => {
const output = data.toString();
serverOutput += output;
console.log('Server stdout:', output.trim());
});
serverProcess.stderr.on('data', (data) => {
const error = data.toString();
serverError += error;
console.log('Server stderr:', error.trim());
});
serverProcess.on('close', (code) => {
console.log(`Server process exited with code ${code}`);
if (code === 0) {
console.log('✅ Server started and shut down gracefully');
} else {
console.log('❌ Server exited with error code');
}
// Check if our error handling messages are present
if (serverOutput.includes('MCP server connected successfully') ||
serverOutput.includes('Starting MCP server')) {
console.log('✅ Connection logging is working');
} else {
console.log('⚠️ Connection logging may not be working as expected');
}
});
serverProcess.on('error', (error) => {
console.error('Failed to start server process:', error);
});
// Send a test message to simulate MCP communication
setTimeout(() => {
console.log('Sending test message...');
serverProcess.stdin.write(JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
}) + '\n');
}, 1000);
// Gracefully shut down after 5 seconds
setTimeout(() => {
console.log('Sending SIGINT to test graceful shutdown...');
serverProcess.kill('SIGINT');
}, 5000);
// Force kill after 10 seconds if it doesn't shut down gracefully
setTimeout(() => {
if (!serverProcess.killed) {
console.log('Force killing server process...');
serverProcess.kill('SIGKILL');
}
}, 10000);