1
1
import { Session } from "../../../../src/session.js" ;
2
2
import { expectDefined } from "../../helpers.js" ;
3
- import { describeWithAtlas , withProject , sleep , randomId } from "./atlasHelpers.js" ;
3
+ import { describeWithAtlas , withProject , randomId } from "./atlasHelpers.js" ;
4
4
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
5
5
6
+ function sleep ( ms : number ) {
7
+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
8
+ }
9
+
6
10
async function deleteAndWaitCluster ( session : Session , projectId : string , clusterName : string ) {
7
11
await session . apiClient . deleteCluster ( {
8
12
params : {
9
13
path : {
10
14
groupId : projectId ,
11
- clusterName : clusterName ,
15
+ clusterName,
12
16
} ,
13
17
} ,
14
18
} ) ;
@@ -18,7 +22,7 @@ async function deleteAndWaitCluster(session: Session, projectId: string, cluster
18
22
params : {
19
23
path : {
20
24
groupId : projectId ,
21
- clusterName : clusterName ,
25
+ clusterName,
22
26
} ,
23
27
} ,
24
28
} ) ;
@@ -29,6 +33,23 @@ async function deleteAndWaitCluster(session: Session, projectId: string, cluster
29
33
}
30
34
}
31
35
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
+
32
53
describeWithAtlas ( "clusters" , ( integration ) => {
33
54
withProject ( integration , ( { getProjectId } ) => {
34
55
const clusterName = "ClusterTest-" + randomId ;
@@ -66,7 +87,7 @@ describeWithAtlas("clusters", (integration) => {
66
87
} ,
67
88
} ) ) as CallToolResult ;
68
89
expect ( response . content ) . toBeArray ( ) ;
69
- expect ( response . content ) . toHaveLength ( 1 ) ;
90
+ expect ( response . content ) . toHaveLength ( 2 ) ;
70
91
expect ( response . content [ 0 ] . text ) . toContain ( "has been created" ) ;
71
92
} ) ;
72
93
} ) ;
@@ -117,5 +138,48 @@ describeWithAtlas("clusters", (integration) => {
117
138
expect ( response . content [ 1 ] . text ) . toContain ( `${ clusterName } | ` ) ;
118
139
} ) ;
119
140
} ) ;
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
+ } ) ;
120
184
} ) ;
121
185
} ) ;
0 commit comments