🔃 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:
Dustin Healy 2025-07-12 11:09:20 -07:00
parent abafbfeefa
commit 94c329680f
2 changed files with 6 additions and 12 deletions

View file

@ -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,
};

View file

@ -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);