mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20: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
|
|
@ -1,7 +1,7 @@
|
|||
import { logger } from '@librechat/data-schemas';
|
||||
import { MCPConnectionFactory } from '~/mcp/MCPConnectionFactory';
|
||||
import { MCPConnection } from './connection';
|
||||
import { mcpServersRegistry as registry } from '~/mcp/registry/MCPServersRegistry';
|
||||
import { MCPServersRegistry } from '~/mcp/registry/MCPServersRegistry';
|
||||
import type * as t from './types';
|
||||
|
||||
/**
|
||||
|
|
@ -25,7 +25,7 @@ export class ConnectionsRepository {
|
|||
|
||||
/** Checks whether this repository can connect to a specific server */
|
||||
async has(serverName: string): Promise<boolean> {
|
||||
const config = await registry.getServerConfig(serverName, this.ownerId);
|
||||
const config = await MCPServersRegistry.getInstance().getServerConfig(serverName, this.ownerId);
|
||||
const canConnect = !!config && this.isAllowedToConnectToServer(config);
|
||||
if (!canConnect) {
|
||||
//if connection is no longer possible we attempt to disconnect any leftover connections
|
||||
|
|
@ -36,7 +36,10 @@ export class ConnectionsRepository {
|
|||
|
||||
/** Gets or creates a connection for the specified server with lazy loading */
|
||||
async get(serverName: string): Promise<MCPConnection | null> {
|
||||
const serverConfig = await registry.getServerConfig(serverName, this.ownerId);
|
||||
const serverConfig = await MCPServersRegistry.getInstance().getServerConfig(
|
||||
serverName,
|
||||
this.ownerId,
|
||||
);
|
||||
|
||||
const existingConnection = this.connections.get(serverName);
|
||||
if (!serverConfig || !this.isAllowedToConnectToServer(serverConfig)) {
|
||||
|
|
@ -94,7 +97,7 @@ export class ConnectionsRepository {
|
|||
async getAll(): Promise<Map<string, MCPConnection>> {
|
||||
//TODO in the future we should use a scoped config getter (APPLevel, UserLevel, Private)
|
||||
//for now the absent config will not throw error
|
||||
const allConfigs = await registry.getAllServerConfigs(this.ownerId);
|
||||
const allConfigs = await MCPServersRegistry.getInstance().getAllServerConfigs(this.ownerId);
|
||||
return this.getMany(Object.keys(allConfigs));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue