@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
49 lines • 1.66 kB
JavaScript
export const cachedMcpTools = {};
export const cachedMcpToolKeysByServer = {};
const activeServerToolsCacheListings = new Map();
export function beginServerToolsCacheListing(serverName) {
const listing = { invalidated: false };
let activeListings = activeServerToolsCacheListings.get(serverName);
if (!activeListings) {
activeListings = new Set();
activeServerToolsCacheListings.set(serverName, activeListings);
}
activeListings.add(listing);
let released = false;
return {
isCurrent: () => !listing.invalidated,
release: () => {
if (released) {
return;
}
released = true;
activeListings.delete(listing);
if (activeListings.size === 0) {
activeServerToolsCacheListings.delete(serverName);
}
},
};
}
/**
* Remove cached tools for the given server so the next lookup fetches fresh data.
*
* @param serverName - Name of the MCP server whose cache should be cleared.
*/
export async function invalidateServerToolsCache(serverName) {
const activeListings = activeServerToolsCacheListings.get(serverName);
if (activeListings) {
for (const listing of activeListings) {
listing.invalidated = true;
}
}
const cachedKeys = cachedMcpToolKeysByServer[serverName];
if (cachedKeys) {
for (const cacheKey of cachedKeys) {
delete cachedMcpTools[cacheKey];
}
delete cachedMcpToolKeysByServer[serverName];
return;
}
delete cachedMcpTools[serverName];
}
//# sourceMappingURL=mcpToolCache.mjs.map