mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🧬 refactor: Wire Database Methods into MCP Package via Registry Pattern (#10715)
* Refactor: MCPServersRegistry Singleton Pattern with Dependency Injection for DB methods consumption * refactor: error handling in MCP initialization and improve logging for MCPServersRegistry instance creation. - Added checks for mongoose instance in ServerConfigsDB constructor and refined error messages for clarity. - Reorder and use type imports --------- Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com> Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
da473bf43a
commit
ad6ba4b6d1
24 changed files with 328 additions and 150 deletions
|
|
@ -5,7 +5,7 @@ import { logger } from '@librechat/data-schemas';
|
|||
import { ParsedServerConfig } from '~/mcp/types';
|
||||
import { sanitizeUrlForLogging } from '~/mcp/utils';
|
||||
import type * as t from '~/mcp/types';
|
||||
import { mcpServersRegistry as registry } from './MCPServersRegistry';
|
||||
import { MCPServersRegistry } from './MCPServersRegistry';
|
||||
|
||||
const MCP_INIT_TIMEOUT_MS =
|
||||
process.env.MCP_INIT_TIMEOUT_MS != null ? parseInt(process.env.MCP_INIT_TIMEOUT_MS) : 30_000;
|
||||
|
|
@ -36,7 +36,7 @@ export class MCPServersInitializer {
|
|||
if (await isLeader()) {
|
||||
// Leader performs initialization
|
||||
await statusCache.reset();
|
||||
await registry.reset();
|
||||
await MCPServersRegistry.getInstance().reset();
|
||||
const serverNames = Object.keys(rawConfigs);
|
||||
await Promise.allSettled(
|
||||
serverNames.map((serverName) =>
|
||||
|
|
@ -59,7 +59,11 @@ export class MCPServersInitializer {
|
|||
/** Initializes a single server with all its metadata and adds it to appropriate collections */
|
||||
public static async initializeServer(serverName: string, rawConfig: t.MCPOptions): Promise<void> {
|
||||
try {
|
||||
const config = await registry.addServer(serverName, rawConfig, 'CACHE');
|
||||
const config = await MCPServersRegistry.getInstance().addServer(
|
||||
serverName,
|
||||
rawConfig,
|
||||
'CACHE',
|
||||
);
|
||||
MCPServersInitializer.logParsedConfig(serverName, config);
|
||||
} catch (error) {
|
||||
logger.error(`${MCPServersInitializer.prefix(serverName)} Failed to initialize:`, error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue