• 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

82.35
/src/tools/atlas/createAccessList.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

6
const DEFAULT_COMMENT = "Added by Atlas MCP";
18✔
7

8
export class CreateAccessListTool extends AtlasToolBase {
18✔
9
    protected name = "atlas-create-access-list";
18✔
10
    protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
18✔
11
    protected operationType: OperationType = "create";
18✔
12
    protected argsShape = {
18✔
13
        projectId: z.string().describe("Atlas project ID"),
14
        ipAddresses: z
15
            .array(z.string().ip({ version: "v4" }))
16
            .describe("IP addresses to allow access from")
17
            .optional(),
18
        cidrBlocks: z.array(z.string().cidr()).describe("CIDR blocks to allow access from").optional(),
19
        currentIpAddress: z.boolean().describe("Add the current IP address").default(false),
20
        comment: z.string().describe("Comment for the access list entries").default(DEFAULT_COMMENT).optional(),
21
    };
22

23
    protected async execute({
24
        projectId,
25
        ipAddresses,
26
        cidrBlocks,
27
        comment,
28
        currentIpAddress,
29
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
30
        this.session.ensureAuthenticated();
1!
UNCOV
31

×
32
        if (!ipAddresses?.length && !cidrBlocks?.length && !currentIpAddress) {
33
            throw new Error("One of  ipAddresses, cidrBlocks, currentIpAddress must be provided.");
34
        }
2!
35

36
        const ipInputs = (ipAddresses || []).map((ipAddress) => ({
37
            groupId: projectId,
4✔
38
            ipAddress,
39
            comment: comment || DEFAULT_COMMENT,
40
        }));
1✔
41

1✔
42
        if (currentIpAddress) {
1✔
43
            const currentIp = await this.session.apiClient.getIpInfo();
44
            const input = {
45
                groupId: projectId,
2✔
46
                ipAddress: currentIp.currentIpv4Address,
47
                comment: comment || DEFAULT_COMMENT,
1✔
48
            };
49
            ipInputs.push(input);
50
        }
2!
51

52
        const cidrInputs = (cidrBlocks || []).map((cidrBlock) => ({
53
            groupId: projectId,
4✔
54
            cidrBlock,
55
            comment: comment || DEFAULT_COMMENT,
56
        }));
1✔
57

58
        const inputs = [...ipInputs, ...cidrInputs];
1✔
59

60
        await this.session.apiClient.createProjectIpAccessList({
61
            params: {
62
                path: {
63
                    groupId: projectId,
64
                },
65
            },
66
            body: inputs,
67
        });
1✔
68

69
        return {
70
            content: [
71
                {
72
                    type: "text",
73
                    text: `IP/CIDR ranges added to access list for project ${projectId}.`,
74
                },
75
            ],
76
        };
77
    }
78
}
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