mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🔧 fix: Invalidate Tool Caching after MCP Initialization (#8384)
- Added Constants import in PluginController for better organization. - Renamed cachedTools to cachedToolsArray for clarity in PluginController. - Ensured getCachedTools returns an empty object if no tools are found. - Cleared tools array cache after MCP initialization in initializeMCP for consistency.
This commit is contained in:
parent
e4531d682d
commit
8523074e87
2 changed files with 8 additions and 6 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
const { logger } = require('@librechat/data-schemas');
|
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 { getCustomConfig, getCachedTools } = require('~/server/services/Config');
|
||||||
const { getToolkitKey } = require('~/server/services/ToolService');
|
const { getToolkitKey } = require('~/server/services/ToolService');
|
||||||
const { getMCPManager, getFlowStateManager } = require('~/config');
|
const { getMCPManager, getFlowStateManager } = require('~/config');
|
||||||
const { availableTools } = require('~/app/clients/tools');
|
const { availableTools } = require('~/app/clients/tools');
|
||||||
const { getLogStores } = require('~/cache');
|
const { getLogStores } = require('~/cache');
|
||||||
const { Constants } = require('librechat-data-provider');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters out duplicate plugins from the list of plugins.
|
* Filters out duplicate plugins from the list of plugins.
|
||||||
|
|
@ -140,9 +139,9 @@ function createGetServerTools() {
|
||||||
const getAvailableTools = async (req, res) => {
|
const getAvailableTools = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
||||||
const cachedTools = await cache.get(CacheKeys.TOOLS);
|
const cachedToolsArray = await cache.get(CacheKeys.TOOLS);
|
||||||
if (cachedTools) {
|
if (cachedToolsArray) {
|
||||||
res.status(200).json(cachedTools);
|
res.status(200).json(cachedToolsArray);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +172,7 @@ const getAvailableTools = async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const toolDefinitions = await getCachedTools({ includeGlobal: true });
|
const toolDefinitions = (await getCachedTools({ includeGlobal: true })) || {};
|
||||||
|
|
||||||
const toolsOutput = [];
|
const toolsOutput = [];
|
||||||
for (const plugin of authenticatedPlugins) {
|
for (const plugin of authenticatedPlugins) {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ async function initializeMCP(app) {
|
||||||
await mcpManager.mapAvailableTools(toolsCopy, flowManager);
|
await mcpManager.mapAvailableTools(toolsCopy, flowManager);
|
||||||
await setCachedTools(toolsCopy, { isGlobal: true });
|
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');
|
logger.info('MCP servers initialized successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to initialize MCP servers:', error);
|
logger.error('Failed to initialize MCP servers:', error);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue