From 91698a50e38090878041be638d811098ac2aaf7d Mon Sep 17 00:00:00 2001 From: samanhappy Date: Sat, 11 Oct 2025 23:44:23 +0800 Subject: [PATCH] fix: use specified environment setting path when available (#359) --- src/services/registry.ts | 1 - src/utils/path.ts | 29 +++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/services/registry.ts b/src/services/registry.ts index 8e8d6f8..c962ecd 100644 --- a/src/services/registry.ts +++ b/src/services/registry.ts @@ -43,7 +43,6 @@ export function registerService(key: string, entry: Service) { } } - console.log(`Service registered: ${key} with entry:`, entry); registry.set(key, entry); } diff --git a/src/utils/path.ts b/src/utils/path.ts index 8069414..0748d11 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -12,15 +12,28 @@ const rootDir = process.cwd(); * @returns The path to the file */ export const getConfigFilePath = (filename: string, description = 'Configuration'): string => { - const envPath = process.env.MCPHUB_SETTING_PATH; + if (filename === 'mcp_settings.json') { + const envPath = process.env.MCPHUB_SETTING_PATH; + if (envPath) { + // check envPath is file or directory + const stats = fs.statSync(envPath); + if (stats.isFile()) { + return envPath; + } + // if directory, return path under that directory + return path.resolve(envPath, filename); + } + } + const potentialPaths = [ - ...(envPath ? [envPath] : []), - // Prioritize process.cwd() as the first location to check - path.resolve(process.cwd(), filename), - // Use path relative to the root directory - path.join(rootDir, filename), - // If installed with npx, may need to look one level up - path.join(dirname(rootDir), filename), + ...[ + // Prioritize process.cwd() as the first location to check + path.resolve(process.cwd(), filename), + // Use path relative to the root directory + path.join(rootDir, filename), + // If installed with npx, may need to look one level up + path.join(dirname(rootDir), filename), + ], ]; for (const filePath of potentialPaths) {