Skip to content

Commit c4f2d5a

Browse files
committed
feat: add more details about atlas connect flow
1 parent d471cdd commit c4f2d5a

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

src/tools/atlas/connect/connectCluster.ts

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class ConnectClusterTool extends AtlasToolBase {
6262
private async prepareClusterConnection(
6363
projectId: string,
6464
clusterName: string
65-
): Promise<{ connectionString: string; atlas: AtlasClusterConnectionInfo }> {
65+
): Promise<{ connectionString: string; atlas: AtlasClusterConnectionInfo; userCreated: boolean }> {
6666
const cluster = await inspectCluster(this.session.apiClient, projectId, clusterName);
6767

6868
if (!cluster.connectionString) {
@@ -110,7 +110,7 @@ export class ConnectClusterTool extends AtlasToolBase {
110110
cn.password = password;
111111
cn.searchParams.set("authSource", "admin");
112112

113-
return { connectionString: cn.toString(), atlas: connectedAtlasCluster };
113+
return { connectionString: cn.toString(), atlas: connectedAtlasCluster, userCreated: true };
114114
}
115115

116116
private async connectToCluster(connectionString: string, atlas: AtlasClusterConnectionInfo): Promise<void> {
@@ -190,19 +190,29 @@ export class ConnectClusterTool extends AtlasToolBase {
190190
}
191191

192192
protected async execute({ projectId, clusterName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
193-
await ensureCurrentIpInAccessList(this.session.apiClient, projectId);
193+
const ipAccessListUpdated = await ensureCurrentIpInAccessList(this.session.apiClient, projectId);
194+
let createdUser = false;
195+
194196
for (let i = 0; i < 60; i++) {
195197
const state = this.queryConnection(projectId, clusterName);
196198
switch (state) {
197199
case "connected": {
198-
return {
199-
content: [
200-
{
201-
type: "text",
202-
text: `Connected to cluster "${clusterName}".`,
203-
},
204-
],
205-
};
200+
const content: CallToolResult["content"] = [
201+
{
202+
type: "text",
203+
text: `Connected to cluster "${clusterName}".`,
204+
},
205+
];
206+
207+
// Add feedback about IP access list if it was updated
208+
if (ipAccessListUpdated) {
209+
content.push({
210+
type: "text",
211+
text: `Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.`,
212+
});
213+
}
214+
215+
return { content };
206216
}
207217
case "connecting":
208218
case "unknown": {
@@ -212,8 +222,12 @@ export class ConnectClusterTool extends AtlasToolBase {
212222
case "disconnected":
213223
default: {
214224
await this.session.disconnect();
215-
const { connectionString, atlas } = await this.prepareClusterConnection(projectId, clusterName);
225+
const { connectionString, atlas, userCreated } = await this.prepareClusterConnection(
226+
projectId,
227+
clusterName
228+
);
216229

230+
createdUser = userCreated;
217231
// try to connect for about 5 minutes asynchronously
218232
void this.connectToCluster(connectionString, atlas).catch((err: unknown) => {
219233
const error = err instanceof Error ? err : new Error(String(err));
@@ -230,21 +244,31 @@ export class ConnectClusterTool extends AtlasToolBase {
230244
await sleep(500);
231245
}
232246

233-
return {
234-
content: [
235-
{
236-
type: "text" as const,
237-
text: `Attempting to connect to cluster "${clusterName}"...`,
238-
},
239-
{
240-
type: "text" as const,
241-
text: `Warning: Provisioning a user and connecting to the cluster may take more time, please check again in a few seconds.`,
242-
},
243-
{
244-
type: "text" as const,
245-
text: `Warning: Make sure your IP address was enabled in the allow list setting of the Atlas cluster.`,
246-
},
247-
],
248-
};
247+
const content: CallToolResult["content"] = [
248+
{
249+
type: "text" as const,
250+
text: `Attempting to connect to cluster "${clusterName}"...`,
251+
},
252+
{
253+
type: "text" as const,
254+
text: `Warning: Provisioning a user and connecting to the cluster may take more time, please check again in a few seconds.`,
255+
},
256+
];
257+
258+
if (ipAccessListUpdated) {
259+
content.push({
260+
type: "text" as const,
261+
text: `Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.`,
262+
});
263+
}
264+
265+
if (createdUser) {
266+
content.push({
267+
type: "text" as const,
268+
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`,
269+
});
270+
}
271+
272+
return { content };
249273
}
250274
}

0 commit comments

Comments
 (0)