Repository navigation
Expand file tree
/
Copy pathtest-modern.js
More file actions
executable file
·120 lines (104 loc) · 2.72 KB
/
Copy pathtest-modern.js
File metadata and controls
executable file
·120 lines (104 loc) · 2.72 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
112
113
114
115
116
117
118
119
120
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Test the modern server implementation
async function testModernServer() {
console.log('Testing modern MCP server implementation...\n');
// Start the server
const serverPath = join(__dirname, 'dist', 'index-modern.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
let output = '';
let errorOutput = '';
server.stdout.on('data', (data) => {
output += data.toString();
});
server.stderr.on('data', (data) => {
errorOutput += data.toString();
});
// Send initialization request
const initRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '0.1.0',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Send tools/list request
setTimeout(() => {
const listRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/list',
params: {}
};
server.stdin.write(JSON.stringify(listRequest) + '\n');
}, 500);
// Send a test tool call
setTimeout(() => {
const toolCall = {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'tractatus_thinking',
arguments: {
operation: 'start',
concept: 'What is truth?',
depth_limit: 3
}
}
};
server.stdin.write(JSON.stringify(toolCall) + '\n');
}, 1000);
// Wait for responses and close
setTimeout(() => {
server.kill();
console.log('Server output:');
if (output) {
try {
const lines = output.split('\n').filter(l => l.trim());
lines.forEach(line => {
try {
const json = JSON.parse(line);
console.log(JSON.stringify(json, null, 2));
} catch {
console.log(line);
}
});
} catch {
console.log(output);
}
}
if (errorOutput) {
console.log('\nServer logs:');
console.log(errorOutput);
}
console.log('\n[SUCCESS] Test completed');
}, 2000);
}
// First build the modern implementation
console.log('Building modern implementation...');
const build = spawn('npx', ['tsup', 'src/index-modern.ts', '--format', 'esm', '--outDir', 'dist'], {
stdio: 'inherit'
});
build.on('close', (code) => {
if (code === 0) {
console.log('Build successful!\n');
testModernServer();
} else {
console.error('Build failed with code', code);
process.exit(1);
}
});