Skip to main content
Glama
mongodb-developer

MongoDB Atlas MCP Server

Official

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

Implementation Reference

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

Other Tools

Related Tools

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