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

mongodb-js / mongodb-mcp-server / 14618487127

23 Apr 2025 12:45PM UTC coverage: 78.42% (+1.7%) from 76.675%
14618487127

Pull #91

github

nirinchev
PR comments
Pull Request #91: chore: add tests for metadata actions

90 of 161 branches covered (55.9%)

Branch coverage included in aggregate %.

22 of 23 new or added lines in 4 files covered. (95.65%)

30 existing lines in 12 files now uncovered.

575 of 687 relevant lines covered (83.7%)

30.41 hits per line

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

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

7
export class CreateDBUserTool extends AtlasToolBase {
18✔
8
    protected name = "atlas-create-db-user";
18✔
9
    protected description = "Create an MongoDB Atlas database user";
18✔
10
    protected operationType: OperationType = "create";
18✔
11
    protected argsShape = {
18✔
12
        projectId: z.string().describe("Atlas project ID"),
13
        username: z.string().describe("Username for the new user"),
14
        password: z.string().describe("Password for the new user"),
15
        roles: z
16
            .array(
17
                z.object({
18
                    roleName: z.string().describe("Role name"),
19
                    databaseName: z.string().describe("Database name").default("admin"),
20
                    collectionName: z.string().describe("Collection name").optional(),
21
                })
22
            )
23
            .describe("Roles for the new user"),
24
        clusters: z
25
            .array(z.string())
26
            .describe("Clusters to assign the user to, leave empty for access to all clusters")
27
            .optional(),
28
    };
29

30
    protected async execute({
31
        projectId,
32
        username,
33
        password,
34
        roles,
35
        clusters,
36
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
37
        this.session.ensureAuthenticated();
1✔
38

39
        const input = {
40
            groupId: projectId,
41
            awsIAMType: "NONE",
42
            databaseName: "admin",
43
            ldapAuthType: "NONE",
44
            oidcAuthType: "NONE",
45
            x509Type: "NONE",
46
            username,
47
            password,
1!
UNCOV
48
            roles: roles as unknown as DatabaseUserRole[],
×
49
            scopes: clusters?.length
50
                ? clusters.map((cluster) => ({
51
                      type: "CLUSTER",
52
                      name: cluster,
53
                  }))
54
                : undefined,
55
        } as CloudDatabaseUser;
1✔
56

57
        await this.session.apiClient.createDatabaseUser({
58
            params: {
59
                path: {
60
                    groupId: projectId,
61
                },
62
            },
63
            body: input,
64
        });
1✔
65

66
        return {
67
            content: [{ type: "text", text: `User "${username}" created sucessfully.` }],
68
        };
69
    }
70
}
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