-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-mcp-protocol.js
More file actions
executable file
·111 lines (96 loc) · 2.98 KB
/
test-mcp-protocol.js
File metadata and controls
executable file
·111 lines (96 loc) · 2.98 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
// Test MCP protocol communication
import { spawn } from 'child_process';
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
green: '\x1b[32m',
blue: '\x1b[34m',
cyan: '\x1b[36m'
};
function log(message, color = colors.reset) {
console.log(`${color}${message}${colors.reset}`);
}
async function testMCPProtocol() {
log('🧪 Testing MCP Protocol Communication', colors.cyan);
return new Promise((resolve) => {
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
let responseReceived = false;
let stdout = '';
let stderr = '';
server.stdout.on('data', (data) => {
const output = data.toString();
stdout += output;
try {
// Try to parse as JSON RPC response
const lines = output.split('\n').filter(line => line.trim());
for (const line of lines) {
if (line.trim()) {
const response = JSON.parse(line);
if (response.result && response.result.tools) {
log('✅ MCP Server responded with tools list', colors.green);
log(`Found ${response.result.tools.length} tools:`, colors.cyan);
response.result.tools.forEach(tool => {
log(` - ${tool.name}: ${tool.description}`, colors.blue);
});
responseReceived = true;
server.kill('SIGTERM');
return;
}
}
}
} catch (e) {
// Not JSON, might be startup message
if (output.includes('Codex MCP Server is running')) {
log('✅ Server started, sending tools request...', colors.green);
// Send list tools request
const request = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {}
};
server.stdin.write(JSON.stringify(request) + '\n');
}
}
});
server.stderr.on('data', (data) => {
stderr += data.toString();
});
server.on('close', (code) => {
if (responseReceived) {
log('✅ MCP Protocol test passed', colors.green);
resolve(true);
} else {
log('❌ MCP Protocol test failed', colors.red);
log(`Exit code: ${code}`, colors.red);
log('Stdout:', colors.blue);
console.log(stdout);
log('Stderr:', colors.red);
console.log(stderr);
resolve(false);
}
});
server.on('error', (error) => {
log(`❌ Server error: ${error.message}`, colors.red);
resolve(false);
});
// Timeout after 10 seconds
setTimeout(() => {
if (!responseReceived) {
log('❌ MCP Protocol test timeout', colors.red);
server.kill('SIGKILL');
resolve(false);
}
}, 10000);
});
}
// Run the test
testMCPProtocol().then(success => {
process.exit(success ? 0 : 1);
}).catch(error => {
console.error('Test error:', error);
process.exit(1);
});