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

mongodb-js / mongodb-mcp-server / 14590701503

22 Apr 2025 08:50AM UTC coverage: 50.118% (-0.9%) from 50.98%
14590701503

Pull #82

github

blva
lint
Pull Request #82: add create project tool

23 of 150 branches covered (15.33%)

Branch coverage included in aggregate %.

8 of 31 new or added lines in 3 files covered. (25.81%)

4 existing lines in 1 file now uncovered.

401 of 696 relevant lines covered (57.61%)

36.62 hits per line

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

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

7
export class ListDBUsersTool extends AtlasToolBase {
6✔
8
    protected name = "atlas-list-db-users";
42✔
9
    protected description = "List MongoDB Atlas database users";
42✔
10
    protected operationType: OperationType = "read";
42✔
11
    protected argsShape = {
42✔
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();
×
17

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

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

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

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

57
function formatScopes(scopes?: UserScope[]) {
58
    if (!scopes?.length) {
×
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