@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI-native artifact management
68 lines • 3.04 kB
JavaScript
import { EventEmitter } from 'events';
import { Command } from 'commander';
import { McpServer } from './server/McpServer.js';
import { McpConfig } from './server/McpConfig.js';
import { LoggerFactory } from './logging/LoggerFactory.js';
// Increase max listeners to prevent AbortSignal memory leak warnings
// This is a safety net while we also implement proper cleanup
EventEmitter.defaultMaxListeners = 40;
async function main() {
const program = new Command();
program
.name('ucm-mcp-server')
.description('Universal Context Manager - Read the ucm_quickstart first to avoid mistakes')
.version('1.0.5')
.option('-u, --ucm-url <url>', 'UCM API base URL (defaults to https://ucm.utaba.ai)')
.option('-p, --port <port>', 'Server port', '3001')
.option('--log-level <level>', 'Log level', 'ERROR')
.option('--auth-token <token>', 'Authentication token for UCM API format is {auhtorid}:{apikey}. Get one from https://ucm.utaba.ai')
.option('--trusted-authors <authors>', 'Comma-separated list of trusted authors (e.g., "utaba,{anotherauthor}")', "utaba")
.parse();
const options = program.opts();
const config = new McpConfig({
ucmApiUrl: options.ucmUrl,
port: parseInt(options.port),
logLevel: options.logLevel,
authToken: options.authToken,
trustedAuthors: options.trustedAuthors ? options.trustedAuthors.split(',').map((a) => a.trim()) : ["utaba"]
});
// Set the log level in the factory before creating any loggers
LoggerFactory.setLogLevel(config.logLevel);
const logger = LoggerFactory.createLogger('MCP-Server');
const server = new McpServer(config, logger);
try {
await server.start();
logger.info('MCP-Server', 'UCM MCP Server started successfully');
}
catch (error) {
logger.error('MCP-Server', 'Failed to start UCM MCP Server', '', error);
process.exit(1);
}
// Graceful shutdown handlers
const gracefulShutdown = async (signal) => {
logger.info('MCP-Server', `Received ${signal}, shutting down UCM MCP Server...`);
try {
await server.stop();
logger.info('MCP-Server', 'UCM MCP Server shutdown complete');
process.exit(0);
}
catch (error) {
logger.error('MCP-Server', 'Error during shutdown', '', error);
process.exit(1);
}
};
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
// Handle uncaught exceptions and unhandled rejections
process.on('uncaughtException', (error) => {
logger.error('MCP-Server', 'Uncaught exception', '', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
logger.error('MCP-Server', 'Unhandled rejection', '', { reason, promise });
process.exit(1);
});
}
main().catch(console.error);
//# sourceMappingURL=index.js.map