Skip to content

Commit 3954b89

Browse files
committed
🔃 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.
1 parent 952bfc4 commit 3954b89

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

‎api/server/controllers/PluginController.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ const getAvailableTools = async (req, res) => {
146146
const userPlugins = convertMCPToolsToPlugins(cachedUserTools, customConfig);
147147

148148
if (cachedToolsArray && userPlugins) {
149-
const dedupedTools = [
150-
...new Map(
151-
[...userPlugins, ...cachedToolsArray].map((tool) => [tool.pluginKey, tool]),
152-
).values(),
153-
];
149+
const dedupedTools = filterUniquePlugins([...userPlugins, ...cachedToolsArray]);
154150
res.status(200).json(dedupedTools);
155151
return;
156152
}
@@ -230,9 +226,7 @@ const getAvailableTools = async (req, res) => {
230226
const finalTools = filterUniquePlugins(toolsOutput);
231227
await cache.set(CacheKeys.TOOLS, finalTools);
232228

233-
const dedupedTools = [
234-
...new Map([...userPlugins, ...finalTools].map((tool) => [tool.pluginKey, tool])).values(),
235-
];
229+
const dedupedTools = filterUniquePlugins([...userPlugins, ...finalTools]);
236230

237231
res.status(200).json(dedupedTools);
238232
} catch (error) {
@@ -295,8 +289,4 @@ function convertMCPToolsToPlugins(functionTools, customConfig) {
295289
module.exports = {
296290
getAvailableTools,
297291
getAvailablePluginsController,
298-
filterUniquePlugins,
299-
checkPluginAuth,
300-
createServerToolsCallback,
301-
createGetServerTools,
302292
};

‎api/server/services/initializeMCPs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ async function initializeMCPs(app) {
5959
await mcpManager.mapAvailableTools(toolsCopy, flowManager);
6060
await setCachedTools(toolsCopy, { isGlobal: true });
6161

62+
const cache = getLogStores(CacheKeys.CONFIG_STORE);
63+
await cache.delete(CacheKeys.TOOLS);
64+
logger.debug('Cleared tools array cache after MCP initialization');
65+
6266
logger.info('MCP servers initialized successfully');
6367
} catch (error) {
6468
logger.error('Failed to initialize MCP servers:', error);

0 commit comments

Comments
 (0)