• 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

74.07
/src/tools/atlas/listDBUsers.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 { DatabaseUserRole, UserScope } from "../../common/atlas/openapi.js";
6

7
export class ListDBUsersTool extends AtlasToolBase {
18✔
8
    protected name = "atlas-list-db-users";
18✔
9
    protected description = "List MongoDB Atlas database users";
18✔
10
    protected operationType: OperationType = "read";
18✔
11
    protected argsShape = {
18✔
12
        projectId: z.string().describe("Atlas project ID to filter DB users"),
13
    };
14

15
    protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
16
        this.session.ensureAuthenticated();
1✔
17

18
        const data = await this.session.apiClient.listDatabaseUsers({
19
            params: {
20
                path: {
21
                    groupId: projectId,
22
                },
23
            },
24
        });
1!
UNCOV
25

×
26
        if (!data?.results?.length) {
27
            throw new Error("No database users found.");
28
        }
29

1✔
30
        const output =
31
            `Username | Roles | Scopes
32
----------------|----------------|----------------
33
` +
34
            data.results
1✔
35
                .map((user) => {
36
                    return `${user.username} | ${formatRoles(user.roles)} | ${formatScopes(user.scopes)}`;
37
                })
1✔
38
                .join("\n");
39
        return {
40
            content: [{ type: "text", text: output }],
41
        };
42
    }
43
}
44

1!
UNCOV
45
function formatRoles(roles?: DatabaseUserRole[]) {
×
46
    if (!roles?.length) {
47
        return "N/A";
1✔
48
    }
49
    return roles
50
        .map(
1!
51
            (role) =>
52
                `${role.roleName}${role.databaseName ? `@${role.databaseName}${role.collectionName ? `:${role.collectionName}` : ""}` : ""}`
53
        )
54
        .join(", ");
55
}
56

1✔
57
function formatScopes(scopes?: UserScope[]) {
1✔
58
    if (!scopes?.length) {
UNCOV
59
        return "All";
×
60
    }
61
    return scopes.map((scope) => `${scope.type}:${scope.name}`).join(", ");
62
}
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