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

mongodb-js / mongodb-mcp-server / 16123662219

07 Jul 2025 05:25PM UTC coverage: 60.879% (-13.3%) from 74.187%
16123662219

Pull #343

github

web-flow
Merge 24298edad into 5b7ba55e0
Pull Request #343: fix: turn atlas-connect-cluster async

183 of 411 branches covered (44.53%)

Branch coverage included in aggregate %.

0 of 34 new or added lines in 1 file covered. (0.0%)

129 existing lines in 15 files now uncovered.

704 of 1046 relevant lines covered (67.3%)

59.03 hits per line

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

25.0
/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";
33✔
10
    protected description = "Create an MongoDB Atlas database user";
33✔
11
    protected operationType: OperationType = "create";
33✔
12
    protected argsShape = {
33✔
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> {
UNCOV
47
        const shouldGeneratePassword = !password;
×
UNCOV
48
        if (shouldGeneratePassword) {
×
UNCOV
49
            password = await generateSecurePassword();
×
50
        }
51

UNCOV
52
        const input = {
×
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
×
63
                ? clusters.map((cluster) => ({
×
64
                      type: "CLUSTER",
65
                      name: cluster,
66
                  }))
67
                : undefined,
68
        } as CloudDatabaseUser;
69

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

UNCOV
79
        return {
×
80
            content: [
81
                {
82
                    type: "text",
83
                    text: `User "${username}" created successfully${shouldGeneratePassword ? ` with password: \`${password}\`` : ""}.`,
×
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

© 2025 Coveralls, Inc