-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsimple-test.js
More file actions
executable file
·130 lines (109 loc) · 3.42 KB
/
simple-test.js
File metadata and controls
executable file
·130 lines (109 loc) · 3.42 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
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env node
/**
* Simple test script for checking ChuckNorris MCP server schema behavior
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// Add async main function to handle top-level awaits
async function main() {
// Start the server
const server = spawn('node', ['chucknorris-mcp-server.js'], {
stdio: ['pipe', 'pipe', 'inherit']
});
// Set up readline interface to read server stdout
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
// Process server responses
rl.on('line', (line) => {
try {
const response = JSON.parse(line);
console.log('\nSERVER RESPONSE:', JSON.stringify(response, null, 2));
// Extract and display schema description if available
if (response.id === 1 && response.result && response.result.tools) {
console.log('\nINITIAL SCHEMA DESCRIPTION:');
console.log(response.result.tools[0].description.substring(0, 100) + '...');
}
if (response.id === 3 && response.result && response.result.tools) {
console.log('\nUPDATED SCHEMA DESCRIPTION:');
console.log(response.result.tools[0].description.substring(0, 100) + '...');
}
} catch (error) {
console.log('Non-JSON output:', line);
}
});
try {
// Wait 1 second to let server initialize
await new Promise(resolve => setTimeout(resolve, 1000));
// Step 1: Send initialize request
const initRequest = {
jsonrpc: '2.0',
id: 0,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'simple-test',
version: '1.0.0'
}
}
};
console.log('Sending initialize request...');
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Wait for response
await new Promise(resolve => setTimeout(resolve, 1000));
// Step 2: Get initial schema
const listRequest = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {}
};
console.log('Requesting initial schema...');
server.stdin.write(JSON.stringify(listRequest) + '\n');
// Wait for response
await new Promise(resolve => setTimeout(resolve, 1000));
// Step 3: Call the tool
const callRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'chuckNorris',
arguments: {
llmName: 'ANTHROPIC'
}
}
};
console.log('Calling tool with llmName=ANTHROPIC...');
server.stdin.write(JSON.stringify(callRequest) + '\n');
// Wait for response
await new Promise(resolve => setTimeout(resolve, 1000));
// Step 4: Get updated schema
const secondListRequest = {
jsonrpc: '2.0',
id: 3,
method: 'tools/list',
params: {}
};
console.log('Requesting updated schema...');
server.stdin.write(JSON.stringify(secondListRequest) + '\n');
// Wait for response
await new Promise(resolve => setTimeout(resolve, 1000));
// Give more time for the final response to be processed
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('\nTest completed.');
} finally {
// Close resources and exit
rl.close();
server.kill('SIGKILL');
setTimeout(() => process.exit(0), 100);
}
}
// Run the test
main().catch(error => {
console.error('Test failed:', error);
process.exit(1);
});