mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-31 23:58:50 +01:00
🔧 fix: Fix rampant pings and rate limiting
- Skips idle connection checks in `getMCPManager` to avoid unnecessary pings. - Introduces a skipOAuthTimeout flag during initial connection to prevent timeouts during server discovery. - Uses a lightweight connection state check instead of ping to avoid rate limits. - Prevents refetch spam and rate limit errors when checking connection status. - Fixes an issue where the server connection was not being disconnected.
This commit is contained in:
parent
1da5365397
commit
10e06f2221
9 changed files with 90 additions and 39 deletions
|
|
@ -97,7 +97,6 @@ function createServerToolsCallback() {
|
|||
return;
|
||||
}
|
||||
await mcpToolsCache.set(serverName, serverTools);
|
||||
logger.warn(`MCP tools for ${serverName} added to cache.`);
|
||||
} catch (error) {
|
||||
logger.error('Error retrieving MCP tools from cache:', error);
|
||||
}
|
||||
|
|
@ -240,7 +239,6 @@ const getAvailableTools = async (req, res) => {
|
|||
// Check if the app-level connection is active
|
||||
try {
|
||||
const mcpManager = getMCPManager();
|
||||
const allConnections = mcpManager.getAllConnections();
|
||||
|
||||
const appConnection = mcpManager.getConnection(serverName);
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ const updateUserPluginsController = async (req, res) => {
|
|||
`[updateUserPluginsController] Disconnecting MCP connection for user ${user.id} and server ${serverName} after plugin auth update for ${pluginKey}.`,
|
||||
);
|
||||
// Don't kill the server connection on revoke anymore, user can just reinitialize the server if thats what they want
|
||||
// await mcpManager.disconnectUserConnection(user.id, serverName);
|
||||
await mcpManager.disconnectUserConnection(user.id, serverName);
|
||||
}
|
||||
} catch (disconnectError) {
|
||||
logger.error(
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ router.get('/connection/status', requireJwtAuth, async (req, res) => {
|
|||
return res.status(401).json({ error: 'User not authenticated' });
|
||||
}
|
||||
|
||||
const mcpManager = getMCPManager();
|
||||
const mcpManager = getMCPManager(null, true); // Skip idle checks to avoid ping spam
|
||||
const connectionStatus = {};
|
||||
|
||||
// Get all MCP server names from custom config
|
||||
|
|
@ -237,12 +237,14 @@ router.get('/connection/status', requireJwtAuth, async (req, res) => {
|
|||
const userConnection = mcpManager.getUserConnectionIfExists(user.id, serverName);
|
||||
const hasUserConnection = !!userConnection;
|
||||
|
||||
// Determine if connected based on actual connection state
|
||||
// Use lightweight connection state check instead of ping-based isConnected()
|
||||
let connected = false;
|
||||
if (hasAppConnection) {
|
||||
connected = await appConnection.isConnected();
|
||||
// Check connection state without ping to avoid rate limits
|
||||
connected = appConnection.connectionState === 'connected';
|
||||
} else if (hasUserConnection) {
|
||||
connected = await userConnection.isConnected();
|
||||
// Check connection state without ping to avoid rate limits
|
||||
connected = userConnection.connectionState === 'connected';
|
||||
}
|
||||
|
||||
// Determine if this server requires user authentication
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue