mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🧰 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:
parent
a49b2b2833
commit
aba0a93d1d
5 changed files with 268 additions and 195 deletions
|
|
@ -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:',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue