Skip to content

Commit 7d68929

Browse files
committed
fix: address comments
1 parent 15e9e5b commit 7d68929

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

src/config.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,11 @@ const config = {
4949
export default config;
5050

5151
function 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
}

src/logger.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from "fs";
12
import { MongoLogId, MongoLogManager, MongoLogWriter } from "mongodb-log-writer";
23
import config from "./config.js";
34
import redact from "mongodb-redact";
@@ -97,7 +98,21 @@ class ProxyingLogger extends LoggerBase {
9798
const logger = new ProxyingLogger();
9899
export 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+
100113
export 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,

src/state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver
22

33
export class State {
44
serviceProvider?: NodeDriverServiceProvider;
5-
connectionString?: string;
65
}
76

87
const defaultState = new State();

src/tools/mongodb/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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: [

src/tools/mongodb/mongodbTool.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ export abstract class MongoDBToolBase extends ToolBase {
6666
});
6767

6868
state.serviceProvider = provider;
69-
state.connectionString = connectionString;
7069
}
7170
}

0 commit comments

Comments
 (0)