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

mongodb-js / mongodb-mcp-server / 18911327516

29 Oct 2025 02:27PM UTC coverage: 80.317% (+0.09%) from 80.227%
18911327516

Pull #653

github

web-flow
Merge c9247e7ad into 01f799ccb
Pull Request #653: chore: update atlas tools output to json - MCP-264

1349 of 1815 branches covered (74.33%)

Branch coverage included in aggregate %.

37 of 60 new or added lines in 6 files covered. (61.67%)

2 existing lines in 2 files now uncovered.

6343 of 7762 relevant lines covered (81.72%)

71.36 hits per line

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

60.64
/src/tools/atlas/read/listClusters.ts
1
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import { AtlasToolBase } from "../atlasTool.js";
3✔
3
import type { ToolArgs, OperationType } from "../../tool.js";
4
import { formatUntrustedData } from "../../tool.js";
3✔
5
import type {
6
    PaginatedClusterDescription20240805,
7
    PaginatedOrgGroupView,
8
    Group,
9
    PaginatedFlexClusters20241113,
10
} from "../../../common/atlas/openapi.js";
11
import { formatCluster, formatFlexCluster } from "../../../common/atlas/cluster.js";
3✔
12
import { AtlasArgs } from "../../args.js";
3✔
13

14
export const ListClustersArgs = {
3✔
15
    projectId: AtlasArgs.projectId().describe("Atlas project ID to filter clusters").optional(),
3✔
16
};
3✔
17

18
export class ListClustersTool extends AtlasToolBase {
3✔
19
    public name = "atlas-list-clusters";
84✔
20
    protected description = "List MongoDB Atlas clusters";
84✔
21
    public operationType: OperationType = "read";
84✔
22
    protected argsShape = {
84✔
23
        ...ListClustersArgs,
84✔
24
    };
84✔
25

26
    protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
3✔
27
        if (!projectId) {
1!
28
            const data = await this.session.apiClient.listClustersForAllProjects();
×
29

30
            return this.formatAllClustersTable(data);
×
31
        } else {
1✔
32
            const project = await this.session.apiClient.getProject({
1✔
33
                params: {
1✔
34
                    path: {
1✔
35
                        groupId: projectId,
1✔
36
                    },
1✔
37
                },
1✔
38
            });
1✔
39

40
            if (!project?.id) {
1!
41
                throw new Error(`Project with ID "${projectId}" not found.`);
×
42
            }
×
43

44
            const data = await this.session.apiClient.listClusters({
1✔
45
                params: {
1✔
46
                    path: {
1✔
47
                        groupId: project.id || "",
1!
48
                    },
1✔
49
                },
1✔
50
            });
1✔
51

52
            return this.formatClustersTable(project, data);
1✔
53
        }
1✔
54
    }
1✔
55

56
    private formatAllClustersTable(clusters?: PaginatedOrgGroupView): CallToolResult {
3✔
57
        if (!clusters?.results?.length) {
×
58
            throw new Error("No clusters found.");
×
59
        }
×
60
        const formattedClusters = clusters.results
×
61
            .map((result) => {
×
NEW
62
                return (result.clusters || []).map((cluster) => ({
×
NEW
63
                    projectName: result.groupName,
×
NEW
64
                    projectId: result.groupId,
×
NEW
65
                    clusterName: cluster.name,
×
NEW
66
                }));
×
67
            })
×
68
            .flat();
×
69
        if (!formattedClusters.length) {
×
70
            throw new Error("No clusters found.");
×
71
        }
×
72

73
        return {
×
NEW
74
            content: formatUntrustedData(
×
NEW
75
                `Found ${formattedClusters.length} clusters across all projects`,
×
NEW
76
                JSON.stringify(formattedClusters)
×
NEW
77
            ),
×
78
        };
×
79
    }
×
80

81
    private formatClustersTable(
3✔
82
        project: Group,
1✔
83
        clusters?: PaginatedClusterDescription20240805,
1✔
84
        flexClusters?: PaginatedFlexClusters20241113
1✔
85
    ): CallToolResult {
1✔
86
        // Check if both traditional clusters and flex clusters are absent
87
        if (!clusters?.results?.length && !flexClusters?.results?.length) {
1!
UNCOV
88
            return {
×
89
                content: [{ type: "text", text: "No clusters found." }],
×
90
            };
×
91
        }
×
92
        const formattedClusters = clusters?.results?.map((cluster) => formatCluster(cluster)) || [];
1!
93
        const formattedFlexClusters = flexClusters?.results?.map((cluster) => formatFlexCluster(cluster)) || [];
1!
94
        const allClusters = [...formattedClusters, ...formattedFlexClusters];
1✔
95

96
        return {
1✔
97
            content: formatUntrustedData(
1✔
98
                `Found ${allClusters.length} clusters in project "${project.name}" (${project.id}):`,
1✔
99
                JSON.stringify(allClusters)
1✔
100
            ),
1✔
101
        };
1✔
102
    }
1✔
103
}
3✔
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