Skip to content

Commit 84a0fe0

Browse files
committed
Change config storage location
1 parent 7f3a8d9 commit 84a0fe0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/config.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import argv from "yargs-parser";
44

55
import packageJson from "../package.json" with { type: "json" };
66
import fs from "fs";
7-
const localDataPath = getLocalDataPath();
7+
const { localDataPath, configPath } = getLocalDataPath();
88

99
// If we decide to support non-string config options, we'll need to extend the mechanism for parsing
1010
// env variables.
@@ -37,22 +37,28 @@ const config = {
3737

3838
export default config;
3939

40-
function getLocalDataPath(): string {
41-
let result: string | undefined;
40+
function getLocalDataPath(): { localDataPath: string; configPath: string } {
41+
let localDataPath: string | undefined;
42+
let configPath: string | undefined;
4243

4344
if (process.platform === "win32") {
4445
const appData = process.env.APPDATA;
4546
const localAppData = process.env.LOCALAPPDATA ?? process.env.APPDATA;
4647
if (localAppData && appData) {
47-
result = path.join(localAppData, "mongodb", "mongodb-mcp");
48+
localDataPath = path.join(localAppData, "mongodb", "mongodb-mcp");
49+
configPath = path.join(localAppData, "mongodb", "mongodb-mcp.conf");
4850
}
4951
}
5052

51-
result ??= path.join(os.homedir(), ".mongodb", "mongodb-mcp");
53+
localDataPath ??= path.join(os.homedir(), ".mongodb", "mongodb-mcp");
54+
configPath ??= "/etc/mongodb-mcp.conf";
5255

53-
fs.mkdirSync(result, { recursive: true });
56+
fs.mkdirSync(localDataPath, { recursive: true });
5457

55-
return result;
58+
return {
59+
localDataPath,
60+
configPath,
61+
};
5662
}
5763

5864
// Gets the config supplied by the user as environment variables. The variable names
@@ -77,8 +83,6 @@ function getEnvConfig(): Partial<UserConfig> {
7783
// Gets the config supplied by the user as a JSON file. The file is expected to be located in the local data path
7884
// and named `config.json`.
7985
function getFileConfig(): Partial<UserConfig> {
80-
const configPath = path.join(localDataPath, "config.json");
81-
8286
try {
8387
const config = fs.readFileSync(configPath, "utf8");
8488
return JSON.parse(config);

0 commit comments

Comments
 (0)