File tree Expand file tree Collapse file tree 5 files changed +20
-17
lines changed
Expand file tree Collapse file tree 5 files changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -49,21 +49,11 @@ const config = {
4949export default config ;
5050
5151function getLogPath ( ) : string {
52- let localDataPath : string | undefined ;
52+ const localDataPath = ( process . platform === "win32" ) ?
53+ path . join ( process . env . LOCALAPPDATA || process . env . APPDATA || os . homedir ( ) , "mongodb" )
54+ : path . join ( os . homedir ( ) , ".mongodb" ) ;
5355
54- if ( process . platform === "win32" ) {
55- const appData = process . env . APPDATA ;
56- const localAppData = process . env . LOCALAPPDATA ?? process . env . APPDATA ;
57- if ( localAppData && appData ) {
58- localDataPath = path . join ( localAppData , "mongodb" , "mongodb-mcp" ) ;
59- }
60- }
61-
62- localDataPath ??= path . join ( os . homedir ( ) , ".mongodb" , "mongodb-mcp" ) ;
63-
64- const logPath = path . join ( localDataPath , ".app-logs" ) ;
65-
66- fs . mkdirSync ( logPath , { recursive : true } ) ;
56+ const logPath = path . join ( localDataPath , "mongodb-mcp" , ".app-logs" ) ;
6757
6858 return logPath ;
6959}
Original file line number Diff line number Diff line change 1+ import fs from "fs" ;
12import { MongoLogId , MongoLogManager , MongoLogWriter } from "mongodb-log-writer" ;
23import config from "./config.js" ;
34import redact from "mongodb-redact" ;
@@ -97,7 +98,21 @@ class ProxyingLogger extends LoggerBase {
9798const logger = new ProxyingLogger ( ) ;
9899export default logger ;
99100
101+ async function mkdirPromise ( path : fs . PathLike , options ?: fs . Mode | fs . MakeDirectoryOptions ) {
102+ return new Promise < string | undefined > ( ( resolve , reject ) => {
103+ fs . mkdir ( path , options , ( err , resultPath ) => {
104+ if ( err ) {
105+ reject ( err ) ;
106+ } else {
107+ resolve ( resultPath ) ;
108+ }
109+ } ) ;
110+ } ) ;
111+ }
112+
100113export async function initializeLogger ( server : McpServer ) : Promise < void > {
114+ await mkdirPromise ( config . logPath , { recursive : true } ) ;
115+
101116 const manager = new MongoLogManager ( {
102117 directory : config . logPath ,
103118 retentionDays : 30 ,
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver
22
33export class State {
44 serviceProvider ?: NodeDriverServiceProvider ;
5- connectionString ?: string ;
65}
76
87const defaultState = new State ( ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export class ConnectTool extends MongoDBToolBase {
2020 protected async execute ( {
2121 connectionStringOrClusterName,
2222 } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
23- connectionStringOrClusterName ??= config . connectionString || this . state . connectionString ;
23+ connectionStringOrClusterName ??= config . connectionString ;
2424 if ( ! connectionStringOrClusterName ) {
2525 return {
2626 content : [
Original file line number Diff line number Diff line change @@ -66,6 +66,5 @@ export abstract class MongoDBToolBase extends ToolBase {
6666 } ) ;
6767
6868 state . serviceProvider = provider ;
69- state . connectionString = connectionString ;
7069 }
7170}
You can’t perform that action at this time.
0 commit comments