mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-02 15:51:49 +01:00
📡 refactor: MCP Runtime Config Sync with Redis Distributed Locking (#10352)
* 🔄 Refactoring: MCP Runtime Configuration Reload
- PrivateServerConfigs own cache classes (inMemory and Redis).
- Connections staleness detection by comparing (connection.createdAt and config.LastUpdatedAt)
- ConnectionsRepo access Registry instead of in memory config dict and renew stale connections
- MCPManager: adjusted init of ConnectionsRepo (app level)
- UserConnectionManager: renew stale connections
- skipped test, to test "should only clear keys in its own namespace"
- MCPPrivateServerLoader: new component to manage logic of loading / editing private servers on runtime
- PrivateServersLoadStatusCache to track private server cache status
- New unit and integration tests.
Misc:
- add es lint rule to enforce line between class methods
* Fix cluster mode batch update and delete workarround. Fixed unit tests for cluster mode.
* Fix Keyv redis clear cache namespace awareness issue + Integration tests fixes
* chore: address copilot comments
* Fixing rebase issue: removed the mcp config fallback in single getServerConfig method:
- to not to interfere with the logic of the right Tier (APP/USER/Private)
- If userId is null, the getServerConfig should not return configs that are a SharedUser tier and not APP tier
* chore: add dev-staging branch to workflow triggers for backend, cache integration, and ESLint checks
---------
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
This commit is contained in:
parent
52e6796635
commit
ac68e629e6
49 changed files with 5244 additions and 257 deletions
|
|
@ -40,8 +40,7 @@ export class MCPManager extends UserConnectionManager {
|
|||
/** Initializes the MCPManager by setting up server registry and app connections */
|
||||
public async initialize(configs: t.MCPServers) {
|
||||
await MCPServersInitializer.initialize(configs);
|
||||
const appConfigs = await registry.sharedAppServers.getAll();
|
||||
this.appConnections = new ConnectionsRepository(appConfigs);
|
||||
this.appConnections = new ConnectionsRepository(undefined);
|
||||
}
|
||||
|
||||
/** Retrieves an app-level or user-specific connection based on provided arguments */
|
||||
|
|
@ -53,8 +52,10 @@ export class MCPManager extends UserConnectionManager {
|
|||
flowManager?: FlowStateManager<MCPOAuthTokens | null>;
|
||||
} & Omit<t.OAuthConnectionOptions, 'useOAuth' | 'user' | 'flowManager'>,
|
||||
): Promise<MCPConnection> {
|
||||
if (this.appConnections!.has(args.serverName)) {
|
||||
return this.appConnections!.get(args.serverName);
|
||||
//the get method checks if the config is still valid as app level
|
||||
const existingAppConnection = await this.appConnections!.get(args.serverName);
|
||||
if (existingAppConnection) {
|
||||
return existingAppConnection;
|
||||
} else if (args.user?.id) {
|
||||
return this.getUserConnection(args as Parameters<typeof this.getUserConnection>[0]);
|
||||
} else {
|
||||
|
|
@ -83,11 +84,10 @@ export class MCPManager extends UserConnectionManager {
|
|||
serverName: string,
|
||||
): Promise<t.LCAvailableTools | null> {
|
||||
try {
|
||||
if (this.appConnections?.has(serverName)) {
|
||||
return MCPServerInspector.getToolFunctions(
|
||||
serverName,
|
||||
await this.appConnections.get(serverName),
|
||||
);
|
||||
//try get the appConnection (if the config is not in the app level anymore any existing connection will disconnect and get will return null)
|
||||
const existingAppConnection = await this.appConnections?.get(serverName);
|
||||
if (existingAppConnection) {
|
||||
return MCPServerInspector.getToolFunctions(serverName, existingAppConnection);
|
||||
}
|
||||
|
||||
const userConnections = this.getUserConnections(userId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue