11import { Session } from "../../../../src/session.js" ;
22import { expectDefined } from "../../helpers.js" ;
3- import { describeWithAtlas , withProject , sleep , randomId } from "./atlasHelpers.js" ;
3+ import { describeWithAtlas , withProject , randomId } from "./atlasHelpers.js" ;
44import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
55
6+ function sleep ( ms : number ) {
7+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
8+ }
9+
610async function deleteAndWaitCluster ( session : Session , projectId : string , clusterName : string ) {
711 await session . apiClient . deleteCluster ( {
812 params : {
913 path : {
1014 groupId : projectId ,
11- clusterName : clusterName ,
15+ clusterName,
1216 } ,
1317 } ,
1418 } ) ;
@@ -18,7 +22,7 @@ async function deleteAndWaitCluster(session: Session, projectId: string, cluster
1822 params : {
1923 path : {
2024 groupId : projectId ,
21- clusterName : clusterName ,
25+ clusterName,
2226 } ,
2327 } ,
2428 } ) ;
@@ -29,6 +33,23 @@ async function deleteAndWaitCluster(session: Session, projectId: string, cluster
2933 }
3034}
3135
36+ async function waitClusterState ( session : Session , projectId : string , clusterName : string , state : string ) {
37+ while ( true ) {
38+ const cluster = await session . apiClient . getCluster ( {
39+ params : {
40+ path : {
41+ groupId : projectId ,
42+ clusterName,
43+ } ,
44+ } ,
45+ } ) ;
46+ if ( cluster ?. stateName === state ) {
47+ return ;
48+ }
49+ await sleep ( 1000 ) ;
50+ }
51+ }
52+
3253describeWithAtlas ( "clusters" , ( integration ) => {
3354 withProject ( integration , ( { getProjectId } ) => {
3455 const clusterName = "ClusterTest-" + randomId ;
@@ -66,7 +87,7 @@ describeWithAtlas("clusters", (integration) => {
6687 } ,
6788 } ) ) as CallToolResult ;
6889 expect ( response . content ) . toBeArray ( ) ;
69- expect ( response . content ) . toHaveLength ( 1 ) ;
90+ expect ( response . content ) . toHaveLength ( 2 ) ;
7091 expect ( response . content [ 0 ] . text ) . toContain ( "has been created" ) ;
7192 } ) ;
7293 } ) ;
@@ -117,5 +138,48 @@ describeWithAtlas("clusters", (integration) => {
117138 expect ( response . content [ 1 ] . text ) . toContain ( `${ clusterName } | ` ) ;
118139 } ) ;
119140 } ) ;
141+
142+ describe ( "atlas-connect-cluster" , ( ) => {
143+ beforeAll ( async ( ) => {
144+ const projectId = getProjectId ( ) ;
145+ await waitClusterState ( integration . mcpServer ( ) . session , projectId , clusterName , "IDLE" ) ;
146+ await integration . mcpServer ( ) . session . apiClient . createProjectIpAccessList ( {
147+ params : {
148+ path : {
149+ groupId : projectId ,
150+ } ,
151+ } ,
152+ body : [
153+ {
154+ comment : "MCP test" ,
155+ cidrBlock : "0.0.0.0/0" ,
156+ } ,
157+ ] ,
158+ } ) ;
159+ } ) ;
160+
161+ it ( "should have correct metadata" , async ( ) => {
162+ const { tools } = await integration . mcpClient ( ) . listTools ( ) ;
163+ const connectCluster = tools . find ( ( tool ) => tool . name === "atlas-connect-cluster" ) ;
164+
165+ expectDefined ( connectCluster ) ;
166+ expect ( connectCluster . inputSchema . type ) . toBe ( "object" ) ;
167+ expectDefined ( connectCluster . inputSchema . properties ) ;
168+ expect ( connectCluster . inputSchema . properties ) . toHaveProperty ( "projectId" ) ;
169+ expect ( connectCluster . inputSchema . properties ) . toHaveProperty ( "clusterName" ) ;
170+ } ) ;
171+
172+ it ( "connects to cluster" , async ( ) => {
173+ const projectId = getProjectId ( ) ;
174+
175+ const response = ( await integration . mcpClient ( ) . callTool ( {
176+ name : "atlas-connect-cluster" ,
177+ arguments : { projectId, clusterName } ,
178+ } ) ) as CallToolResult ;
179+ expect ( response . content ) . toBeArray ( ) ;
180+ expect ( response . content ) . toHaveLength ( 1 ) ;
181+ expect ( response . content [ 0 ] . text ) . toContain ( `Connected to cluster "${ clusterName } "` ) ;
182+ } ) ;
183+ } ) ;
120184 } ) ;
121185} ) ;
0 commit comments