-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.js
More file actions
91 lines (76 loc) · 2.17 KB
/
test-client.js
File metadata and controls
91 lines (76 loc) · 2.17 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
// Simple test client for the MCP server
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('Starting Etherscan MCP Server test...\n');
// Start the server
const serverProcess = spawn('node', [join(__dirname, 'dist', 'index.js')], {
env: {
...process.env,
ETHERSCAN_API_KEY: 'YourApiKeyToken'
}
});
let buffer = '';
serverProcess.stdout.on('data', (data) => {
buffer += data.toString();
// Try to parse complete JSON messages
const lines = buffer.split('\n');
buffer = lines.pop(); // Keep incomplete line in buffer
for (const line of lines) {
if (line.trim()) {
try {
const message = JSON.parse(line);
console.log('Response:', JSON.stringify(message, null, 2));
} catch (e) {
console.log('Raw output:', line);
}
}
}
});
serverProcess.stderr.on('data', (data) => {
console.log('Server log:', data.toString().trim());
});
serverProcess.on('close', (code) => {
console.log(`\nServer process exited with code ${code}`);
process.exit(code);
});
// Wait for server to start
setTimeout(() => {
console.log('\n=== Test 1: List Tools ===');
const listToolsRequest = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {}
};
serverProcess.stdin.write(JSON.stringify(listToolsRequest) + '\n');
// Wait a bit then send another test
setTimeout(() => {
console.log('\n=== Test 2: Get Gas Oracle (will fail with dummy API key) ===');
const gasOracleRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'etherscan_gas_oracle',
arguments: {
chainid: '1'
}
}
};
serverProcess.stdin.write(JSON.stringify(gasOracleRequest) + '\n');
// Give time to process then exit
setTimeout(() => {
console.log('\n=== Tests complete, shutting down ===');
serverProcess.kill();
}, 2000);
}, 2000);
}, 1000);
// Handle Ctrl+C
process.on('SIGINT', () => {
console.log('\nShutting down...');
serverProcess.kill();
process.exit();
});