@@ -5,6 +5,8 @@ import os from "os";
55
66import argv from "yargs-parser" ;
77
8+ const localDataPath = getLocalDataPath ( ) ;
9+
810// If we decide to support non-string config options, we'll need to extend the mechanism for parsing
911// env variables.
1012interface UserConfig extends Record < string , string > {
@@ -19,7 +21,7 @@ const cliConfig = argv(process.argv.slice(2)) as unknown as Partial<UserConfig>;
1921const defaults : UserConfig = {
2022 apiBaseUrl : "https://cloud.mongodb.com/" ,
2123 clientId : "0oabtxactgS3gHIR0297" ,
22- stateFile : path . join ( getLocalDataPath ( ) , "state.json" ) ,
24+ stateFile : path . join ( localDataPath , "state.json" ) ,
2325 projectId : "" ,
2426} ;
2527
@@ -36,21 +38,27 @@ const config = {
3638 atlasApiVersion : `2025-03-12` ,
3739 version : packageJson . version ,
3840 userAgent : `AtlasMCP/${ packageJson . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
39- localDataPath : getLocalDataPath ( ) ,
41+ localDataPath,
4042} ;
4143
4244export default config ;
4345
4446function getLocalDataPath ( ) : string {
47+ let result : string | undefined ;
48+
4549 if ( process . platform === "win32" ) {
4650 const appData = process . env . APPDATA ;
4751 const localAppData = process . env . LOCALAPPDATA ?? process . env . APPDATA ;
4852 if ( localAppData && appData ) {
49- return path . join ( localAppData , "mongodb" , "mongodb-mcp" ) ;
53+ result = path . join ( localAppData , "mongodb" , "mongodb-mcp" ) ;
5054 }
5155 }
5256
53- return path . join ( os . homedir ( ) , ".mongodb" , "mongodb-mcp" ) ;
57+ result ??= path . join ( os . homedir ( ) , ".mongodb" , "mongodb-mcp" ) ;
58+
59+ fs . mkdirSync ( result , { recursive : true } ) ;
60+
61+ return result ;
5462}
5563
5664// Gets the config supplied by the user as environment variables. The variable names
@@ -75,7 +83,7 @@ function getEnvConfig(): Partial<UserConfig> {
7583// Gets the config supplied by the user as a JSON file. The file is expected to be located in the local data path
7684// and named `config.json`.
7785function getFileConfig ( ) : Partial < UserConfig > {
78- const configPath = path . join ( getLocalDataPath ( ) , "config.json" ) ;
86+ const configPath = path . join ( localDataPath , "config.json" ) ;
7987
8088 try {
8189 const config = fs . readFileSync ( configPath , "utf8" ) ;
0 commit comments