💾 chore: Enhance Local Storage Handling and Update MCP SDK (#6809)

* feat: Update MCP package version and dependencies; refactor ToolContentPart type

* refactor: Change module type to commonjs and update rollup configuration, remove unused dev dependency

* refactor: Change async calls to synchronous for MCP and FlowStateManager retrieval

* chore: Add eslint disable comment for i18next rule in DropdownPopup component

* fix: improve statefulness of mcp servers selected if some were removed since last session

* feat: implement conversation storage cleanup functions and integrate them into mutation success handlers

* feat: enhance storage condition logic in useLocalStorageAlt to prevent unnecessary local storage writes

* refactor: streamline local storage update logic in useLocalStorageAlt
This commit is contained in:
Danny Avila 2025-04-09 18:38:48 -04:00 committed by GitHub
parent 24c0433dcf
commit e16a6190a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 420 additions and 382 deletions

View file

@ -1,6 +1,7 @@
const axios = require('axios');
const { EventSource } = require('eventsource');
const { Time, CacheKeys } = require('librechat-data-provider');
const { MCPManager, FlowStateManager } = require('librechat-mcp');
const logger = require('./winston');
global.EventSource = EventSource;
@ -9,11 +10,10 @@ let mcpManager = null;
let flowManager = null;
/**
* @returns {Promise<MCPManager>}
* @returns {MCPManager}
*/
async function getMCPManager() {
function getMCPManager() {
if (!mcpManager) {
const { MCPManager } = await import('librechat-mcp');
mcpManager = MCPManager.getInstance(logger);
}
return mcpManager;
@ -21,11 +21,10 @@ async function getMCPManager() {
/**
* @param {(key: string) => Keyv} getLogStores
* @returns {Promise<FlowStateManager>}
* @returns {FlowStateManager}
*/
async function getFlowStateManager(getLogStores) {
function getFlowStateManager(getLogStores) {
if (!flowManager) {
const { FlowStateManager } = await import('librechat-mcp');
flowManager = new FlowStateManager(getLogStores(CacheKeys.FLOWS), {
ttl: Time.ONE_MINUTE * 3,
logger,

View file

@ -108,7 +108,7 @@ const getAvailableTools = async (req, res) => {
const pluginManifest = availableTools;
const customConfig = await getCustomConfig();
if (customConfig?.mcpServers != null) {
const mcpManager = await getMCPManager();
const mcpManager = getMCPManager();
await mcpManager.loadManifestTools(pluginManifest);
}

View file

@ -20,7 +20,7 @@ router.get('/:action_id/oauth/callback', async (req, res) => {
const { action_id } = req.params;
const { code, state } = req.query;
const flowManager = await getFlowStateManager(getLogStores);
const flowManager = getFlowStateManager(getLogStores);
let identifier = action_id;
try {
let decodedState;

View file

@ -189,7 +189,7 @@ async function createActionTool({
expires_at: Date.now() + Time.TWO_MINUTES,
},
};
const flowManager = await getFlowStateManager(getLogStores);
const flowManager = getFlowStateManager(getLogStores);
await flowManager.createFlowWithHandler(
`${identifier}:oauth_login:${config.metadata.thread_id}:${config.metadata.run_id}`,
'oauth_login',
@ -265,7 +265,7 @@ async function createActionTool({
encrypted_oauth_client_id: encrypted.oauth_client_id,
encrypted_oauth_client_secret: encrypted.oauth_client_secret,
});
const flowManager = await getFlowStateManager(getLogStores);
const flowManager = getFlowStateManager(getLogStores);
const refreshData = await flowManager.createFlowWithHandler(
`${identifier}:refresh`,
'oauth_refresh',

View file

@ -66,7 +66,7 @@ const AppService = async (app) => {
});
if (config.mcpServers != null) {
const mcpManager = await getMCPManager();
const mcpManager = getMCPManager();
await mcpManager.initializeMCP(config.mcpServers, processMCPEnv);
await mcpManager.mapAvailableTools(availableTools);
}

View file

@ -49,7 +49,7 @@ async function createMCPTool({ req, toolKey, provider }) {
/** @type {(toolArguments: Object | string, config?: GraphRunnableConfig) => Promise<unknown>} */
const _call = async (toolArguments, config) => {
try {
const mcpManager = await getMCPManager();
const mcpManager = getMCPManager();
const result = await mcpManager.callTool({
serverName,
toolName,