-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·72 lines (60 loc) · 2.18 KB
/
Copy pathcli.js
File metadata and controls
executable file
·72 lines (60 loc) · 2.18 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
#!/usr/bin/env node
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { spawn } from 'node:child_process';
import { createRequire } from 'node:module';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const require = createRequire(import.meta.url);
// Parse command line arguments
const args = process.argv.slice(2);
const httpMode = args.includes('--http') || args.includes('-h');
// Parse wallet mode argument
let walletMode = null;
const walletModeIndex = args.findIndex(arg => arg === '--wallet-mode');
if (walletModeIndex !== -1 && walletModeIndex + 1 < args.length) {
walletMode = args[walletModeIndex + 1];
}
// Set environment variables based on CLI arguments
if (walletMode) {
const validModes = ['private-key', 'disabled'];
if (validModes.includes(walletMode)) {
process.env.WALLET_MODE = walletMode;
} else {
console.error(`Invalid wallet mode: ${walletMode}. Valid modes are: ${validModes.join(', ')}`);
process.exit(1);
}
}
// Determine which file to execute
const scriptPath = resolve(__dirname, '../dist/esm', httpMode ? '/server/http-server.js' : 'index.js');
try {
// Check if the built files exist
require.resolve(scriptPath);
// Execute the server
const server = spawn('node', [scriptPath], {
stdio: 'inherit',
shell: false
});
server.on('error', (err) => {
console.error('Failed to start server:', err);
process.exit(1);
});
// Handle clean shutdown
const cleanup = () => {
if (!server.killed) {
server.kill();
}
};
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);
process.on('exit', cleanup);
} catch (error) {
console.error('Error: Server files not found. The package may not be built correctly.');
console.error('Please try reinstalling the package or contact the maintainers.');
console.error('\nUsage:');
console.error(' mcp-server # Start in STDIO mode (default)');
console.error(' mcp-server --http # Start in HTTP mode');
console.error(' mcp-server --wallet-mode MODE # Set wallet mode (private-key|dynamic|porto|disabled)');
console.error(error);
process.exit(1);
}