-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-chat-integration.js
More file actions
300 lines (245 loc) Β· 13.1 KB
/
Copy pathtest-chat-integration.js
File metadata and controls
300 lines (245 loc) Β· 13.1 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env node
/**
* Test script for MCP Bridge Chat Integration
* Tests the new chat participant and language model tools integration
*/
const WebSocket = require('ws');
class ChatIntegrationTester {
constructor() {
this.mcpServerPort = 3056;
this.extensionPort = 3057;
this.results = [];
}
async runAllTests() {
console.log('π Starting MCP Bridge Chat Integration Tests...\n');
try {
// Test 1: Test MCP Server Tools List
await this.testMCPServerToolsList();
// Test 2: Test Chat Tools via MCP Server
await this.testChatToolsViaMCP();
// Test 3: Test Extension WebSocket
await this.testExtensionWebSocket();
// Test 4: Test Chat Participant Configuration
await this.testChatParticipantConfig();
// Show results
this.showResults();
} catch (error) {
console.error('β Test suite failed:', error.message);
process.exit(1);
}
}
async testMCPServerToolsList() {
console.log('π Test 1: MCP Server Tools List');
try {
const ws = new WebSocket(`ws://localhost:${this.mcpServerPort}`);
return new Promise((resolve, reject) => {
ws.on('open', () => {
const request = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list'
};
ws.send(JSON.stringify(request));
});
ws.on('message', (data) => {
try {
const response = JSON.parse(data.toString());
const tools = response.result?.tools || [];
// Check for chat tools
const expectedChatTools = [
'cursor_chat_with_ai',
'cursor_trigger_auto_agent',
'cursor_get_chat_history',
'start_ai_collaboration'
];
const foundChatTools = tools.filter(tool =>
expectedChatTools.includes(tool.name)
);
if (foundChatTools.length === expectedChatTools.length) {
this.results.push({ test: 'MCP Server Tools List', status: 'β
PASS', details: `Found all ${expectedChatTools.length} chat tools` });
} else {
this.results.push({ test: 'MCP Server Tools List', status: 'β FAIL', details: `Found ${foundChatTools.length}/${expectedChatTools.length} chat tools` });
}
console.log(` π Total tools: ${tools.length}`);
console.log(` π¬ Chat tools: ${foundChatTools.length}/${expectedChatTools.length}`);
console.log(` π§ Chat tools found: ${foundChatTools.map(t => t.name).join(', ')}\n`);
ws.close();
resolve();
} catch (error) {
reject(error);
}
});
ws.on('error', (error) => {
this.results.push({ test: 'MCP Server Tools List', status: 'β FAIL', details: `Connection error: ${error.message}` });
console.log(` β Connection failed: ${error.message}\n`);
resolve(); // Continue with other tests
});
});
} catch (error) {
this.results.push({ test: 'MCP Server Tools List', status: 'β FAIL', details: error.message });
console.log(` β Test failed: ${error.message}\n`);
}
}
async testChatToolsViaMCP() {
console.log('π¬ Test 2: Chat Tools via MCP Server');
try {
const ws = new WebSocket(`ws://localhost:${this.mcpServerPort}`);
return new Promise((resolve, reject) => {
ws.on('open', async () => {
// Test cursor_chat_with_ai tool
const chatRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'cursor_chat_with_ai',
arguments: {
message: 'Test message from Claude Desktop',
context: 'integration-test'
}
}
};
ws.send(JSON.stringify(chatRequest));
});
ws.on('message', (data) => {
try {
const response = JSON.parse(data.toString());
if (response.result) {
this.results.push({ test: 'Chat Tools via MCP', status: 'β
PASS', details: 'Chat tool executed successfully' });
console.log(` β
Chat tool response: ${JSON.stringify(response.result)}`);
} else if (response.error) {
this.results.push({ test: 'Chat Tools via MCP', status: 'β οΈ PARTIAL', details: `Tool executed with error: ${response.error.message}` });
console.log(` β οΈ Tool error (expected if extension not running): ${response.error.message}`);
}
ws.close();
resolve();
} catch (error) {
reject(error);
}
});
ws.on('error', (error) => {
this.results.push({ test: 'Chat Tools via MCP', status: 'β FAIL', details: `Connection error: ${error.message}` });
console.log(` β Connection failed: ${error.message}`);
resolve();
});
});
} catch (error) {
this.results.push({ test: 'Chat Tools via MCP', status: 'β FAIL', details: error.message });
console.log(` β Test failed: ${error.message}\n`);
}
console.log('');
}
async testExtensionWebSocket() {
console.log('π Test 3: Extension WebSocket Integration');
try {
const ws = new WebSocket(`ws://localhost:${this.extensionPort}`);
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
this.results.push({ test: 'Extension WebSocket', status: 'β οΈ PARTIAL', details: 'Extension WebSocket not running (expected when extension not loaded)' });
console.log(` β οΈ Extension WebSocket not available (extension may not be loaded)\n`);
resolve();
}, 3000);
ws.on('open', () => {
clearTimeout(timeout);
// Test chat integration message
const testMessage = {
method: 'cursor_chat_with_ai',
params: {
message: 'Test message for chat integration',
context: 'websocket-test'
},
id: Date.now()
};
ws.send(JSON.stringify(testMessage));
});
ws.on('message', (data) => {
try {
const response = JSON.parse(data.toString());
this.results.push({ test: 'Extension WebSocket', status: 'β
PASS', details: 'Extension WebSocket responding correctly' });
console.log(` β
Extension response: ${JSON.stringify(response)}`);
ws.close();
resolve();
} catch (error) {
reject(error);
}
});
ws.on('error', (error) => {
clearTimeout(timeout);
this.results.push({ test: 'Extension WebSocket', status: 'β οΈ PARTIAL', details: 'Extension not running (expected when not loaded in Cursor)' });
console.log(` β οΈ Extension WebSocket error (expected): ${error.message}\n`);
resolve();
});
});
} catch (error) {
this.results.push({ test: 'Extension WebSocket', status: 'β FAIL', details: error.message });
console.log(` β Test failed: ${error.message}\n`);
}
}
async testChatParticipantConfig() {
console.log('βοΈ Test 4: Chat Participant Configuration');
try {
const fs = require('fs');
const path = require('path');
// Check if extension package.json has chat participant config
const packagePath = path.join(__dirname, 'extension-package.json');
if (fs.existsSync(packagePath)) {
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const chatParticipants = packageJson.contributes?.chatParticipants || [];
const mcpParticipant = chatParticipants.find(p => p.id === 'mcp-bridge.cursor-integration');
if (mcpParticipant) {
this.results.push({ test: 'Chat Participant Config', status: 'β
PASS', details: 'Chat participant properly configured' });
console.log(` β
Chat participant configured: ${mcpParticipant.name}`);
console.log(` π Description: ${mcpParticipant.description}`);
} else {
this.results.push({ test: 'Chat Participant Config', status: 'β FAIL', details: 'Chat participant not found in config' });
console.log(` β Chat participant not configured`);
}
} else {
this.results.push({ test: 'Chat Participant Config', status: 'β FAIL', details: 'Extension package.json not found' });
console.log(` β Extension package.json not found`);
}
// Check if compiled files exist
const outDir = path.join(__dirname, 'out');
const compiledFiles = [
'extension.js',
'chat-participant.js',
'language-model-tools.js'
];
const existingFiles = compiledFiles.filter(file =>
fs.existsSync(path.join(outDir, file))
);
console.log(` π¦ Compiled files: ${existingFiles.length}/${compiledFiles.length}`);
console.log(` ποΈ Files: ${existingFiles.join(', ')}\n`);
} catch (error) {
this.results.push({ test: 'Chat Participant Config', status: 'β FAIL', details: error.message });
console.log(` β Test failed: ${error.message}\n`);
}
}
showResults() {
console.log('π Test Results Summary:');
console.log('ββββββββββββββββββββββββββββββββββββββββ\n');
this.results.forEach(result => {
console.log(`${result.status} ${result.test}`);
console.log(` ${result.details}\n`);
});
const passed = this.results.filter(r => r.status.includes('β
')).length;
const partial = this.results.filter(r => r.status.includes('β οΈ')).length;
const failed = this.results.filter(r => r.status.includes('β')).length;
console.log(`π Summary: ${passed} passed, ${partial} partial, ${failed} failed`);
if (failed === 0) {
console.log('\nπ Chat Integration Implementation Complete!');
console.log('\nβ¨ Ready for Claude Desktop β Cursor AI communication!');
console.log('\nπ Next Steps:');
console.log('1. Install the extension in Cursor IDE');
console.log('2. Configure Claude Desktop with the MCP server');
console.log('3. Use @mcp-bridge in Cursor chat to test integration');
console.log('4. Try: @mcp-bridge /chat Create a React component');
console.log('5. Try: @mcp-bridge /agent Build a simple web app');
} else {
console.log('\nβ οΈ Some tests failed. Check the errors above.');
}
}
}
// Run the tests
const tester = new ChatIntegrationTester();
tester.runAllTests().catch(console.error);