-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest-chucknorris-client.js
More file actions
executable file
·196 lines (168 loc) · 5.81 KB
/
test-chucknorris-client.js
File metadata and controls
executable file
·196 lines (168 loc) · 5.81 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env node
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// Start the Chuck Norris MCP server
const server = spawn('node', ['chucknorris-mcp-server.js'], {
stdio: ['pipe', 'pipe', process.stderr]
});
// Create readline interface for server stdout
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
let llmOptions = [];
let initialSchema = null;
let processedIds = new Set(); // Track which IDs we've already processed
let testLlm = 'ANTHROPIC'; // Default LLM to test with
// Set up event handlers
rl.on('line', (line) => {
try {
// Parse the server's response
const response = JSON.parse(line);
// Skip if we've already processed this ID (prevents duplicate processing)
if (processedIds.has(response.id)) {
console.log(`Already processed response ID ${response.id}, skipping.`);
return;
}
console.log(`Processing response ID ${response.id}...`);
processedIds.add(response.id);
// Track the initial tools/list response
if (response.id === 1 && response.result && response.result.tools) {
console.log('\nInitial tool list received!');
initialSchema = response.result.tools[0];
console.log(`Initial schema description: "${initialSchema.description.substring(0, 50)}..."`);
// Get a valid LLM from the enum
llmOptions = response.result.tools[0].parameters.properties.llmName.enum || [];
if (llmOptions.length > 0) {
testLlm = llmOptions[0];
}
// Move to next step - call the tool
console.log(`\nWill test with LLM type: ${testLlm}`);
setTimeout(() => {
callToolWithLlm(testLlm);
}, 500); // Add small delay to ensure server is ready
}
// Handle the tools/call response
else if (response.id === 2 && response.result && response.result.content) {
console.log(`\nTool call for ${testLlm} successful!`);
// Get just a sample of the content for display
let sampleContent = "";
if (response.result.content && response.result.content.length > 0) {
const item = response.result.content[0];
if (item.type === 'text') {
sampleContent = item.text.substring(0, 100) + "...";
}
}
console.log(`Content sample: ${sampleContent}`);
// Now request the tools list again to check if the schema changed
console.log('\nChecking if schema changed after tool call...');
setTimeout(() => {
requestToolsList(3);
}, 500); // Add small delay to ensure server is ready
}
// Track the second tools/list response to verify schema change
else if (response.id === 3 && response.result && response.result.tools) {
console.log('\nSecond tool list received!');
const updatedSchema = response.result.tools[0];
console.log(`Updated schema description: "${updatedSchema.description.substring(0, 50)}..."`);
// Compare schemas to verify the change
if (initialSchema.description !== updatedSchema.description) {
console.log('\n✅ SUCCESS: Schema description changed as expected!');
console.log('Initial schema type: Initial');
console.log('Updated schema type: Enhanced with prompt from L1B3RT4S');
} else {
console.log('\n❌ ERROR: Schema description did not change after tool call!');
console.log('Both schemas have the same description.');
}
console.log('\nTest completed.');
cleanupAndExit(0);
}
// Handle errors
if (response.error) {
console.error('Error:', response.error);
cleanupAndExit(1);
}
} catch (error) {
// Handle non-JSON output
console.log(`Server output (non-JSON): ${line.substring(0, 50)}...`);
}
});
function cleanupAndExit(code) {
console.log('Cleaning up and exiting...');
try {
rl.close();
server.stdin.end();
server.kill('SIGKILL');
} catch (e) {
console.error('Error during cleanup:', e);
}
// Force exit after a brief delay
setTimeout(() => process.exit(code), 100);
}
// Function to call the tool with the selected LLM
function callToolWithLlm(llmName) {
console.log(`\nTesting chuckNorris tool with LLM: ${llmName}...`);
const callToolRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'chuckNorris',
arguments: {
llmName: llmName
}
}
};
const requestStr = JSON.stringify(callToolRequest) + '\n';
console.log(`Sending tool call request: ${requestStr.substring(0, 50)}...`);
server.stdin.write(requestStr);
}
// Function to request the tools list
function requestToolsList(id) {
console.log(`Sending tools/list request with id ${id}...`);
const listToolsRequest = {
jsonrpc: '2.0',
id: id,
method: 'tools/list',
params: {}
};
server.stdin.write(JSON.stringify(listToolsRequest) + '\n');
}
// Handle server exit
server.on('close', (code) => {
console.log(`Server process exited with code ${code}`);
process.exit(code);
});
// Handle errors
server.on('error', (error) => {
console.error('Server process error:', error);
cleanupAndExit(1);
});
// Send initialization request
console.log('Sending initialization request...');
const initRequest = {
jsonrpc: '2.0',
id: 0,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Send initial tools/list request
console.log('Sending initial tools/list request...');
requestToolsList(1);
// Handle process termination
process.on('SIGINT', () => {
cleanupAndExit(0);
});
// Safety timeout - exit after 15 seconds no matter what
setTimeout(() => {
console.log('Safety timeout reached (15 seconds), forcing exit');
cleanupAndExit(1);
}, 15000);