mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
🔃 refactor: Simplify Plugin Deduplication and Clear Cache Post-MCP Initialization
- Replaced manual deduplication of tools with the dedicated `filterUniquePlugins` function for improved readability. - Added back cache clearing for tools after MCP initialization to ensure fresh data is used. - Removed unused exports from `PluginController.js` to clean up the codebase.
This commit is contained in:
parent
abafbfeefa
commit
94c329680f
2 changed files with 6 additions and 12 deletions
|
|
@ -146,11 +146,7 @@ const getAvailableTools = async (req, res) => {
|
|||
const userPlugins = convertMCPToolsToPlugins(cachedUserTools, customConfig);
|
||||
|
||||
if (cachedToolsArray && userPlugins) {
|
||||
const dedupedTools = [
|
||||
...new Map(
|
||||
[...userPlugins, ...cachedToolsArray].map((tool) => [tool.pluginKey, tool]),
|
||||
).values(),
|
||||
];
|
||||
const dedupedTools = filterUniquePlugins([...userPlugins, ...cachedToolsArray]);
|
||||
res.status(200).json(dedupedTools);
|
||||
return;
|
||||
}
|
||||
|
|
@ -230,9 +226,7 @@ const getAvailableTools = async (req, res) => {
|
|||
const finalTools = filterUniquePlugins(toolsOutput);
|
||||
await cache.set(CacheKeys.TOOLS, finalTools);
|
||||
|
||||
const dedupedTools = [
|
||||
...new Map([...userPlugins, ...finalTools].map((tool) => [tool.pluginKey, tool])).values(),
|
||||
];
|
||||
const dedupedTools = filterUniquePlugins([...userPlugins, ...finalTools]);
|
||||
|
||||
res.status(200).json(dedupedTools);
|
||||
} catch (error) {
|
||||
|
|
@ -295,8 +289,4 @@ function convertMCPToolsToPlugins(functionTools, customConfig) {
|
|||
module.exports = {
|
||||
getAvailableTools,
|
||||
getAvailablePluginsController,
|
||||
filterUniquePlugins,
|
||||
checkPluginAuth,
|
||||
createServerToolsCallback,
|
||||
createGetServerTools,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ async function initializeMCPs(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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue