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

mongodb-js / mongodb-mcp-server / 16292877152

15 Jul 2025 12:10PM UTC coverage: 77.385% (+2.1%) from 75.27%
16292877152

push

github

web-flow
chore(tests): switch to vitest (#363)

498 of 687 branches covered (72.49%)

Branch coverage included in aggregate %.

0 of 27 new or added lines in 2 files covered. (0.0%)

293 existing lines in 26 files now uncovered.

2828 of 3611 relevant lines covered (78.32%)

28.46 hits per line

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

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

8
export class CreateDBUserTool extends AtlasToolBase {
2✔
9
    public name = "atlas-create-db-user";
34✔
10
    protected description = "Create an MongoDB Atlas database user";
34✔
11
    public operationType: OperationType = "create";
34✔
12
    protected argsShape = {
34✔
13
        projectId: z.string().describe("Atlas project ID"),
34✔
14
        username: z.string().describe("Username for the new user"),
34✔
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
34✔
19
            .string()
34✔
20
            .optional()
34✔
21
            .nullable()
34✔
22
            .describe(
34✔
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."
34✔
24
            ),
34✔
25
        roles: z
34✔
26
            .array(
34✔
27
                z.object({
34✔
28
                    roleName: z.string().describe("Role name"),
34✔
29
                    databaseName: z.string().describe("Database name").default("admin"),
34✔
30
                    collectionName: z.string().describe("Collection name").optional(),
34✔
31
                })
34✔
32
            )
34✔
33
            .describe("Roles for the new user"),
34✔
34
        clusters: z
34✔
35
            .array(z.string())
34✔
36
            .describe("Clusters to assign the user to, leave empty for access to all clusters")
34✔
37
            .optional(),
34✔
38
    };
34✔
39

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

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

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

79
        return {
3✔
80
            content: [
3✔
81
                {
3✔
82
                    type: "text",
3✔
83
                    text: `User "${username}" created successfully${shouldGeneratePassword ? ` with password: \`${password}\`` : ""}.`,
3✔
84
                },
3✔
85
            ],
3✔
86
        };
3✔
87
    }
3✔
88
}
2✔
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

© 2025 Coveralls, Inc