get_atlas_connection_strings
Retrieve connection strings for MongoDB Atlas clusters to establish database connectivity in applications.
Instructions
Retrieves connection strings for a 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. |
Implementation Reference
- src/index.ts:215-240 (handler)The main handler function that retrieves the cluster details from the MongoDB Atlas API, enhances the connection strings by adding an appName parameter using a helper function, and returns the result in MCP format.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 expected input parameters for the getAtlasConnectionStrings handler.interface ConnectionStringsInput { projectId: string; clusterName: string; }
- src/index.ts:460-477 (registration)Tool registration in the MCP listTools handler, defining the tool name, description, and 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)Dispatch logic in the MCP callTool handler that invokes the getAtlasConnectionStrings method when the tool is called.case 'get_atlas_connection_strings': result = await this.getAtlasConnectionStrings(input as unknown as ConnectionStringsInput); break;
- src/index.ts:264-311 (helper)Supporting helper method that modifies Atlas cluster response connection strings by appending an appName query parameter for tracking.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; }