Skip to main content
Glama
mongodb-developer

MongoDB Atlas MCP Server

Official

create_atlas_user

Create a new database user with admin privileges for an existing MongoDB Atlas project to manage database access and permissions.

Instructions

Creates a new database user for an existing Atlas project. User will have atlasAdmin role.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdYesThe ID of the Atlas project.
usernameYesThe username for the database user.
passwordYesThe password for the database user.
rolesNoAn array of roles for the user. Default is [atlasAdmin].

Implementation Reference

  • The core handler function that implements the 'create_atlas_user' tool logic. It constructs a POST request to the MongoDB Atlas API to create a database user in the admin database with specified roles.
    private async createAtlasUser(input: CreateUserInput) {
      try {
        const url = `https://cloud.mongodb.com/api/atlas/v1.0/groups/${input.projectId}/databaseUsers`;
        const body = {
          databaseName: "admin",
          username: input.username,
          password: input.password,
          roles: input.roles.map(role => ({ databaseName: 'admin', roleName: role }))
        };
    
        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
        };
      }
    }
  • TypeScript interface defining the expected input structure for the createAtlasUser handler.
    interface CreateUserInput {
      projectId: string;
      username: string;
      password: string;
      roles: string[];
    }
  • src/index.ts:431-459 (registration)
    MCP tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and JSON inputSchema.
    {
      name: 'create_atlas_user',
      description: 'Creates a new database user for an existing Atlas project. User will have atlasAdmin role.',
      inputSchema: {
        type: 'object',
        properties: {
          projectId: {
            type: 'string',
            description: 'The ID of the Atlas project.',
          },
          username: {
            type: 'string',
            description: 'The username for the database user.',
          },
          password: {
            type: 'string',
            description: 'The password for the database user.',
          },
          roles: {
            type: 'array',
            items: {
              type: 'string',
            },
            description: 'An array of roles for the user. Default is [atlasAdmin].',
          }
        },
        required: ['projectId', 'username', 'password'],
      },
    },
  • src/index.ts:555-556 (registration)
    Dispatcher logic in CallToolRequestSchema that routes the tool call to the createAtlasUser handler.
    case 'create_atlas_user':
      result = await this.createAtlasUser(input as unknown as CreateUserInput);
  • Shared helper method for making authenticated requests to the Atlas API using Digest authentication, used by the createAtlasUser handler.
    private async makeAtlasRequest(url: string, method: string, body?: any) {
      // Step 1: Make initial request to get digest challenge
      const initialResponse = await fetch(url, {
        method,
        headers: {
          'Content-Type': 'application/json'
        },
        body: body ? JSON.stringify(body) : undefined
      });
    
      // Check if we got a 401 with WWW-Authenticate header (digest challenge)
      if (initialResponse.status === 401) {
        const wwwAuthHeader = initialResponse.headers.get('WWW-Authenticate');
        if (!wwwAuthHeader || !wwwAuthHeader.startsWith('Digest ')) {
          throw new Error('Expected Digest authentication challenge not received');
        }
    
        // Parse the digest challenge
        const authDetails: Record<string, string> = {};
        wwwAuthHeader.substring(7).split(',').forEach(part => {
          const [key, value] = part.trim().split('=');
          // Remove quotes if present
          authDetails[key] = value.startsWith('"') ? value.slice(1, -1) : value;
        });
    
        // Generate a random client nonce (cnonce)
        const cnonce = Math.random().toString(36).substring(2, 15);
        const nc = '00000001'; // nonce count, incremented for each request with the same nonce
    
        // Calculate the response hash
        const ha1 = this.md5(`${this.apiKey}:${authDetails.realm}:${this.privateKey}`);
        const ha2 = this.md5(`${method}:${new URL(url).pathname}`);
        const response = this.md5(`${ha1}:${authDetails.nonce}:${nc}:${cnonce}:${authDetails.qop}:${ha2}`);
    
        // Build the Authorization header
        const authHeader = `Digest username="${this.apiKey}", realm="${authDetails.realm}", nonce="${authDetails.nonce}", uri="${new URL(url).pathname}", qop=${authDetails.qop}, nc=${nc}, cnonce="${cnonce}", response="${response}", algorithm=${authDetails.algorithm || 'MD5'}`;
    
        // Make the actual request with the digest authentication
        const digestResponse = await fetch(url, {
          method,
          headers: {
            'Content-Type': 'application/json',
            'Authorization': authHeader
          },
          body: body ? JSON.stringify(body) : undefined
        });
    
        if (!digestResponse.ok) {
          throw new Error(`Atlas API error: ${digestResponse.statusText}`);
        }
    
        return digestResponse.json();
      } else if (initialResponse.ok) {
        // If the initial request succeeded without authentication (unlikely)
        return initialResponse.json();
      } else {
        throw new Error(`Atlas API error: ${initialResponse.statusText}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the action is a creation operation and mentions the default role, but lacks details on permissions required, whether the operation is idempotent, rate limits, or what happens on failure. For a mutation tool with zero annotation coverage, this is a significant gap in behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and includes key details (project requirement and default role). There is no wasted verbiage, and every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 4 parameters), no annotations, and no output schema, the description is moderately complete. It covers the basic purpose and default role but lacks details on behavioral aspects like error handling, response format, or integration with sibling tools. It's adequate but has clear gaps for a creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description adds minimal value beyond the schema by mentioning the default role ('atlasAdmin'), which is partially covered in the schema's description of the 'roles' parameter. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Creates a new database user') and the resource ('for an existing Atlas project'), with specific role information ('atlasAdmin role'). It distinguishes from siblings like 'create_atlas_cluster' (creates clusters) and 'list_atlas_projects' (lists projects), though it doesn't explicitly mention these distinctions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('for an existing Atlas project'), suggesting this tool should be used when a project already exists. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'setup_atlas_network_access' or prerequisites beyond project existence.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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