Skip to content

Commit 8aeee07

Browse files
committed
update tests
1 parent 9ff88ed commit 8aeee07

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/tools/atlas/connect/connectCluster.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const EXPIRY_MS = 1000 * 60 * 60 * 12; // 12 hours
1313
const addedIpAccessListMessage =
1414
"Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.";
1515

16+
const createdUserMessage =
17+
"Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations";
18+
1619
function sleep(ms: number): Promise<void> {
1720
return new Promise((resolve) => setTimeout(resolve, ms));
1821
}
@@ -206,14 +209,20 @@ export class ConnectClusterTool extends AtlasToolBase {
206209
},
207210
];
208211

209-
// Add feedback about IP access list if it was updated
210212
if (ipAccessListUpdated) {
211213
content.push({
212214
type: "text",
213215
text: addedIpAccessListMessage,
214216
});
215217
}
216218

219+
if (createdUser) {
220+
content.push({
221+
type: "text",
222+
text: createdUserMessage,
223+
});
224+
}
225+
217226
return { content };
218227
}
219228
case "connecting":
@@ -267,7 +276,7 @@ export class ConnectClusterTool extends AtlasToolBase {
267276
if (createdUser) {
268277
content.push({
269278
type: "text" as const,
270-
text: `Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations`,
279+
text: createdUserMessage,
271280
});
272281
}
273282

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction): vo
2929

3030
interface ProjectTestArgs {
3131
getProjectId: () => string;
32+
getIpAddress: () => string;
3233
}
3334

3435
type ProjectTestFunction = (args: ProjectTestArgs) => void;
3536

3637
export function withProject(integration: IntegrationTest, fn: ProjectTestFunction): SuiteCollector<object> {
3738
return describe("with project", () => {
3839
let projectId: string = "";
40+
let ipAddress: string = "";
3941

4042
beforeAll(async () => {
4143
const apiClient = integration.mcpServer().session.apiClient;
@@ -49,6 +51,8 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
4951
await apiClient.validateAccessToken();
5052
try {
5153
const group = await createProject(apiClient);
54+
const ipInfo = await apiClient.getIpInfo();
55+
ipAddress = ipInfo.currentIpv4Address;
5256
projectId = group.id;
5357
} catch (error) {
5458
console.error("Failed to create project:", error);
@@ -72,6 +76,7 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
7276

7377
const args = {
7478
getProjectId: (): string => projectId,
79+
getIpAddress: (): string => ipAddress,
7580
};
7681

7782
fn(args);

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function waitCluster(
5757
}
5858

5959
describeWithAtlas("clusters", (integration) => {
60-
withProject(integration, ({ getProjectId }) => {
60+
withProject(integration, ({ getProjectId, getIpAddress }) => {
6161
const clusterName = "ClusterTest-" + randomId;
6262

6363
afterAll(async () => {
@@ -162,6 +162,7 @@ describeWithAtlas("clusters", (integration) => {
162162
describe("atlas-connect-cluster", () => {
163163
beforeAll(async () => {
164164
const projectId = getProjectId();
165+
const ipAddress = getIpAddress();
165166
await waitCluster(integration.mcpServer().session, projectId, clusterName, (cluster) => {
166167
return (
167168
cluster.stateName === "IDLE" &&
@@ -177,7 +178,7 @@ describeWithAtlas("clusters", (integration) => {
177178
body: [
178179
{
179180
comment: "MCP test",
180-
cidrBlock: "0.0.0.0/0",
181+
ipAddress: ipAddress,
181182
},
182183
],
183184
});
@@ -196,6 +197,7 @@ describeWithAtlas("clusters", (integration) => {
196197

197198
it("connects to cluster", async () => {
198199
const projectId = getProjectId();
200+
let connected = false;
199201

200202
for (let i = 0; i < 10; i++) {
201203
const response = await integration.mcpClient().callTool({
@@ -205,16 +207,25 @@ describeWithAtlas("clusters", (integration) => {
205207

206208
const elements = getResponseElements(response.content);
207209
expect(elements.length).toBeGreaterThanOrEqual(1);
208-
if (
209-
elements[0]?.text.includes("Cluster is already connected.") ||
210-
elements[0]?.text.includes(`Connected to cluster "${clusterName}"`)
211-
) {
212-
break; // success
210+
if (elements[0]?.text.includes(`Connected to cluster "${clusterName}"`)) {
211+
connected = true;
212+
213+
// assert that some of the element s have the message
214+
expect(
215+
elements.some((element) =>
216+
element.text.includes(
217+
"Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations"
218+
)
219+
)
220+
).toBe(true);
221+
222+
break;
213223
} else {
214224
expect(elements[0]?.text).toContain(`Attempting to connect to cluster "${clusterName}"...`);
215225
}
216226
await sleep(500);
217227
}
228+
expect(connected).toBe(true);
218229
});
219230

220231
describe("when not connected", () => {

0 commit comments

Comments
 (0)