Skip to main content
Glama
mongodb-developer

MongoDB Atlas MCP Server

Official

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
NameRequiredDescriptionDefault
projectIdYesThe ID of the Atlas project.
clusterNameYesThe name of the cluster.

Implementation Reference

  • 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 }; } }
  • 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;
  • 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; }

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-developer/mcp-mongodb-atlas'

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