Feat/Implement caching for MCP toolkit in CachePool (#4897)

feat: Implement caching for MCP toolkit in CachePool

- Added methods to CachePool for managing MCP toolkit cache.
- Integrated caching logic in CustomMCP to store and retrieve toolkit data based on workspaceId and configuration.
- Updated node service to pass cachePool to CustomMCP for enhanced performance.
This commit is contained in:
Henry Heng
2025-07-18 19:07:48 +01:00
committed by GitHub
parent cc4a773010
commit 2b7a074c8b
3 changed files with 49 additions and 1 deletions
+24
View File
@@ -8,6 +8,7 @@ export class CachePool {
private redisClient: Redis | null = null
activeLLMCache: IActiveCache = {}
activeEmbeddingCache: IActiveCache = {}
activeMCPCache: { [key: string]: any } = {}
constructor() {
if (process.env.MODE === MODE.QUEUE) {
@@ -73,6 +74,29 @@ export class CachePool {
}
}
/**
* Add to the mcp toolkit cache pool
* @param {string} cacheKey
* @param {any} value
*/
async addMCPCache(cacheKey: string, value: any) {
// Only add to cache for non-queue mode, because we are storing the toolkit instances in memory, and we can't store them in redis
if (process.env.MODE !== MODE.QUEUE) {
this.activeMCPCache[`mcpCache:${cacheKey}`] = value
}
}
/**
* Get item from mcp toolkit cache pool
* @param {string} cacheKey
*/
async getMCPCache(cacheKey: string): Promise<any | undefined> {
if (process.env.MODE !== MODE.QUEUE) {
return this.activeMCPCache[`mcpCache:${cacheKey}`]
}
return undefined
}
/**
* Get item from llm cache pool
* @param {string} chatflowid
+2 -1
View File
@@ -103,7 +103,8 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
componentNodes: appServer.nodesPool.componentNodes,
previousNodes: requestBody.previousNodes,
currentNode: requestBody.currentNode,
searchOptions: requestBody.searchOptions
searchOptions: requestBody.searchOptions,
cachePool: appServer.cachePool
})
return dbResponse