-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
executable file
·142 lines (125 loc) · 3.67 KB
/
test.js
File metadata and controls
executable file
·142 lines (125 loc) · 3.67 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
#!/usr/bin/env node
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// Path to the MCP server executable
const serverPath = './dist/index.js';
// Start the MCP server as a child process
console.log('Starting Base MCP Server...');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', process.stderr]
});
// Create readline interface for user input
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
// Sample MCP tool call in JSON format
const createToolCall = (name, args) => {
return JSON.stringify({
jsonrpc: '2.0',
id: Date.now().toString(),
method: 'callTool',
params: {
name,
arguments: args
}
}) + '\n';
};
// Get list of tools
const getToolsList = () => {
return JSON.stringify({
jsonrpc: '2.0',
id: Date.now().toString(),
method: 'listTools',
params: {}
}) + '\n';
};
// Wait for server to start
setTimeout(() => {
console.log('\n=== Base MCP Server Test Client ===');
console.log('Fetching available tools...');
// Get list of tools
server.stdin.write(getToolsList());
// Show menu after a short delay
setTimeout(() => {
console.log('Available commands:');
console.log('1. Create a wallet');
console.log('2. Check wallet balance');
console.log('3. Send transaction');
console.log('4. Process natural language command');
console.log('5. Exit');
promptUser();
}, 1000);
}, 1000);
// Handle server output
server.stdout.on('data', (data) => {
try {
const response = JSON.parse(data.toString());
if (response.result && response.result.content) {
console.log('\nServer Response:');
console.log(response.result.content[0].text);
} else {
console.log('\nRaw Server Response:', data.toString());
}
promptUser();
} catch (error) {
console.log('\nRaw Server Output:', data.toString());
promptUser();
}
});
// Prompt user for input
function promptUser() {
rl.question('\nEnter command number: ', (answer) => {
switch (answer) {
case '1':
rl.question('Enter wallet name (optional): ', (name) => {
const args = name ? { name } : {};
server.stdin.write(createToolCall('create_wallet', args));
});
break;
case '2':
rl.question('Enter wallet name or address (optional): ', (wallet) => {
const args = wallet ? { wallet } : {};
server.stdin.write(createToolCall('check_balance', args));
});
break;
case '3':
rl.question('Enter recipient address: ', (to) => {
rl.question('Enter amount in ETH: ', (amount) => {
rl.question('Enter sender wallet name (optional): ', (from) => {
const args = {
to,
amount,
...(from ? { from } : {})
};
server.stdin.write(createToolCall('process_command', {
command: `Send ${amount} ETH to ${to}${from ? ` from ${from}` : ''}`
}));
});
});
});
break;
case '4':
rl.question('Enter natural language command: ', (command) => {
server.stdin.write(createToolCall('process_command', { command }));
});
break;
case '5':
console.log('Exiting...');
server.kill();
rl.close();
process.exit(0);
break;
default:
console.log('Invalid command. Please try again.');
promptUser();
}
});
}
// Handle process termination
process.on('SIGINT', () => {
console.log('\nShutting down...');
server.kill();
rl.close();
process.exit(0);
});