UNPKG

purchase-mcp-server

Version:

Purchase and budget management server handling requisitions, purchase orders, expenses, budgets, and vendor management with ERP access for data extraction

57 lines 1.64 kB
import { Client } from 'typesense'; import { logger } from './logger.js'; import { config } from './config.js'; let client = null; /** * Initialize Typesense client connection * This should be called during server startup */ export function initializeConnection() { if (!client) { try { client = new Client({ nodes: [{ host: config.typesenseHost, port: parseInt(config.typesensePort, 10), protocol: config.typesenseProtocol }], apiKey: config.typesenseApiKey, connectionTimeoutSeconds: 2 }); logger.info('Initialized Typesense client'); } catch (error) { logger.error('Error initializing Typesense client:', error); throw error; } } return client; } /** * Get Typesense client * If not already initialized, this will initialize the client */ export function getTypesenseClient() { if (!client) { return initializeConnection(); } return client; } /** * Close Typesense connection * This should be called during server shutdown */ export async function closeConnection() { if (client) { try { // Typesense doesn't have a direct close method, but we can nullify the client client = null; logger.info('Closed Typesense connection'); } catch (error) { logger.error('Error closing Typesense connection:', error); throw error; } } } //# sourceMappingURL=typesense.js.map