mirror of
https://github.com/samanhappy/mcphub.git
synced 2026-01-11 17:16:55 -05:00
fix: update getServerInfos handling to avoid stale references in smart routing service
This commit is contained in:
@@ -14,6 +14,7 @@ import { getGroup } from './sseService.js';
|
|||||||
|
|
||||||
// Reference to serverInfos from mcpService - will be set via init
|
// Reference to serverInfos from mcpService - will be set via init
|
||||||
let serverInfosRef: ServerInfo[] = [];
|
let serverInfosRef: ServerInfo[] = [];
|
||||||
|
let getServerInfosFn: () => ServerInfo[] = () => serverInfosRef;
|
||||||
let filterToolsByConfigFn: (serverName: string, tools: Tool[]) => Promise<Tool[]>;
|
let filterToolsByConfigFn: (serverName: string, tools: Tool[]) => Promise<Tool[]>;
|
||||||
let filterToolsByGroupFn: (
|
let filterToolsByGroupFn: (
|
||||||
group: string | undefined,
|
group: string | undefined,
|
||||||
@@ -33,11 +34,8 @@ export const initSmartRoutingService = (
|
|||||||
tools: Tool[],
|
tools: Tool[],
|
||||||
) => Promise<Tool[]>,
|
) => Promise<Tool[]>,
|
||||||
) => {
|
) => {
|
||||||
// Store a getter function instead of direct reference
|
// Store the getter to avoid stale references while staying ESM-safe
|
||||||
Object.defineProperty(module.exports, 'serverInfosRef', {
|
getServerInfosFn = getServerInfos;
|
||||||
get: getServerInfos,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
serverInfosRef = getServerInfos();
|
serverInfosRef = getServerInfos();
|
||||||
filterToolsByConfigFn = filterToolsByConfig;
|
filterToolsByConfigFn = filterToolsByConfig;
|
||||||
filterToolsByGroupFn = filterToolsByGroup;
|
filterToolsByGroupFn = filterToolsByGroup;
|
||||||
@@ -47,7 +45,7 @@ export const initSmartRoutingService = (
|
|||||||
* Get current server infos (refreshed each call)
|
* Get current server infos (refreshed each call)
|
||||||
*/
|
*/
|
||||||
const getServerInfos = (): ServerInfo[] => {
|
const getServerInfos = (): ServerInfo[] => {
|
||||||
return serverInfosRef;
|
return getServerInfosFn();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user