purchase-mcp-server
Version:
Purchase and budget management server handling requisitions, purchase orders, expenses, budgets, and vendor management with ERP access for data extraction
50 lines (42 loc) • 1.42 kB
JavaScript
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { Command } from 'commander';
import { readFileSync } from 'fs';
// Get package version from package.json
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
// Setup Commander
const program = new Command();
program
.name('purchase-mcp-server')
.description('Purchase and budget management MCP server')
.version(packageJson.version)
.allowUnknownOption() // Allow unknown options to be passed to the server
.option('--help', 'Display help information')
.action(() => {
// If --help is explicitly passed, show help and exit
if (program.opts().help) {
program.help();
return;
}
const serverPath = join(__dirname, '..', 'dist', 'index.js');
const args = process.argv.slice(2);
// Start the server process
const child = spawn('node', [serverPath, ...args], {
stdio: 'inherit',
shell: true
});
// Handle process events
child.on('error', (error) => {
console.error('Error starting server:', error);
process.exit(1);
});
child.on('exit', (code) => {
process.exit(code || 0);
});
});
// Parse arguments
program.parse(process.argv);