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

mongodb-js / mongodb-mcp-server / 18714130420

22 Oct 2025 11:06AM UTC coverage: 80.129% (-1.8%) from 81.905%
18714130420

Pull #674

github

web-flow
Merge ec48e82c7 into 17b595b2f
Pull Request #674: chore: move perf advisor to long running tests - MCP-269

1317 of 1776 branches covered (74.16%)

Branch coverage included in aggregate %.

6018 of 7378 relevant lines covered (81.57%)

73.88 hits per line

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

50.44
/src/common/atlas/cluster.ts
1
import type { ClusterDescription20240805, FlexClusterDescription20241113 } from "./openapi.js";
2
import type { ApiClient } from "./apiClient.js";
3
import { LogId } from "../logger.js";
3✔
4
import { ConnectionString } from "mongodb-connection-string-url";
3✔
5

6
type AtlasProcessId = `${string}:${number}`;
7

8
function extractProcessIds(connectionString: string): Array<AtlasProcessId> {
4✔
9
    if (!connectionString) {
4✔
10
        return [];
2✔
11
    }
2✔
12
    const connectionStringUrl = new ConnectionString(connectionString);
2✔
13
    return connectionStringUrl.hosts as Array<AtlasProcessId>;
2✔
14
}
2✔
15
export interface Cluster {
16
    name?: string;
17
    instanceType: "FREE" | "DEDICATED" | "FLEX";
18
    instanceSize?: string;
19
    state?: "IDLE" | "CREATING" | "UPDATING" | "DELETING" | "REPAIRING";
20
    mongoDBVersion?: string;
21
    connectionString?: string;
22
    processIds?: Array<string>;
23
}
24

25
export function formatFlexCluster(cluster: FlexClusterDescription20241113): Cluster {
3✔
26
    const connectionString = cluster.connectionStrings?.standardSrv || cluster.connectionStrings?.standard;
×
27
    return {
×
28
        name: cluster.name,
×
29
        instanceType: "FLEX",
×
30
        instanceSize: undefined,
×
31
        state: cluster.stateName,
×
32
        mongoDBVersion: cluster.mongoDBVersion,
×
33
        connectionString,
×
34
        processIds: extractProcessIds(cluster.connectionStrings?.standard ?? ""),
×
35
    };
×
36
}
×
37

38
export function formatCluster(cluster: ClusterDescription20240805): Cluster {
3✔
39
    const regionConfigs = (cluster.replicationSpecs || [])
4!
40
        .map(
4✔
41
            (replicationSpec) =>
4✔
42
                (replicationSpec.regionConfigs || []) as {
4!
43
                    providerName: string;
44
                    electableSpecs?: {
45
                        instanceSize: string;
46
                    };
47
                    readOnlySpecs?: {
48
                        instanceSize: string;
49
                    };
50
                    analyticsSpecs?: {
51
                        instanceSize: string;
52
                    };
53
                }[]
54
        )
4✔
55
        .flat()
4✔
56
        .map((regionConfig) => {
4✔
57
            return {
4✔
58
                providerName: regionConfig.providerName,
4✔
59
                instanceSize:
4✔
60
                    regionConfig.electableSpecs?.instanceSize ||
4!
61
                    regionConfig.readOnlySpecs?.instanceSize ||
×
62
                    regionConfig.analyticsSpecs?.instanceSize,
×
63
            };
4✔
64
        });
4✔
65

66
    const instanceSize = regionConfigs[0]?.instanceSize ?? "UNKNOWN";
4!
67
    const clusterInstanceType = instanceSize === "M0" ? "FREE" : "DEDICATED";
4!
68
    const connectionString = cluster.connectionStrings?.standardSrv || cluster.connectionStrings?.standard;
4!
69

70
    return {
4✔
71
        name: cluster.name,
4✔
72
        instanceType: clusterInstanceType,
4✔
73
        instanceSize: clusterInstanceType === "DEDICATED" ? instanceSize : undefined,
4!
74
        state: cluster.stateName,
4✔
75
        mongoDBVersion: cluster.mongoDBVersion,
4✔
76
        connectionString,
4✔
77
        processIds: extractProcessIds(cluster.connectionStrings?.standard ?? ""),
4✔
78
    };
4✔
79
}
4✔
80

81
export async function inspectCluster(apiClient: ApiClient, projectId: string, clusterName: string): Promise<Cluster> {
3✔
82
    try {
3✔
83
        const cluster = await apiClient.getCluster({
3✔
84
            params: {
3✔
85
                path: {
3✔
86
                    groupId: projectId,
3✔
87
                    clusterName,
3✔
88
                },
3✔
89
            },
3✔
90
        });
3✔
91
        return formatCluster(cluster);
3✔
92
    } catch (error) {
3!
93
        try {
×
94
            const cluster = await apiClient.getFlexCluster({
×
95
                params: {
×
96
                    path: {
×
97
                        groupId: projectId,
×
98
                        name: clusterName,
×
99
                    },
×
100
                },
×
101
            });
×
102
            return formatFlexCluster(cluster);
×
103
        } catch (flexError) {
×
104
            const err = flexError instanceof Error ? flexError : new Error(String(flexError));
×
105
            apiClient.logger.error({
×
106
                id: LogId.atlasInspectFailure,
×
107
                context: "inspect-cluster",
×
108
                message: `error inspecting cluster: ${err.message}`,
×
109
            });
×
110
            throw error;
×
111
        }
×
112
    }
×
113
}
3✔
114

115
export async function getProcessIdsFromCluster(
×
116
    apiClient: ApiClient,
×
117
    projectId: string,
×
118
    clusterName: string
×
119
): Promise<Array<string>> {
×
120
    try {
×
121
        const cluster = await inspectCluster(apiClient, projectId, clusterName);
×
122
        return cluster.processIds || [];
×
123
    } catch (error) {
×
124
        throw new Error(
×
125
            `Failed to get processIds from cluster: ${error instanceof Error ? error.message : String(error)}`
×
126
        );
×
127
    }
×
128
}
×
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