mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +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
19b78ecd81
commit
36e42abce1
49 changed files with 5244 additions and 257 deletions
|
|
@ -98,6 +98,12 @@ export class MCPConnection extends EventEmitter {
|
|||
timeout?: number;
|
||||
url?: string;
|
||||
|
||||
/**
|
||||
* Timestamp when this connection was created.
|
||||
* Used to detect if connection is stale compared to updated config.
|
||||
*/
|
||||
public readonly createdAt: number;
|
||||
|
||||
setRequestHeaders(headers: Record<string, string> | null): void {
|
||||
if (!headers) {
|
||||
return;
|
||||
|
|
@ -121,6 +127,7 @@ export class MCPConnection extends EventEmitter {
|
|||
this.iconPath = params.serverConfig.iconPath;
|
||||
this.timeout = params.serverConfig.timeout;
|
||||
this.lastPingTime = Date.now();
|
||||
this.createdAt = Date.now(); // Record creation timestamp for staleness detection
|
||||
if (params.oauthTokens) {
|
||||
this.oauthTokens = params.oauthTokens;
|
||||
}
|
||||
|
|
@ -736,6 +743,17 @@ export class MCPConnection extends EventEmitter {
|
|||
this.oauthTokens = tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this connection is stale compared to config update time.
|
||||
* A connection is stale if it was created before the config was updated.
|
||||
*
|
||||
* @param configUpdatedAt - Unix timestamp (ms) when config was last updated
|
||||
* @returns true if connection was created before config update, false otherwise
|
||||
*/
|
||||
public isStale(configUpdatedAt: number): boolean {
|
||||
return this.createdAt < configUpdatedAt;
|
||||
}
|
||||
|
||||
private isOAuthError(error: unknown): boolean {
|
||||
if (!error || typeof error !== 'object') {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue