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

mongodb-js / mongodb-mcp-server / 17657973871

11 Sep 2025 09:37PM UTC coverage: 81.59% (+0.4%) from 81.188%
17657973871

Pull #524

github

web-flow
Merge 7617674d0 into d6b84c7bd
Pull Request #524: chore: update smithery dockerfile to be closer to the official one

962 of 1279 branches covered (75.22%)

Branch coverage included in aggregate %.

4866 of 5864 relevant lines covered (82.98%)

46.3 hits per line

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

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

10
export const CreateDBUserArgs = {
2✔
11
    projectId: AtlasArgs.projectId().describe("Atlas project ID"),
2✔
12
    username: AtlasArgs.username().describe("Username for the new user"),
2✔
13
    // Models will generate overly simplistic passwords like SecurePassword123 or
14
    // AtlasPassword123, which are easily guessable and exploitable. We're instructing
15
    // the model not to try and generate anything and instead leave the field unset.
16
    password: AtlasArgs.password()
2✔
17
        .optional()
2✔
18
        .nullable()
2✔
19
        .describe(
2✔
20
            "Password for the new user. IMPORTANT: 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."
2✔
21
        ),
2✔
22
    roles: z
2✔
23
        .array(
2✔
24
            z.object({
2✔
25
                roleName: CommonArgs.string().describe("Role name"),
2✔
26
                databaseName: CommonArgs.string().describe("Database name").default("admin"),
2✔
27
                collectionName: CommonArgs.string().describe("Collection name").optional(),
2✔
28
            })
2✔
29
        )
2✔
30
        .describe("Roles for the new user"),
2✔
31
    clusters: z
2✔
32
        .array(AtlasArgs.clusterName())
2✔
33
        .describe("Clusters to assign the user to, leave empty for access to all clusters")
2✔
34
        .optional(),
2✔
35
};
2✔
36

37
export class CreateDBUserTool extends AtlasToolBase {
2✔
38
    public name = "atlas-create-db-user";
61✔
39
    protected description = "Create an MongoDB Atlas database user";
61✔
40
    public operationType: OperationType = "create";
61✔
41
    protected argsShape = {
61✔
42
        ...CreateDBUserArgs,
61✔
43
    };
61✔
44

45
    protected async execute({
2✔
46
        projectId,
4✔
47
        username,
4✔
48
        password,
4✔
49
        roles,
4✔
50
        clusters,
4✔
51
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
4✔
52
        await ensureCurrentIpInAccessList(this.session.apiClient, projectId);
4✔
53
        const shouldGeneratePassword = !password;
4✔
54
        if (shouldGeneratePassword) {
4✔
55
            password = await generateSecurePassword();
3✔
56
        }
3✔
57

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

76
        await this.session.apiClient.createDatabaseUser({
4✔
77
            params: {
4✔
78
                path: {
4✔
79
                    groupId: projectId,
4✔
80
                },
4✔
81
            },
4✔
82
            body: input,
4✔
83
        });
4✔
84

85
        this.session.keychain.register(username, "user");
4✔
86
        if (password) {
4✔
87
            this.session.keychain.register(password, "password");
4✔
88
        }
4✔
89

90
        return {
4✔
91
            content: [
4✔
92
                {
4✔
93
                    type: "text",
4✔
94
                    text: `User "${username}" created successfully${shouldGeneratePassword ? ` with password: \`${password}\`` : ""}.`,
4✔
95
                },
4✔
96
            ],
4✔
97
        };
4✔
98
    }
4✔
99
}
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