get_atlas_connection_strings
Retrieve connection strings for MongoDB Atlas clusters by specifying the project ID and cluster name to enable direct database access.
Instructions
Retrieves connection strings for a cluster in an existing Atlas project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clusterName | Yes | The name of the cluster. | |
| projectId | Yes | The ID of the Atlas project. |
Implementation Reference
- src/index.ts:215-240 (handler)The handler function that retrieves connection strings for the specified Atlas project and cluster by making an API request, enhancing the response with appName parameters, and formatting the output or error response.private async getAtlasConnectionStrings(input: ConnectionStringsInput) { try { const url = `https://cloud.mongodb.com/api/atlas/v1.0/groups/${input.projectId}/clusters/${input.clusterName}`; const result = await this.makeAtlasRequest(url, 'GET'); // Add appName to connection strings if they exist if (result.connectionStrings) { this.addAppNameToConnectionStrings(result); } 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:32-35 (schema)TypeScript interface defining the input parameters for the getAtlasConnectionStrings tool: projectId and clusterName.interface ConnectionStringsInput { projectId: string; clusterName: string; }
- src/index.ts:460-477 (registration)Tool registration in the ListTools response, including name, description, and JSON input schema.{ name: 'get_atlas_connection_strings', description: 'Retrieves connection strings for a 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.', }, }, required: ['projectId', 'clusterName'], }, },
- src/index.ts:558-560 (registration)Invocation of the handler in the CallToolRequest switch statement.case 'get_atlas_connection_strings': result = await this.getAtlasConnectionStrings(input as unknown as ConnectionStringsInput); break;
- src/index.ts:264-311 (helper)Helper function that modifies connection strings by appending an appName query parameter for telemetry/tracking purposes, used by the handler.private addAppNameToConnectionStrings(result: any) { const appName = "devrel.integration.mcp-atlas"; // Helper function to safely add appName parameter to a connection string const addAppNameParam = (connectionString: string): string => { if (!connectionString) return connectionString; // Add appName parameter return connectionString + (connectionString.includes('?') ? '&' : '?') + `appName=${appName}`; }; // Handle single cluster object if (result.connectionStrings) { // Add appName to standard connection string if (result.connectionStrings.standard) { result.connectionStrings.standard = addAppNameParam(result.connectionStrings.standard); } // Add appName to standardSrv connection string if (result.connectionStrings.standardSrv) { result.connectionStrings.standardSrv = addAppNameParam(result.connectionStrings.standardSrv); } // Add appName to other connection string formats if (result.mongoURI) { result.mongoURI = addAppNameParam(result.mongoURI); } if (result.mongoURIWithOptions) { result.mongoURIWithOptions = addAppNameParam(result.mongoURIWithOptions); } if (result.srvAddress) { result.srvAddress = addAppNameParam(result.srvAddress); } } // Handle array of clusters (for listAtlasClusters) if (result.results && Array.isArray(result.results)) { result.results.forEach((cluster: any) => { if (cluster.connectionStrings) { this.addAppNameToConnectionStrings(cluster); } }); } return result; }