@@ -8,6 +8,7 @@ import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUti
88import type { AtlasClusterConnectionInfo } from "../../../common/connectionManager.js" ;
99import { getDefaultRoleFromConfig } from "../../../common/atlas/roles.js" ;
1010import { AtlasArgs } from "../../args.js" ;
11+ import { getConnectionString } from "../../../common/atlas/cluster.js" ;
1112
1213const addedIpAccessListMessage =
1314 "Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection." ;
@@ -22,6 +23,7 @@ function sleep(ms: number): Promise<void> {
2223export const ConnectClusterArgs = {
2324 projectId : AtlasArgs . projectId ( ) . describe ( "Atlas project ID" ) ,
2425 clusterName : AtlasArgs . clusterName ( ) . describe ( "Atlas cluster name" ) ,
26+ connectionType : AtlasArgs . connectionType ( ) . optional ( ) ,
2527} ;
2628
2729export class ConnectClusterTool extends AtlasToolBase {
@@ -69,12 +71,16 @@ export class ConnectClusterTool extends AtlasToolBase {
6971
7072 private async prepareClusterConnection (
7173 projectId : string ,
72- clusterName : string
74+ clusterName : string ,
75+ connectionType : "standard" | "private"
7376 ) : Promise < { connectionString : string ; atlas : AtlasClusterConnectionInfo } > {
7477 const cluster = await inspectCluster ( this . session . apiClient , projectId , clusterName ) ;
75-
76- if ( ! cluster . connectionString ) {
77- throw new Error ( "Connection string not available" ) ;
78+ if ( cluster . connectionStrings === undefined ) {
79+ throw new Error ( "Connection strings not available" ) ;
80+ }
81+ const connectionString = getConnectionString ( cluster . connectionStrings , connectionType ) ;
82+ if ( connectionString === undefined ) {
83+ throw new Error ( "Connection string not available for connection type: " + connectionType ) ;
7884 }
7985
8086 const username = `mcpUser${ Math . floor ( Math . random ( ) * 100000 ) } ` ;
@@ -200,7 +206,11 @@ export class ConnectClusterTool extends AtlasToolBase {
200206 } ) ;
201207 }
202208
203- protected async execute ( { projectId, clusterName } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
209+ protected async execute ( {
210+ projectId,
211+ clusterName,
212+ connectionType,
213+ } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
204214 const ipAccessListUpdated = await ensureCurrentIpInAccessList ( this . session . apiClient , projectId ) ;
205215 let createdUser = false ;
206216
@@ -239,7 +249,11 @@ export class ConnectClusterTool extends AtlasToolBase {
239249 case "disconnected" :
240250 default : {
241251 await this . session . disconnect ( ) ;
242- const { connectionString, atlas } = await this . prepareClusterConnection ( projectId , clusterName ) ;
252+ const { connectionString, atlas } = await this . prepareClusterConnection (
253+ projectId ,
254+ clusterName ,
255+ connectionType
256+ ) ;
243257
244258 createdUser = true ;
245259 // try to connect for about 5 minutes asynchronously
0 commit comments