-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-mcp.js
More file actions
executable file
·153 lines (134 loc) · 4.16 KB
/
test-mcp.js
File metadata and controls
executable file
·153 lines (134 loc) · 4.16 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
#!/usr/bin/env node
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// Create a simple MCP client to test the server
async function main() {
console.log('Starting MCP test client');
// Start the MCP server as a child process
const server = spawn('node', ['mcp.js'], {
stdio: ['pipe', 'pipe', process.stderr],
env: { ...process.env, DEBUG: 'true' }
});
// Create readline interface for reading the server's stdout
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
// Track message IDs
let messageId = 0;
// Function to send a JSON-RPC message to the server
const send = (message) => {
console.log('CLIENT SENDING:', JSON.stringify(message));
server.stdin.write(JSON.stringify(message) + '\n');
};
// Set up event listeners
rl.on('line', (line) => {
if (line.trim()) {
try {
const response = JSON.parse(line);
console.log('CLIENT RECEIVED:', JSON.stringify(response));
// If this is the initialize response, send the initialized notification
if (response.id === 0) {
console.log('Sending initialized notification');
// Send initialized notification immediately
send({
jsonrpc: '2.0',
method: 'notifications/initialized'
});
// After initialization, immediately request the resources list
send({
jsonrpc: '2.0',
id: ++messageId,
method: 'resources/list'
});
}
// After resources/list, immediately request the tools list
if (response.id === 1) {
console.log('Requesting tools list');
send({
jsonrpc: '2.0',
id: ++messageId,
method: 'tools/list',
params: {}
});
}
// After tools/list, immediately test calling tools
if (response.id === 2 && response.result && response.result.tools) {
console.log(`Found ${response.result.tools.length} tools`);
// Test all available tools with basic arguments
const tools = response.result.tools;
// Start with LSTool as it's simple and reliable
const lsTool = tools.find(tool => tool.name === 'LSTool');
if (lsTool) {
console.log('Testing LSTool call');
send({
jsonrpc: '2.0',
id: ++messageId,
method: 'tools/call',
params: {
name: 'LSTool',
arguments: {
path: process.cwd()
}
}
});
}
// Test BashTool with a simple echo command
const bashTool = tools.find(tool => tool.name === 'BashTool');
if (bashTool) {
console.log('Testing BashTool call');
send({
jsonrpc: '2.0',
id: ++messageId,
method: 'tools/call',
params: {
name: 'BashTool',
arguments: {
command: 'echo "Testing MCP server with BashTool"'
}
}
});
}
}
} catch (error) {
console.error('Error parsing response:', error);
}
}
});
// Handle server process events
server.on('error', (error) => {
console.error('Server error:', error);
});
server.on('close', (code) => {
console.log(`Server process exited with code ${code}`);
process.exit(code);
});
// Send initialize request
send({
jsonrpc: '2.0',
id: messageId,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {
tools: {
listChanged: true
},
resources: {
subscribe: true,
listChanged: true
}
},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
});
// Keep the script running
console.log('Test client running. Press Ctrl+C to exit.');
}
main().catch(error => {
console.error('Unhandled error:', error);
process.exit(1);
});