🧰 fix: Available Tools Retrieval with correct MCP Caching (#9181)

* fix: available tools retrieval with correct mcp caching and conversion

* test: Enhance PluginController tests with MCP tool mocking and conversion

* refactor: Simplify PluginController tests by removing unused mocks and enhancing test clarity
This commit is contained in:
Danny Avila 2025-08-20 22:33:54 -04:00 committed by GitHub
parent a49b2b2833
commit aba0a93d1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 268 additions and 195 deletions

View file

@ -4,6 +4,7 @@ const {
getToolkitKey,
checkPluginAuth,
filterUniquePlugins,
convertMCPToolToPlugin,
convertMCPToolsToPlugins,
} = require('@librechat/api');
const {
@ -107,16 +108,20 @@ const getAvailableTools = async (req, res) => {
if (customConfig?.mcpServers != null) {
try {
const mcpManager = getMCPManager();
const mcpTools = await mcpManager.loadAllManifestTools(userId);
const mcpToolsRecord = mcpTools.reduce((acc, tool) => {
pluginManifest.push(tool);
acc[tool.pluginKey] = tool;
if (!toolDefinitions[tool.pluginKey]) {
toolDefinitions[tool.pluginKey] = tool;
const mcpTools = await mcpManager.getAllToolFunctions(userId);
prelimCachedTools = prelimCachedTools ?? {};
for (const [toolKey, toolData] of Object.entries(mcpTools)) {
const plugin = convertMCPToolToPlugin({
toolKey,
toolData,
customConfig,
});
if (plugin) {
pluginManifest.push(plugin);
}
return acc;
}, prelimCachedTools ?? {});
await mergeUserTools({ userId, cachedUserTools, userTools: mcpToolsRecord });
prelimCachedTools[toolKey] = toolData;
}
await mergeUserTools({ userId, cachedUserTools, userTools: prelimCachedTools });
} catch (error) {
logger.error(
'[getAvailableTools] Error loading MCP Tools, servers may still be initializing:',