Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔧 fix: Invalidate Tool Caching after MCP Initialization (#8384)

Danny Avila8523074e8781
diff --git a/api/server/controllers/PluginController.js b/api/server/controllers/PluginController.js
index f7aad84aeb..a0af142938 100644
--- a/api/server/controllers/PluginController.js
+++ b/api/server/controllers/PluginController.js
@@ -1,11 +1,10 @@
const { logger } = require('@librechat/data-schemas');
-const { CacheKeys, AuthType } = require('librechat-data-provider');
+const { CacheKeys, AuthType, Constants } = require('librechat-data-provider');
const { getCustomConfig, getCachedTools } = require('~/server/services/Config');
const { getToolkitKey } = require('~/server/services/ToolService');
const { getMCPManager, getFlowStateManager } = require('~/config');
const { availableTools } = require('~/app/clients/tools');
const { getLogStores } = require('~/cache');
-const { Constants } = require('librechat-data-provider');
/**
* Filters out duplicate plugins from the list of plugins.
@@ -140,9 +139,9 @@ function createGetServerTools() {
const getAvailableTools = async (req, res) => {
try {
const cache = getLogStores(CacheKeys.CONFIG_STORE);
- const cachedTools = await cache.get(CacheKeys.TOOLS);
- if (cachedTools) {
- res.status(200).json(cachedTools);
+ const cachedToolsArray = await cache.get(CacheKeys.TOOLS);
+ if (cachedToolsArray) {
+ res.status(200).json(cachedToolsArray);
return;
}
@@ -173,7 +172,7 @@ const getAvailableTools = async (req, res) => {
}
});
- const toolDefinitions = await getCachedTools({ includeGlobal: true });
+ const toolDefinitions = (await getCachedTools({ includeGlobal: true })) || {};
const toolsOutput = [];
for (const plugin of authenticatedPlugins) {
diff --git a/api/server/services/initializeMCP.js b/api/server/services/initializeMCP.js
index 98b87d156e..0ed82e6ea1 100644
--- a/api/server/services/initializeMCP.js
+++ b/api/server/services/initializeMCP.js
@@ -44,6 +44,9 @@ async function initializeMCP(app) {
await mcpManager.mapAvailableTools(toolsCopy, flowManager);
await setCachedTools(toolsCopy, { isGlobal: true });
+ const cache = getLogStores(CacheKeys.CONFIG_STORE);
+ await cache.delete(CacheKeys.TOOLS);
+ logger.debug('Cleared tools array cache after MCP initialization');
logger.info('MCP servers initialized successfully');
} catch (error) {
logger.error('Failed to initialize MCP servers:', error);