-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
executable file
·79 lines (69 loc) · 1.89 KB
/
test.js
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
#!/usr/bin/env node
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Path to the MCP server script
const mcpServerPath = path.join(__dirname, 'bin', 'probe-docs-mcp');
// Sample MCP request
const mcpRequest = {
jsonrpc: '2.0',
id: '1',
method: 'mcp.callTool',
params: {
name: 'search_docs',
arguments: {
query: 'installation',
maxResults: 5,
maxTokens: 2000
}
}
};
// Start the MCP server
console.log('Starting MCP server...');
const mcpServer = spawn(mcpServerPath, [], {
stdio: ['pipe', 'pipe', process.stderr]
});
// Handle server output
let buffer = '';
mcpServer.stdout.on('data', (data) => {
buffer += data.toString();
// Check if we have a complete JSON response
try {
const lines = buffer.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line && line.startsWith('{') && line.endsWith('}')) {
const response = JSON.parse(line);
console.log('\nReceived response:');
console.log(JSON.stringify(response, null, 2));
// Exit after receiving the response
console.log('\nTest completed successfully!');
mcpServer.kill();
process.exit(0);
}
}
} catch (error) {
// Not a complete JSON response yet, continue buffering
}
});
// Send the request after a short delay to allow the server to start
setTimeout(() => {
console.log('\nSending request:');
console.log(JSON.stringify(mcpRequest, null, 2));
mcpServer.stdin.write(JSON.stringify(mcpRequest) + '\n');
}, 1000);
// Handle server exit
mcpServer.on('exit', (code) => {
if (code !== 0) {
console.error(`MCP server exited with code ${code}`);
process.exit(code);
}
});
// Handle process termination
process.on('SIGINT', () => {
mcpServer.kill();
process.exit(0);
});