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

mongodb-js / mongodb-mcp-server / 15063490200

16 May 2025 07:51AM UTC coverage: 73.774%. First build
15063490200

Pull #258

github

web-flow
Merge 047c85483 into 298adf4a5
Pull Request #258: feat: listSearchIndexes now lists index status info

209 of 368 branches covered (56.79%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

829 of 1039 relevant lines covered (79.79%)

54.59 hits per line

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

48.65
/src/common/atlas/cluster.ts
1
import { ClusterDescription20240805, FlexClusterDescription20241113 } from "./openapi.js";
2
import { ApiClient } from "./apiClient.js";
3
import logger, { LogId } from "../../logger.js";
4

5
export interface Cluster {
6
    name?: string;
7
    instanceType: "FREE" | "DEDICATED" | "FLEX";
8
    instanceSize?: string;
9
    state?: "IDLE" | "CREATING" | "UPDATING" | "DELETING" | "REPAIRING";
10
    mongoDBVersion?: string;
11
    connectionString?: string;
12
}
13

14
export function formatFlexCluster(cluster: FlexClusterDescription20241113): Cluster {
15
    return {
×
16
        name: cluster.name,
17
        instanceType: "FLEX",
18
        instanceSize: undefined,
19
        state: cluster.stateName,
20
        mongoDBVersion: cluster.mongoDBVersion,
21
        connectionString: cluster.connectionStrings?.standardSrv || cluster.connectionStrings?.standard,
×
22
    };
23
}
24

25
export function formatCluster(cluster: ClusterDescription20240805): Cluster {
26
    const regionConfigs = (cluster.replicationSpecs || [])
3!
27
        .map(
28
            (replicationSpec) =>
29
                (replicationSpec.regionConfigs || []) as {
3!
30
                    providerName: string;
31
                    electableSpecs?: {
32
                        instanceSize: string;
33
                    };
34
                    readOnlySpecs?: {
35
                        instanceSize: string;
36
                    };
37
                    analyticsSpecs?: {
38
                        instanceSize: string;
39
                    };
40
                }[]
41
        )
42
        .flat()
43
        .map((regionConfig) => {
44
            return {
3✔
45
                providerName: regionConfig.providerName,
46
                instanceSize:
47
                    regionConfig.electableSpecs?.instanceSize ||
3!
48
                    regionConfig.readOnlySpecs?.instanceSize ||
49
                    regionConfig.analyticsSpecs?.instanceSize,
50
            };
51
        });
52

53
    const instanceSize = (regionConfigs.length <= 0 ? undefined : regionConfigs[0].instanceSize) || "UNKNOWN";
3!
54

55
    const clusterInstanceType = instanceSize == "M0" ? "FREE" : "DEDICATED";
3!
56

57
    return {
3✔
58
        name: cluster.name,
59
        instanceType: clusterInstanceType,
60
        instanceSize: clusterInstanceType == "DEDICATED" ? instanceSize : undefined,
3!
61
        state: cluster.stateName,
62
        mongoDBVersion: cluster.mongoDBVersion,
63
        connectionString: cluster.connectionStrings?.standardSrv || cluster.connectionStrings?.standard,
5✔
64
    };
65
}
66

67
export async function inspectCluster(apiClient: ApiClient, projectId: string, clusterName: string): Promise<Cluster> {
68
    try {
2✔
69
        const cluster = await apiClient.getCluster({
2✔
70
            params: {
71
                path: {
72
                    groupId: projectId,
73
                    clusterName,
74
                },
75
            },
76
        });
77
        return formatCluster(cluster);
2✔
78
    } catch (error) {
79
        try {
×
80
            const cluster = await apiClient.getFlexCluster({
×
81
                params: {
82
                    path: {
83
                        groupId: projectId,
84
                        name: clusterName,
85
                    },
86
                },
87
            });
88
            return formatFlexCluster(cluster);
×
89
        } catch (flexError) {
90
            const err = flexError instanceof Error ? flexError : new Error(String(flexError));
×
91
            logger.error(LogId.atlasInspectFailure, "inspect-cluster", `error inspecting cluster: ${err.message}`);
×
92
            throw error;
×
93
        }
94
    }
95
}
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