emotions-mcp-server
Version:
MCP Server for accessing PostgreSQL emotions database
63 lines (62 loc) • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmotionsDbService = exports.EmotionsMcpServer = void 0;
const server_1 = require("./server");
Object.defineProperty(exports, "EmotionsMcpServer", { enumerable: true, get: function () { return server_1.EmotionsMcpServer; } });
const database_1 = require("./database");
Object.defineProperty(exports, "EmotionsDbService", { enumerable: true, get: function () { return database_1.EmotionsDbService; } });
if (require.main === module) {
// Check if the connection string is provided as an argument
let connectionString;
if (process.argv.length > 2) {
const arg = process.argv[2];
if (arg.startsWith('file:')) {
// Extract the file path after 'file:'
const filePath = arg.substring(5);
try {
connectionString = require('fs').readFileSync(filePath, 'utf8').trim();
}
catch (error) {
console.error(`Error reading connection string from file "${filePath}":`, error);
process.exit(1);
}
}
else if (arg.startsWith('env:')) {
// Extract the environment variable name after 'env:'
const envVarName = arg.substring(4);
const envValue = process.env[envVarName];
if (!envValue) {
console.error(`Error: Environment variable "${envVarName}" not found`);
process.exit(1);
}
connectionString = envValue;
}
else {
// Direct connection string
connectionString = arg;
}
}
else {
connectionString = process.env.DATABASE_URL || 'postgresql://postgres:password@localhost:5432/emotions';
}
const server = new server_1.EmotionsMcpServer(connectionString);
server.start()
.catch(err => {
console.error('Failed to start server:', err);
process.exit(1);
});
// Handle graceful shutdown
const shutdown = async () => {
try {
await server.stop();
process.exit(0);
}
catch (error) {
console.error('Error during shutdown:', error);
process.exit(1);
}
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
}