Skip to content

Commit 83c9639

Browse files
feat: Allow configuration of temporary user when connecting to atlas cluster
1 parent dd7760b commit 83c9639

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/common/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const OPTIONS = {
4848
"tlsCertificateSelector",
4949
"tlsDisabledProtocols",
5050
"username",
51+
"temporaryDatabaseUserLifetimeSeconds",
5152
],
5253
boolean: [
5354
"apiDeprecationErrors",
@@ -161,6 +162,7 @@ export interface UserConfig extends CliOptions {
161162
loggers: Array<"stderr" | "disk" | "mcp">;
162163
idleTimeoutMs: number;
163164
notificationTimeoutMs: number;
165+
temporaryDatabaseUserLifetimeSeconds: number;
164166
}
165167

166168
export const defaultUserConfig: UserConfig = {
@@ -180,6 +182,7 @@ export const defaultUserConfig: UserConfig = {
180182
idleTimeoutMs: 600000, // 10 minutes
181183
notificationTimeoutMs: 540000, // 9 minutes
182184
httpHeaders: {},
185+
temporaryDatabaseUserLifetimeSeconds: 14400, // 4 hours
183186
};
184187

185188
export const config = setupUserConfig({

src/tools/atlas/connect/connectCluster.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUti
99
import type { AtlasClusterConnectionInfo } from "../../../common/connectionManager.js";
1010
import { getDefaultRoleFromConfig } from "../../../common/atlas/roles.js";
1111

12-
const EXPIRY_MS = 1000 * 60 * 60 * 12; // 12 hours
1312
const addedIpAccessListMessage =
1413
"Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.";
1514

@@ -77,7 +76,7 @@ export class ConnectClusterTool extends AtlasToolBase {
7776
const username = `mcpUser${Math.floor(Math.random() * 100000)}`;
7877
const password = await generateSecurePassword();
7978

80-
const expiryDate = new Date(Date.now() + EXPIRY_MS);
79+
const expiryDate = new Date(Date.now() + this.config.temporaryDatabaseUserLifetimeSeconds * 1000);
8180
const role = getDefaultRoleFromConfig(this.config);
8281

8382
await this.session.apiClient.createDatabaseUser({

tests/unit/common/config.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ describe("config", () => {
4141
{ envVar: "MDB_MCP_HTTP_HOST", property: "httpHost", value: "localhost" },
4242
{ envVar: "MDB_MCP_IDLE_TIMEOUT_MS", property: "idleTimeoutMs", value: 5000 },
4343
{ envVar: "MDB_MCP_NOTIFICATION_TIMEOUT_MS", property: "notificationTimeoutMs", value: 5000 },
44+
{
45+
envVar: "MDB_MCP_TEMPORARY_DATABASE_USER_LIFETIME_SECONDS",
46+
property: "temporaryDatabaseUserLifetimeSeconds",
47+
value: 12345,
48+
},
4449
] as const;
4550

4651
for (const { envVar, property, value } of testCases) {
@@ -129,6 +134,10 @@ describe("config", () => {
129134
cli: ["--notificationTimeoutMs", "42"],
130135
expected: { notificationTimeoutMs: "42" },
131136
},
137+
{
138+
cli: ["--temporaryDatabaseUserLifetimeSeconds", "12345"],
139+
expected: { temporaryDatabaseUserLifetimeSeconds: "12345" },
140+
},
132141
{
133142
cli: ["--telemetry", "enabled"],
134143
expected: { telemetry: "enabled" },

0 commit comments

Comments
 (0)