vnstock-mcp-server
Version:
MCP Server for Vietnamese Stock Market Data using vnstock library - NPX compatible wrapper
53 lines (42 loc) • 1.31 kB
JavaScript
/**
* NPX executable for vnstock-mcp-server
* Enables remote execution via: npx vnstock-mcp-server
*/
const path = require('path');
const { spawn } = require('child_process');
const fs = require('fs');
// Get the package directory
const packageDir = path.join(__dirname, '..');
const srcPath = path.join(packageDir, 'src', 'index.js');
// Check if we're running from a global install or NPX
const isGlobalInstall = __dirname.includes('node_modules');
if (isGlobalInstall) {
console.error('Starting vnstock MCP server...');
} else {
console.error('Running vnstock MCP server via NPX...');
}
// Execute the main Node.js entry point
const child = spawn('node', [srcPath], {
stdio: 'inherit',
cwd: packageDir
});
child.on('error', (error) => {
console.error('Failed to start vnstock MCP server:', error.message);
process.exit(1);
});
child.on('close', (code) => {
if (code !== 0) {
console.error(`vnstock MCP server exited with code ${code}`);
process.exit(code);
}
});
// Handle termination signals
process.on('SIGINT', () => {
console.error('\nShutting down vnstock MCP server...');
child.kill('SIGINT');
});
process.on('SIGTERM', () => {
console.error('\nTerminating vnstock MCP server...');
child.kill('SIGTERM');
});