Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

atlas-connect-cluster

Connect to a MongoDB Atlas cluster by specifying project ID, cluster name, and connection type for database operations and management.

Instructions

Connect to MongoDB Atlas cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdYesAtlas project ID
clusterNameYesAtlas cluster name
connectionTypeNoType of connection (standard, private, or privateEndpoint) to an Atlas clusterstandard

Implementation Reference

  • The main handler function that executes the tool logic: disconnects if needed, prepares connection string with temporary user, adds IP to access list, attempts connection with retries, and returns appropriate messages.
    protected async execute({ projectId, clusterName, connectionType, }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const ipAccessListUpdated = await ensureCurrentIpInAccessList(this.session.apiClient, projectId); let createdUser = false; const state = this.queryConnection(projectId, clusterName); switch (state) { case "connected-to-other-cluster": case "disconnected": { await this.session.disconnect(); const { connectionString, atlas } = await this.prepareClusterConnection( projectId, clusterName, connectionType ); createdUser = true; // try to connect for about 5 minutes asynchronously void this.connectToCluster(connectionString, atlas).catch((err: unknown) => { const error = err instanceof Error ? err : new Error(String(err)); this.session.logger.error({ id: LogId.atlasConnectFailure, context: "atlas-connect-cluster", message: `error connecting to cluster: ${error.message}`, }); }); break; } case "connecting": case "connected": case "unknown": default: { break; } } for (let i = 0; i < 60; i++) { const state = this.queryConnection(projectId, clusterName); switch (state) { case "connected": { const content: CallToolResult["content"] = [ { type: "text", text: `Connected to cluster "${clusterName}".`, }, ]; if (ipAccessListUpdated) { content.push({ type: "text", text: addedIpAccessListMessage, }); } if (createdUser) { content.push({ type: "text", text: createdUserMessage, }); } return { content }; } case "connecting": case "unknown": case "connected-to-other-cluster": case "disconnected": default: { break; } } await sleep(500); // wait 500ms before checking the connection state again } const content: CallToolResult["content"] = [ { type: "text" as const, text: `Attempting to connect to cluster "${clusterName}"...`, }, { type: "text" as const, text: `Warning: Provisioning a user and connecting to the cluster may take more time, please check again in a few seconds.`, }, ]; if (ipAccessListUpdated) { content.push({ type: "text" as const, text: addedIpAccessListMessage, }); } if (createdUser) { content.push({ type: "text" as const, text: createdUserMessage, }); } return { content }; }
  • Input schema defining the arguments for the atlas-connect-cluster tool.
    export const ConnectClusterArgs = { projectId: AtlasArgs.projectId().describe("Atlas project ID"), clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"), connectionType: AtlasArgs.connectionType().describe( "Type of connection (standard, private, or privateEndpoint) to an Atlas cluster" ), };
  • Registration of all tools, including Atlas tools (which include ConnectClusterTool via barrel re-export from src/tools/atlas/tools.ts).
    import * as AtlasTools from "./atlas/tools.js"; import * as AtlasLocalTools from "./atlasLocal/tools.js"; import * as MongoDbTools from "./mongodb/tools.js"; import type { ToolClass } from "./tool.js"; // Export the collection of tools for easier reference export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });
  • Barrel export that makes ConnectClusterTool available for inclusion in the main tools registry.
    export { ConnectClusterTool } from "./connect/connectCluster.js";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mongodb-js/mongodb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server