UNPKG

@toolprint/hypertool-mcp

Version:

HyperTool MCP proxy server for routing requests between clients and multiple underlying MCP servers

77 lines • 2.5 kB
/** * File-based database service implementation * Uses JSON files for storage instead of NeDB */ import { FileServerConfigRecordRepository } from "./file/FileServerConfigRecordRepository.js"; import { FileServerConfigGroupRepository } from "./file/FileServerConfigGroupRepository.js"; import { NullConfigSourceRepository } from "./file/NullConfigSourceRepository.js"; import { createChildLogger } from "../utils/logging.js"; const logger = createChildLogger({ module: "FileDatabaseService" }); /** * File-based implementation of the database service */ export class FileDatabaseService { _servers; _groups; _configSources; isInitialized = false; /** * Get the servers repository */ get servers() { if (!this.isInitialized) { throw new Error("Database not initialized. Call init() first."); } return this._servers; } /** * Get the groups repository */ get groups() { if (!this.isInitialized) { throw new Error("Database not initialized. Call init() first."); } return this._groups; } /** * Get the config sources repository (stub for file-based) */ get configSources() { if (!this.isInitialized) { throw new Error("Database not initialized. Call init() first."); } return this._configSources; } /** * Initialize the database */ async init() { if (this.isInitialized) { logger.warn("Database already initialized"); return; } logger.debug("Initializing file-based database service"); // Initialize repositories const serverRepo = new FileServerConfigRecordRepository(); await serverRepo.init(); this._servers = serverRepo; const groupRepo = new FileServerConfigGroupRepository(this._servers); await groupRepo.init(); this._groups = groupRepo; this._configSources = new NullConfigSourceRepository(); this.isInitialized = true; logger.debug("File-based database initialized successfully"); } /** * Close the database (no-op for file-based) */ async close() { if (!this.isInitialized) { return; } // File-based storage doesn't need explicit closing this.isInitialized = false; logger.debug("File-based database closed successfully"); } } //# sourceMappingURL=fileDatabaseService.js.map