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

mongodb-js / mongodb-mcp-server / 14617009034

23 Apr 2025 11:28AM UTC coverage: 76.414% (-0.3%) from 76.675%
14617009034

Pull #96

github

fmenezes
fix: ignore connectionString on atlas tools
Pull Request #96: feat: hide atlas tools when not configured

83 of 155 branches covered (53.55%)

Branch coverage included in aggregate %.

6 of 7 new or added lines in 2 files covered. (85.71%)

2 existing lines in 2 files now uncovered.

552 of 676 relevant lines covered (81.66%)

27.22 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";
16✔
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { AtlasToolBase } from "./atlasTool.js";
16✔
4
import { ToolArgs, OperationType } from "../tool.js";
5

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

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

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

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

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

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

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

67
        return {
1✔
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