mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
- 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.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
const { EventSource } = require('eventsource');
|
|
const { Time } = require('librechat-data-provider');
|
|
const { MCPManager, FlowStateManager } = require('@librechat/api');
|
|
const logger = require('./winston');
|
|
|
|
global.EventSource = EventSource;
|
|
|
|
/** @type {MCPManager} */
|
|
let mcpManager = null;
|
|
let flowManager = null;
|
|
|
|
/**
|
|
* @param {string} [userId] - Optional user ID, to avoid disconnecting the current user.
|
|
* @param {boolean} [skipIdleCheck] - Skip idle connection checking to avoid unnecessary pings.
|
|
* @returns {MCPManager}
|
|
*/
|
|
function getMCPManager(userId, skipIdleCheck = false) {
|
|
if (!mcpManager) {
|
|
mcpManager = MCPManager.getInstance();
|
|
} else if (!skipIdleCheck) {
|
|
mcpManager.checkIdleConnections(userId);
|
|
}
|
|
return mcpManager;
|
|
}
|
|
|
|
/**
|
|
* @param {Keyv} flowsCache
|
|
* @returns {FlowStateManager}
|
|
*/
|
|
function getFlowStateManager(flowsCache) {
|
|
if (!flowManager) {
|
|
flowManager = new FlowStateManager(flowsCache, {
|
|
ttl: Time.ONE_MINUTE * 3,
|
|
});
|
|
}
|
|
return flowManager;
|
|
}
|
|
|
|
module.exports = {
|
|
logger,
|
|
getMCPManager,
|
|
getFlowStateManager,
|
|
};
|