create_atlas_cluster
Deploy a new MongoDB Atlas cluster in an existing project by specifying cloud provider, region, and instance size.
Instructions
Creates a new Atlas cluster in an existing Atlas project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | The ID of the Atlas project. | |
| clusterName | Yes | The name of the cluster to create. | |
| region | Yes | The cloud provider region to deploy the cluster in. eg. US_EAST_1 | |
| cloudProvider | Yes | The cloud provider (e.g., AWS, GCP, AZURE). | |
| tier | Yes | The instance size (e.g., M0, M2, M5). |
Implementation Reference
- src/index.ts:121-159 (handler)The main handler function that implements the logic for creating an Atlas cluster, including special handling for M0 tier and API request to MongoDB Atlas.private async createAtlasCluster(input: CreateClusterInput) { if (input.tier === 'M0') { return { content: [{ type: 'text', text: 'M0 (Free Tier) clusters cannot be created via the API. Please use the MongoDB Atlas UI to create an M0 cluster.' }], isError: true }; } try { const url = `https://cloud.mongodb.com/api/atlas/v1.0/groups/${input.projectId}/clusters?pretty=true`; const body = { name: input.clusterName, providerSettings: { providerName: input.cloudProvider, instanceSizeName: input.tier, regionName: input.region } }; const result = await this.makeAtlasRequest(url, 'POST', body); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: 'text', text: error.message }], isError: true }; } }
- src/index.ts:12-18 (schema)TypeScript interface defining the input schema for the create_atlas_cluster tool.interface CreateClusterInput { projectId: string; clusterName: string; region: string; cloudProvider: string; tier: string; }
- src/index.ts:380-408 (registration)Registration of the create_atlas_cluster tool in the ListTools response, including name, description, and detailed input schema.{ name: 'create_atlas_cluster', description: 'Creates a new Atlas cluster in an existing Atlas project.', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'The ID of the Atlas project.', }, clusterName: { type: 'string', description: 'The name of the cluster to create.', }, region: { type: 'string', description: 'The cloud provider region to deploy the cluster in. eg. US_EAST_1', }, cloudProvider: { type: 'string', description: 'The cloud provider (e.g., AWS, GCP, AZURE).', }, tier: { type: 'string', description: 'The instance size (e.g., M0, M2, M5).', } }, required: ['projectId', 'clusterName', 'region', 'cloudProvider', 'tier'], },
- src/index.ts:503-587 (registration)The CallTool request handler that dispatches to createAtlasCluster for 'create_atlas_cluster' tool calls, including input validation.this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { if (!['create_atlas_cluster', 'setup_atlas_network_access', 'create_atlas_user', 'get_atlas_connection_strings', 'list_atlas_projects', 'list_atlas_clusters'].includes(request.params.name)) { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!request.params.arguments) { throw new McpError(ErrorCode.InvalidParams, 'Missing arguments'); } const input = request.params.arguments as Record<string, unknown>; switch (request.params.name) { case 'create_atlas_cluster': if (!isValidCreateClusterInput(input)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid cluster creation arguments'); } break; case 'setup_atlas_network_access': if (!input.projectId || !input.ipAddresses || !Array.isArray(input.ipAddresses)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid network access arguments'); } break; case 'create_atlas_user': if (!input.projectId || !input.username || !input.password) { throw new McpError(ErrorCode.InvalidParams, 'Invalid user creation arguments'); } break; case 'get_atlas_connection_strings': if (!input.projectId || !input.clusterName) { throw new McpError(ErrorCode.InvalidParams, 'Invalid connection string arguments'); } break; case 'list_atlas_clusters': if (!input.projectId) { throw new McpError(ErrorCode.InvalidParams, 'Invalid list clusters arguments'); } break; } let result; try { switch (request.params.name) { case 'create_atlas_cluster': result = await this.createAtlasCluster(input as unknown as CreateClusterInput); break; case 'setup_atlas_network_access': result = await this.setupAtlasNetworkAccess(input as unknown as NetworkAccessInput); break; case 'create_atlas_user': result = await this.createAtlasUser(input as unknown as CreateUserInput); break; case 'get_atlas_connection_strings': result = await this.getAtlasConnectionStrings(input as unknown as ConnectionStringsInput); break; case 'list_atlas_projects': result = await this.listAtlasProjects(); break; case 'list_atlas_clusters': result = await this.listAtlasClusters(input as unknown as ListClustersInput); break; default: throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`); } // Ensure we return the expected format return { content: result.content, _meta: request.params._meta }; } catch (error: any) { // Handle any errors that might occur return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true, _meta: request.params._meta }; } });
- src/index.ts:41-48 (helper)Input validation function specifically for CreateClusterInput used before calling the handler.const isValidCreateClusterInput = (args: any): args is CreateClusterInput => typeof args === 'object' && args !== null && typeof args.projectId === 'string' && typeof args.clusterName === 'string' && typeof args.region === 'string' && typeof args.cloudProvider === 'string' && typeof args.tier === 'string';