-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp_server.js
More file actions
97 lines (83 loc) · 2.43 KB
/
test_mcp_server.js
File metadata and controls
97 lines (83 loc) · 2.43 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
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
// Start the MCP server
console.log('Starting MCP server...');
const server = spawn('cargo', ['run', '--package', 'ricegrep', '--', 'mcp'], {
cwd: __dirname,
stdio: ['pipe', 'pipe', 'inherit']
});
let messageId = 1;
let responses = [];
// Send initialize message
function sendInitialize() {
const message = {
jsonrpc: "2.0",
id: messageId++,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
};
console.log('Sending initialize message:', JSON.stringify(message, null, 2));
server.stdin.write(JSON.stringify(message) + '\n');
}
// Send tools/list message
function sendToolsList() {
const message = {
jsonrpc: "2.0",
id: messageId++,
method: "tools/list"
};
console.log('Sending tools/list message:', JSON.stringify(message, null, 2));
server.stdin.write(JSON.stringify(message) + '\n');
}
// Send tools/call message
function sendToolsCall() {
const message = {
jsonrpc: "2.0",
id: messageId++,
method: "tools/call",
params: {
name: "search",
arguments: {
pattern: "fn main",
path: ".",
ai_enhanced: true
}
}
};
console.log('Sending tools/call message:', JSON.stringify(message, null, 2));
server.stdin.write(JSON.stringify(message) + '\n');
}
// Handle server responses
server.stdout.on('data', (data) => {
const response = data.toString().trim();
console.log('Server response:', response);
responses.push(response);
try {
const parsed = JSON.parse(response);
console.log('Parsed response:', JSON.stringify(parsed, null, 2));
} catch (e) {
console.log('Failed to parse response as JSON');
}
});
server.on('close', (code) => {
console.log(`Server exited with code ${code}`);
console.log('Total responses received:', responses.length);
process.exit(0);
});
// Send messages with delays
setTimeout(sendInitialize, 2000);
setTimeout(sendToolsList, 4000);
setTimeout(sendToolsCall, 6000);
// Exit after 10 seconds
setTimeout(() => {
console.log('Timeout reached, killing server...');
server.kill();
}, 10000);