emotions-mcp-server
Version:
MCP Server for accessing PostgreSQL emotions database
69 lines (61 loc) • 1.92 kB
text/typescript
import { EmotionsMcpServer } from './server';
import { EmotionsDbService } from './database';
import { Emotion, EmotionFilter, EmotionRecord, SourceType } from './types';
export {
EmotionsMcpServer,
EmotionsDbService,
Emotion,
EmotionFilter,
EmotionRecord,
SourceType
};
if (require.main === module) {
// Check if the connection string is provided as an argument
let connectionString: string;
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 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);
}