UNPKG

defect-inspection-tools-mcp-server

Version:

Defect inspection tools server handling defect detection, analysis, and reporting with AI/ML capabilities for quality control

70 lines 2.12 kB
import { MongoClient } from 'mongodb'; import { Client as TypesenseClient } from 'typesense'; import { config } from './config.js'; import { logger } from './logger.js'; export class MongoDBClient { constructor() { this._db = null; this.mongoClient = new MongoClient(config.mongoUri); } async connect() { try { await this.mongoClient.connect(); this._db = this.mongoClient.db('syia-etl-dev'); logger.info('Connected to MongoDB'); } catch (error) { logger.error('Failed to connect to MongoDB:', error); throw error; } } get db() { if (!this._db) { throw new Error('MongoDB not connected. Call connect() first.'); } return this._db; } async close() { await this.mongoClient.close(); this._db = null; logger.info('MongoDB connection closed'); } } export class TypesenseClientWrapper { constructor() { if (!config.typesenseHost || !config.typesensePort || !config.typesenseProtocol || !config.typesenseApiKey) { throw new Error('Typesense configuration is incomplete'); } this.typesenseClient = new TypesenseClient({ nodes: [{ host: config.typesenseHost, port: parseInt(config.typesensePort), protocol: config.typesenseProtocol }], apiKey: config.typesenseApiKey, connectionTimeoutSeconds: 2 }); } get collections() { return this.typesenseClient.collections; } get client() { return this.typesenseClient; } } // Singleton instances let mongoInstance = null; let typesenseInstance = null; export function getMongoClient() { if (!mongoInstance) { mongoInstance = new MongoDBClient(); } return mongoInstance; } export function getTypesenseClient() { if (!typesenseInstance) { typesenseInstance = new TypesenseClientWrapper(); } return typesenseInstance; } //# sourceMappingURL=clients.js.map