• 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

16.28
/src/tools/atlas/listClusters.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 { PaginatedClusterDescription20240805, PaginatedOrgGroupView, Group } from "../../common/atlas/openapi.js";
6

7
export class ListClustersTool extends AtlasToolBase {
6✔
8
    protected name = "atlas-list-clusters";
42✔
9
    protected description = "List MongoDB Atlas clusters";
42✔
10
    protected operationType: OperationType = "read";
42✔
11
    protected argsShape = {
42✔
12
        projectId: z.string().describe("Atlas project ID to filter clusters").optional(),
13
    };
14

15
    protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
16
        this.session.ensureAuthenticated();
×
17

18
        if (!projectId) {
×
19
            const data = await this.session.apiClient.listClustersForAllProjects();
×
20

21
            return this.formatAllClustersTable(data);
×
22
        } else {
23
            const project = await this.session.apiClient.getProject({
×
24
                params: {
25
                    path: {
26
                        groupId: projectId,
27
                    },
28
                },
29
            });
30

31
            if (!project?.id) {
×
32
                throw new Error(`Project with ID "${projectId}" not found.`);
×
33
            }
34

35
            const data = await this.session.apiClient.listClusters({
×
36
                params: {
37
                    path: {
38
                        groupId: project.id || "",
×
39
                    },
40
                },
41
            });
42

43
            return this.formatClustersTable(project, data);
×
44
        }
45
    }
46

47
    private formatAllClustersTable(clusters?: PaginatedOrgGroupView): CallToolResult {
48
        if (!clusters?.results?.length) {
×
49
            throw new Error("No clusters found.");
×
50
        }
51
        const rows = clusters.results
×
52
            .map((result) => {
53
                return (result.clusters || []).map((cluster) => {
×
54
                    return { ...result, ...cluster, clusters: undefined };
×
55
                });
56
            })
57
            .flat()
58
            .map((cluster) => {
59
                return `${cluster.groupName} (${cluster.groupId}) | ${cluster.name}`;
×
60
            })
61
            .join("\n");
62
        return {
×
63
            content: [
64
                { type: "text", text: `Here are your MongoDB Atlas clusters:` },
65
                {
66
                    type: "text",
67
                    text: `Project | Cluster Name
68
----------------|----------------
69
${rows}`,
70
                },
71
            ],
72
        };
73
    }
74

75
    private formatClustersTable(project: Group, clusters?: PaginatedClusterDescription20240805): CallToolResult {
76
        if (!clusters?.results?.length) {
×
77
            throw new Error("No clusters found.");
×
78
        }
79
        const rows = clusters.results
×
80
            .map((cluster) => {
81
                const connectionString = cluster.connectionStrings?.standard || "N/A";
×
82
                const mongoDBVersion = cluster.mongoDBVersion || "N/A";
×
83
                return `${cluster.name} | ${cluster.stateName} | ${mongoDBVersion} | ${connectionString}`;
×
84
            })
85
            .join("\n");
86
        return {
×
87
            content: [
88
                {
89
                    type: "text",
90
                    text: `Here are your MongoDB Atlas clusters in project "${project.name}" (${project.id}):`,
91
                },
92
                {
93
                    type: "text",
94
                    text: `Cluster Name | State | MongoDB Version | Connection String
95
----------------|----------------|----------------|----------------|----------------
96
${rows}`,
97
                },
98
            ],
99
        };
100
    }
101
}
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