@@ -29,6 +29,24 @@ async function deleteAndWaitCluster(session: Session, projectId: string, cluster
2929 }
3030}
3131
32+ async function waitClusterState ( session : Session , projectId : string , clusterName : string , state : string ) {
33+ while ( true ) {
34+ const cluster = await session . apiClient . getCluster ( {
35+ params : {
36+ path : {
37+ groupId : projectId ,
38+ clusterName : clusterName ,
39+ } ,
40+ } ,
41+ } ) ;
42+ if ( cluster ?. stateName === state ) {
43+ return ;
44+ }
45+ await sleep ( 1000 ) ;
46+ }
47+ }
48+
49+
3250describeWithAtlas ( "clusters" , ( integration ) => {
3351 withProject ( integration , ( { getProjectId } ) => {
3452 const clusterName = "ClusterTest-" + randomId ;
@@ -117,5 +135,45 @@ describeWithAtlas("clusters", (integration) => {
117135 expect ( response . content [ 1 ] . text ) . toContain ( `${ clusterName } | ` ) ;
118136 } ) ;
119137 } ) ;
138+
139+ describe ( "atlas-connect-cluster" , ( ) => {
140+ beforeAll ( async ( ) => {
141+ const projectId = getProjectId ( ) ;
142+ await waitClusterState ( integration . mcpServer ( ) . session , projectId , clusterName , "IDLE" ) ;
143+ const cluster = await integration . mcpServer ( ) . session . apiClient . getCluster ( {
144+ params : {
145+ path : {
146+ groupId : projectId ,
147+ clusterName : clusterName ,
148+ } ,
149+ }
150+ } ) ;
151+
152+ console . log ( "Cluster connection string: " , cluster ?. connectionStrings ?. standardSrv || cluster ?. connectionStrings ?. standard ) ;
153+ } ) ;
154+
155+ it ( "should have correct metadata" , async ( ) => {
156+ const { tools } = await integration . mcpClient ( ) . listTools ( ) ;
157+ const connectCluster = tools . find ( ( tool ) => tool . name === "atlas-connect-cluster" ) ;
158+
159+ expectDefined ( connectCluster ) ;
160+ expect ( connectCluster . inputSchema . type ) . toBe ( "object" ) ;
161+ expectDefined ( connectCluster . inputSchema . properties ) ;
162+ expect ( connectCluster . inputSchema . properties ) . toHaveProperty ( "projectId" ) ;
163+ expect ( connectCluster . inputSchema . properties ) . toHaveProperty ( "clusterName" ) ;
164+ } ) ;
165+
166+ it ( "connects to cluster" , async ( ) => {
167+ const projectId = getProjectId ( ) ;
168+
169+ const response = ( await integration . mcpClient ( ) . callTool ( {
170+ name : "atlas-connect-cluster" ,
171+ arguments : { projectId, clusterName } ,
172+ } ) ) as CallToolResult ;
173+ expect ( response . content ) . toBeArray ( ) ;
174+ expect ( response . content ) . toHaveLength ( 1 ) ;
175+ expect ( response . content [ 0 ] . text ) . toContain ( `Connected to cluster "${ clusterName } "` ) ;
176+ } ) ;
177+ } ) ;
120178 } ) ;
121179} ) ;
0 commit comments