• 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

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

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

8
export class CreateAccessListTool extends AtlasToolBase {
6✔
9
    protected name = "atlas-create-access-list";
42✔
10
    protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
42✔
11
    protected operationType: OperationType = "create";
42✔
12
    protected argsShape = {
42✔
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();
×
31

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

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

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

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

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

60
        await this.session.apiClient.createProjectIpAccessList({
×
61
            params: {
62
                path: {
63
                    groupId: projectId,
64
                },
65
            },
66
            body: inputs,
67
        });
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