fix: use specified environment setting path when available (#359)

This commit is contained in:
samanhappy
2025-10-11 23:44:23 +08:00
committed by GitHub
parent a5d5045832
commit 91698a50e3
2 changed files with 21 additions and 9 deletions

View File

@@ -43,7 +43,6 @@ export function registerService<T>(key: string, entry: Service<T>) {
}
}
console.log(`Service registered: ${key} with entry:`, entry);
registry.set(key, entry);
}

View File

@@ -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) {