-
Notifications
You must be signed in to change notification settings - Fork 167
chore: Support atlas connect via private and private endpoint connection strings #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e3da69b
80b353f
f7b4ec4
933e18a
a18cbdb
f37c2e4
a9d6526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import { type OperationType, type ToolArgs } from "../../tool.js"; | |
| import { AtlasToolBase } from "../atlasTool.js"; | ||
| import { generateSecurePassword } from "../../../helpers/generatePassword.js"; | ||
| import { LogId } from "../../../common/logger.js"; | ||
| import { inspectCluster } from "../../../common/atlas/cluster.js"; | ||
| import { getConnectionString, inspectCluster } from "../../../common/atlas/cluster.js"; | ||
| import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUtils.js"; | ||
| import type { AtlasClusterConnectionInfo } from "../../../common/connectionManager.js"; | ||
| import { getDefaultRoleFromConfig } from "../../../common/atlas/roles.js"; | ||
|
|
@@ -22,6 +22,9 @@ function sleep(ms: number): Promise<void> { | |
| export const ConnectClusterArgs = { | ||
| projectId: AtlasArgs.projectId().describe("Atlas project ID"), | ||
| clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"), | ||
| connectionType: AtlasArgs.connectionType() | ||
| .optional() | ||
cveticm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .describe("Type of connection (standard, private, or privateEndpoint) to an Atlas cluster"), | ||
| }; | ||
|
|
||
| export class ConnectClusterTool extends AtlasToolBase { | ||
|
|
@@ -69,12 +72,17 @@ export class ConnectClusterTool extends AtlasToolBase { | |
|
|
||
| private async prepareClusterConnection( | ||
| projectId: string, | ||
| clusterName: string | ||
| clusterName: string, | ||
| connectionType: "standard" | "private" | "privateEndpoint" | undefined = "standard" | ||
| ): Promise<{ connectionString: string; atlas: AtlasClusterConnectionInfo }> { | ||
| const cluster = await inspectCluster(this.session.apiClient, projectId, clusterName); | ||
|
|
||
| if (!cluster.connectionString) { | ||
| throw new Error("Connection string not available"); | ||
| if (cluster.connectionStrings === undefined) { | ||
| throw new Error("Connection strings not available"); | ||
| } | ||
| const connectionString = getConnectionString(cluster.connectionStrings, connectionType); | ||
| if (connectionString === undefined) { | ||
| throw new Error(`Connection string for connection type "${connectionType}" not available`); | ||
|
||
| } | ||
|
|
||
| const username = `mcpUser${Math.floor(Math.random() * 100000)}`; | ||
|
|
@@ -113,7 +121,7 @@ export class ConnectClusterTool extends AtlasToolBase { | |
| expiryDate, | ||
| }; | ||
|
|
||
| const cn = new URL(cluster.connectionString); | ||
| const cn = new URL(connectionString); | ||
| cn.username = username; | ||
| cn.password = password; | ||
| cn.searchParams.set("authSource", "admin"); | ||
|
|
@@ -200,7 +208,11 @@ export class ConnectClusterTool extends AtlasToolBase { | |
| }); | ||
| } | ||
|
|
||
| protected async execute({ projectId, clusterName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { | ||
| protected async execute({ | ||
| projectId, | ||
| clusterName, | ||
| connectionType, | ||
| }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { | ||
| const ipAccessListUpdated = await ensureCurrentIpInAccessList(this.session.apiClient, projectId); | ||
| let createdUser = false; | ||
|
|
||
|
|
@@ -239,7 +251,11 @@ export class ConnectClusterTool extends AtlasToolBase { | |
| case "disconnected": | ||
| default: { | ||
| await this.session.disconnect(); | ||
| const { connectionString, atlas } = await this.prepareClusterConnection(projectId, clusterName); | ||
| const { connectionString, atlas } = await this.prepareClusterConnection( | ||
| projectId, | ||
| clusterName, | ||
| connectionType | ||
| ); | ||
|
|
||
| createdUser = true; | ||
| // try to connect for about 5 minutes asynchronously | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.