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

mongodb-js / mongodb-mcp-server / 14733421831

29 Apr 2025 02:11PM UTC coverage: 68.999%. First build
14733421831

Pull #164

github

gagik
test
Pull Request #164: test: dependencies check

109 of 235 branches covered (46.38%)

Branch coverage included in aggregate %.

670 of 894 relevant lines covered (74.94%)

45.18 hits per line

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

23.53
/src/tools/atlas/create/createAccessList.ts
1
import { z } from "zod";
30✔
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { AtlasToolBase } from "../atlasTool.js";
30✔
4
import { ToolArgs, OperationType } from "../../tool.js";
5

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

8
export class CreateAccessListTool extends AtlasToolBase {
30✔
9
    protected name = "atlas-create-access-list";
26✔
10
    protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
26✔
11
    protected operationType: OperationType = "create";
26✔
12
    protected argsShape = {
26✔
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
        if (!ipAddresses?.length && !cidrBlocks?.length && !currentIpAddress) {
×
31
            throw new Error("One of  ipAddresses, cidrBlocks, currentIpAddress must be provided.");
×
32
        }
33

34
        const ipInputs = (ipAddresses || []).map((ipAddress) => ({
×
35
            groupId: projectId,
36
            ipAddress,
37
            comment: comment || DEFAULT_COMMENT,
×
38
        }));
39

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

50
        const cidrInputs = (cidrBlocks || []).map((cidrBlock) => ({
×
51
            groupId: projectId,
52
            cidrBlock,
53
            comment: comment || DEFAULT_COMMENT,
×
54
        }));
55

56
        const inputs = [...ipInputs, ...cidrInputs];
×
57

58
        await this.session.apiClient.createProjectIpAccessList({
×
59
            params: {
60
                path: {
61
                    groupId: projectId,
62
                },
63
            },
64
            body: inputs,
65
        });
66

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