-
Notifications
You must be signed in to change notification settings - Fork 163
fix: creating multiple users on atlas connect [MCP-280] #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f9c47d
ed5ec2f
37e1537
3387a6f
8e0a29a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| import type { Session } from "../../../../src/common/session.js"; | ||
| import { expectDefined, getResponseContent } from "../../helpers.js"; | ||
| import { describeWithAtlas, withProject, randomId, deleteCluster, waitCluster, sleep } from "./atlasHelpers.js"; | ||
| import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
| import { | ||
| describeWithAtlas, | ||
| withProject, | ||
| withCluster, | ||
| randomId, | ||
| deleteCluster, | ||
| waitCluster, | ||
| sleep, | ||
| } from "./atlasHelpers.js"; | ||
| import { afterAll, beforeAll, describe, expect, it, vitest } from "vitest"; | ||
|
|
||
| describeWithAtlas("clusters", (integration) => { | ||
| withProject(integration, ({ getProjectId, getIpAddress }) => { | ||
| const clusterName = "ClusterTest-" + randomId; | ||
| const clusterName = "ClusterTest-" + randomId(); | ||
|
|
||
| afterAll(async () => { | ||
| const projectId = getProjectId(); | ||
|
|
@@ -142,6 +150,11 @@ describeWithAtlas("clusters", (integration) => { | |
| }); | ||
|
|
||
| it("connects to cluster", async () => { | ||
| const createDatabaseUserSpy = vitest.spyOn( | ||
| integration.mcpServer().session.apiClient, | ||
| "createDatabaseUser" | ||
| ); | ||
|
|
||
| const projectId = getProjectId(); | ||
| const connectionType = "standard"; | ||
| let connected = false; | ||
|
|
@@ -158,6 +171,8 @@ describeWithAtlas("clusters", (integration) => { | |
| if (content.includes(`Connected to cluster "${clusterName}"`)) { | ||
| connected = true; | ||
|
|
||
| expect(createDatabaseUserSpy).toHaveBeenCalledTimes(1); | ||
|
|
||
| // assert that some of the element s have the message | ||
| expect(content).toContain( | ||
| "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" | ||
|
|
@@ -172,6 +187,58 @@ describeWithAtlas("clusters", (integration) => { | |
| expect(connected).toBe(true); | ||
| }); | ||
|
|
||
| describe("when connected", () => { | ||
| withCluster( | ||
| integration, | ||
| ({ getProjectId: getSecondaryProjectId, getClusterName: getSecondaryClusterName }) => { | ||
| beforeAll(async () => { | ||
| let connected = false; | ||
| for (let i = 0; i < 10; i++) { | ||
| const response = await integration.mcpClient().callTool({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [q] why do we need to call connect several times, shouldn't we connect and wait a considerable amount of time and that should be enough?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the edge case where atlas can take a long time to provision the DB user to data plane, in which case we need to keep waiting |
||
| name: "atlas-connect-cluster", | ||
| arguments: { | ||
| projectId: getSecondaryProjectId(), | ||
| clusterName: getSecondaryClusterName(), | ||
| connectionType: "standard", | ||
| }, | ||
| }); | ||
|
|
||
| const content = getResponseContent(response.content); | ||
|
|
||
| if (content.includes(`Connected to cluster "${getSecondaryClusterName()}"`)) { | ||
| connected = true; | ||
| break; | ||
| } | ||
|
|
||
| await sleep(500); | ||
| } | ||
|
|
||
| if (!connected) { | ||
| throw new Error("Could not connect to cluster before tests"); | ||
| } | ||
| }); | ||
|
|
||
| it("disconnects and deletes the database user before connecting to another cluster", async () => { | ||
| const deleteDatabaseUserSpy = vitest.spyOn( | ||
| integration.mcpServer().session.apiClient, | ||
| "deleteDatabaseUser" | ||
| ); | ||
|
|
||
| await integration.mcpClient().callTool({ | ||
| name: "atlas-connect-cluster", | ||
| arguments: { | ||
| projectId: getProjectId(), | ||
| clusterName: clusterName, | ||
| connectionType: "standard", | ||
| }, | ||
| }); | ||
|
|
||
| expect(deleteDatabaseUserSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| describe("when not connected", () => { | ||
| it("prompts for atlas-connect-cluster when querying mongodb", async () => { | ||
| const response = await integration.mcpClient().callTool({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.