UNPKG

@mseep/atlas-mcp-server

Version:

A Model Context Protocol (MCP) server for ATLAS, a Neo4j-powered task management system for LLM Agents - implementing a three-tier architecture (Projects, Tasks, Knowledge) to manage complex workflows.

76 lines (75 loc) 2.56 kB
import { EventEmitter } from 'events'; import { logger } from '../../utils/logger.js'; /** * Event types for database operations */ export var DatabaseEventType; (function (DatabaseEventType) { DatabaseEventType["WRITE_OPERATION"] = "write_operation"; DatabaseEventType["READ_OPERATION"] = "read_operation"; DatabaseEventType["TRANSACTION_COMPLETE"] = "transaction_complete"; DatabaseEventType["ERROR"] = "error"; })(DatabaseEventType || (DatabaseEventType = {})); /** * Database event system to facilitate communication between services * Uses the publish-subscribe pattern to decouple components */ class DatabaseEventSystem { constructor() { this.emitter = new EventEmitter(); // Set a higher limit for listeners to avoid warnings this.emitter.setMaxListeners(20); // Log all events in debug mode if (process.env.NODE_ENV === 'development') { this.emitter.on(DatabaseEventType.WRITE_OPERATION, (details) => { logger.debug('Database write operation', { details }); }); this.emitter.on(DatabaseEventType.ERROR, (error) => { logger.debug('Database event error', { error }); }); } } /** * Get the singleton instance */ static getInstance() { if (!DatabaseEventSystem.instance) { DatabaseEventSystem.instance = new DatabaseEventSystem(); } return DatabaseEventSystem.instance; } /** * Subscribe to a database event * @param eventType Event type to subscribe to * @param listener Function to call when the event occurs */ subscribe(eventType, listener) { this.emitter.on(eventType, listener); } /** * Unsubscribe from a database event * @param eventType Event type to unsubscribe from * @param listener Function to remove */ unsubscribe(eventType, listener) { this.emitter.off(eventType, listener); } /** * Publish a database event * @param eventType Event type to publish * @param data Event data */ publish(eventType, data) { this.emitter.emit(eventType, data); } /** * Subscribe to a database event only once * @param eventType Event type to subscribe to * @param listener Function to call when the event occurs */ subscribeOnce(eventType, listener) { this.emitter.once(eventType, listener); } } // Export singleton instance export const databaseEvents = DatabaseEventSystem.getInstance();