• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14788116886

02 May 2025 03:32AM UTC coverage: 74.619% (-7.8%) from 82.446%
14788116886

push

github

web-flow
Incorrect link of VSCode's MCP usage

- Change link of MCP usage

164 of 296 branches covered (55.41%)

Branch coverage included in aggregate %.

668 of 819 relevant lines covered (81.56%)

82.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/tools/atlas/create/createDBUser.ts
1
import { z } from "zod";
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { AtlasToolBase } from "../atlasTool.js";
4
import { ToolArgs, OperationType } from "../../tool.js";
5
import { CloudDatabaseUser, DatabaseUserRole } from "../../../common/atlas/openapi.js";
6
import { generateSecurePassword } from "../../../common/atlas/generatePassword.js";
7

8
export class CreateDBUserTool extends AtlasToolBase {
9
    protected name = "atlas-create-db-user";
54✔
10
    protected description = "Create an MongoDB Atlas database user";
54✔
11
    protected operationType: OperationType = "create";
54✔
12
    protected argsShape = {
54✔
13
        projectId: z.string().describe("Atlas project ID"),
14
        username: z.string().describe("Username for the new user"),
15
        // Models will generate overly simplistic passwords like SecurePassword123 or
16
        // AtlasPassword123, which are easily guessable and exploitable. We're instructing
17
        // the model not to try and generate anything and instead leave the field unset.
18
        password: z
19
            .string()
20
            .optional()
21
            .nullable()
22
            .describe(
23
                "Password for the new user. If the user hasn't supplied an explicit password, leave it unset and under no circumstances try to generate a random one. A secure password will be generated by the MCP server if necessary."
24
            ),
25
        roles: z
26
            .array(
27
                z.object({
28
                    roleName: z.string().describe("Role name"),
29
                    databaseName: z.string().describe("Database name").default("admin"),
30
                    collectionName: z.string().describe("Collection name").optional(),
31
                })
32
            )
33
            .describe("Roles for the new user"),
34
        clusters: z
35
            .array(z.string())
36
            .describe("Clusters to assign the user to, leave empty for access to all clusters")
37
            .optional(),
38
    };
39

40
    protected async execute({
41
        projectId,
42
        username,
43
        password,
44
        roles,
45
        clusters,
46
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
47
        const shouldGeneratePassword = !password;
6✔
48
        if (shouldGeneratePassword) {
6✔
49
            password = await generateSecurePassword();
4✔
50
        }
51

52
        const input = {
6✔
53
            groupId: projectId,
54
            awsIAMType: "NONE",
55
            databaseName: "admin",
56
            ldapAuthType: "NONE",
57
            oidcAuthType: "NONE",
58
            x509Type: "NONE",
59
            username,
60
            password,
61
            roles: roles as unknown as DatabaseUserRole[],
62
            scopes: clusters?.length
6!
63
                ? clusters.map((cluster) => ({
×
64
                      type: "CLUSTER",
65
                      name: cluster,
66
                  }))
67
                : undefined,
68
        } as CloudDatabaseUser;
69

70
        await this.session.apiClient.createDatabaseUser({
6✔
71
            params: {
72
                path: {
73
                    groupId: projectId,
74
                },
75
            },
76
            body: input,
77
        });
78

79
        return {
6✔
80
            content: [
81
                {
82
                    type: "text",
83
                    text: `User "${username}" created successfully${shouldGeneratePassword ? ` with password: \`${password}\`` : ""}.`,
6✔
84
                },
85
            ],
86
        };
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc