haloapi-mcp-tools
Version:
Model Context Protocol (MCP) server for interacting with the HaloPSA API
80 lines (71 loc) • 1.99 kB
JavaScript
#!/usr/bin/env node
/**
* HaloPSA MCP Server CLI
*
* Command-line interface for starting and managing the HaloPSA MCP Server.
*/
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const path = require('path');
const fs = require('fs');
const dotenv = require('dotenv');
// Configure command-line arguments
const argv = yargs(hideBin(process.argv))
.usage('Usage: $0 [options]')
.option('config', {
alias: 'c',
describe: 'Path to configuration file',
type: 'string'
})
.option('env', {
alias: 'e',
describe: 'Path to .env file',
type: 'string'
})
.option('baseUrl', {
describe: 'HaloPSA API base URL',
type: 'string'
})
.option('apiKey', {
describe: 'HaloPSA API key',
type: 'string'
})
.option('logLevel', {
describe: 'Logging level (debug, info, warn, error)',
type: 'string',
default: 'info'
})
.example('$0 --env .env.production', 'Start server with production environment')
.example('$0 --apiKey YOUR_API_KEY', 'Start server with specific API key')
.help()
.version()
.argv;
// Load environment variables from .env file if specified
if (argv.env) {
const envPath = path.resolve(process.cwd(), argv.env);
if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath });
console.log(`Loaded environment from ${envPath}`);
} else {
console.warn(`Warning: Environment file ${envPath} not found`);
}
} else {
// Load from default .env file if it exists
const defaultEnvPath = path.resolve(process.cwd(), '.env');
if (fs.existsSync(defaultEnvPath)) {
dotenv.config();
console.log('Loaded environment from .env');
}
}
// Override environment variables with command-line arguments
if (argv.baseUrl) {
process.env.HALOPSA_API_URL = argv.baseUrl;
}
if (argv.apiKey) {
process.env.HALOPSA_API_KEY = argv.apiKey;
}
if (argv.logLevel) {
process.env.LOG_LEVEL = argv.logLevel;
}
// Start the server
require('../src/index');