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

mongodb-js / mongodb-mcp-server / 18717167438

22 Oct 2025 01:06PM UTC coverage: 79.906% (-2.0%) from 81.905%
18717167438

push

github

web-flow
chore: When querying with vectorSearch use the generated embeddings MCP-245 (#662)

1341 of 1809 branches covered (74.13%)

Branch coverage included in aggregate %.

128 of 193 new or added lines in 4 files covered. (66.32%)

198 existing lines in 6 files now uncovered.

6143 of 7557 relevant lines covered (81.29%)

73.09 hits per line

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

4.03
/src/common/atlas/performanceAdvisorUtils.ts
1
import { LogId } from "../logger.js";
3✔
2
import type { ApiClient } from "./apiClient.js";
3
import { getProcessIdsFromCluster } from "./cluster.js";
3✔
4
import type { components } from "./openapi.js";
5

6
export type SuggestedIndex = components["schemas"]["PerformanceAdvisorIndex"];
7
export type DropIndexSuggestion = components["schemas"]["DropIndexSuggestionsIndex"];
8
export type SlowQueryLog = components["schemas"]["PerformanceAdvisorSlowQuery"];
9

10
export const DEFAULT_SLOW_QUERY_LOGS_LIMIT = 50;
3✔
11

12
export const SUGGESTED_INDEXES_COPY = `Note: The "Weight" field is measured in bytes, and represents the estimated number of bytes saved in disk reads per executed read query that would be saved by implementing an index suggestion. Please convert this to MB or GB for easier readability.`;
3✔
13
export const SLOW_QUERY_LOGS_COPY = `Please notify the user that the MCP server tool limits slow query logs to the most recent ${DEFAULT_SLOW_QUERY_LOGS_LIMIT} slow query logs. This is a limitation of the MCP server tool only. More slow query logs and performance suggestions can be seen in the Atlas UI. Please give to the user the following docs about the performance advisor: https://www.mongodb.com/docs/atlas/performance-advisor/.`;
3✔
14

15
interface SuggestedIndexesResponse {
16
    content: components["schemas"]["PerformanceAdvisorResponse"];
17
}
18
interface DropIndexesResponse {
19
    content: components["schemas"]["DropIndexSuggestionsResponse"];
20
}
21
interface SchemaAdviceResponse {
22
    content: components["schemas"]["SchemaAdvisorResponse"];
23
}
24
export type SchemaRecommendation = components["schemas"]["SchemaAdvisorItemRecommendation"];
25

UNCOV
26
export async function getSuggestedIndexes(
×
UNCOV
27
    apiClient: ApiClient,
×
UNCOV
28
    projectId: string,
×
UNCOV
29
    clusterName: string
×
UNCOV
30
): Promise<{ suggestedIndexes: Array<SuggestedIndex> }> {
×
UNCOV
31
    try {
×
UNCOV
32
        const response = await apiClient.listClusterSuggestedIndexes({
×
UNCOV
33
            params: {
×
UNCOV
34
                path: {
×
UNCOV
35
                    groupId: projectId,
×
UNCOV
36
                    clusterName,
×
UNCOV
37
                },
×
UNCOV
38
            },
×
UNCOV
39
        });
×
UNCOV
40
        return {
×
UNCOV
41
            suggestedIndexes: (response as SuggestedIndexesResponse).content.suggestedIndexes ?? [],
×
UNCOV
42
        };
×
UNCOV
43
    } catch (err) {
×
44
        apiClient.logger.debug({
×
45
            id: LogId.atlasPaSuggestedIndexesFailure,
×
46
            context: "performanceAdvisorUtils",
×
47
            message: `Failed to list suggested indexes: ${err instanceof Error ? err.message : String(err)}`,
×
48
        });
×
49
        throw new Error(`Failed to list suggested indexes: ${err instanceof Error ? err.message : String(err)}`);
×
50
    }
×
UNCOV
51
}
×
52

UNCOV
53
export async function getDropIndexSuggestions(
×
UNCOV
54
    apiClient: ApiClient,
×
UNCOV
55
    projectId: string,
×
UNCOV
56
    clusterName: string
×
57
): Promise<{
58
    hiddenIndexes: Array<DropIndexSuggestion>;
59
    redundantIndexes: Array<DropIndexSuggestion>;
60
    unusedIndexes: Array<DropIndexSuggestion>;
UNCOV
61
}> {
×
UNCOV
62
    try {
×
UNCOV
63
        const response = await apiClient.listDropIndexes({
×
UNCOV
64
            params: {
×
UNCOV
65
                path: {
×
UNCOV
66
                    groupId: projectId,
×
UNCOV
67
                    clusterName,
×
UNCOV
68
                },
×
UNCOV
69
            },
×
UNCOV
70
        });
×
UNCOV
71
        return {
×
UNCOV
72
            hiddenIndexes: (response as DropIndexesResponse).content.hiddenIndexes ?? [],
×
UNCOV
73
            redundantIndexes: (response as DropIndexesResponse).content.redundantIndexes ?? [],
×
UNCOV
74
            unusedIndexes: (response as DropIndexesResponse).content.unusedIndexes ?? [],
×
UNCOV
75
        };
×
UNCOV
76
    } catch (err) {
×
77
        apiClient.logger.debug({
×
78
            id: LogId.atlasPaDropIndexSuggestionsFailure,
×
79
            context: "performanceAdvisorUtils",
×
80
            message: `Failed to list drop index suggestions: ${err instanceof Error ? err.message : String(err)}`,
×
81
        });
×
82
        throw new Error(`Failed to list drop index suggestions: ${err instanceof Error ? err.message : String(err)}`);
×
83
    }
×
UNCOV
84
}
×
85

UNCOV
86
export async function getSchemaAdvice(
×
UNCOV
87
    apiClient: ApiClient,
×
UNCOV
88
    projectId: string,
×
UNCOV
89
    clusterName: string
×
UNCOV
90
): Promise<{ recommendations: Array<SchemaRecommendation> }> {
×
UNCOV
91
    try {
×
UNCOV
92
        const response = await apiClient.listSchemaAdvice({
×
UNCOV
93
            params: {
×
UNCOV
94
                path: {
×
UNCOV
95
                    groupId: projectId,
×
UNCOV
96
                    clusterName,
×
UNCOV
97
                },
×
UNCOV
98
            },
×
UNCOV
99
        });
×
UNCOV
100
        return { recommendations: (response as SchemaAdviceResponse).content.recommendations ?? [] };
×
UNCOV
101
    } catch (err) {
×
102
        apiClient.logger.debug({
×
103
            id: LogId.atlasPaSchemaAdviceFailure,
×
104
            context: "performanceAdvisorUtils",
×
105
            message: `Failed to list schema advice: ${err instanceof Error ? err.message : String(err)}`,
×
106
        });
×
107
        throw new Error(`Failed to list schema advice: ${err instanceof Error ? err.message : String(err)}`);
×
108
    }
×
UNCOV
109
}
×
110

UNCOV
111
export async function getSlowQueries(
×
UNCOV
112
    apiClient: ApiClient,
×
UNCOV
113
    projectId: string,
×
UNCOV
114
    clusterName: string,
×
UNCOV
115
    since?: Date,
×
UNCOV
116
    namespaces?: Array<string>
×
UNCOV
117
): Promise<{ slowQueryLogs: Array<SlowQueryLog> }> {
×
UNCOV
118
    try {
×
UNCOV
119
        const processIds = await getProcessIdsFromCluster(apiClient, projectId, clusterName);
×
120

UNCOV
121
        if (processIds.length === 0) {
×
122
            return { slowQueryLogs: [] };
×
123
        }
×
124

UNCOV
125
        const slowQueryPromises = processIds.map((processId) =>
×
UNCOV
126
            apiClient.listSlowQueries({
×
UNCOV
127
                params: {
×
UNCOV
128
                    path: {
×
UNCOV
129
                        groupId: projectId,
×
UNCOV
130
                        processId,
×
UNCOV
131
                    },
×
UNCOV
132
                    query: {
×
UNCOV
133
                        ...(since && { since: since.getTime() }),
×
UNCOV
134
                        ...(namespaces && { namespaces: namespaces }),
×
UNCOV
135
                        nLogs: DEFAULT_SLOW_QUERY_LOGS_LIMIT,
×
UNCOV
136
                    },
×
UNCOV
137
                },
×
UNCOV
138
            })
×
UNCOV
139
        );
×
140

UNCOV
141
        const responses = await Promise.allSettled(slowQueryPromises);
×
142

UNCOV
143
        const allSlowQueryLogs = responses.reduce((acc, response) => {
×
UNCOV
144
            return acc.concat(response.status === "fulfilled" ? (response.value.slowQueries ?? []) : []);
×
UNCOV
145
        }, [] as Array<SlowQueryLog>);
×
146

UNCOV
147
        return { slowQueryLogs: allSlowQueryLogs };
×
UNCOV
148
    } catch (err) {
×
149
        apiClient.logger.debug({
×
150
            id: LogId.atlasPaSlowQueryLogsFailure,
×
151
            context: "performanceAdvisorUtils",
×
152
            message: `Failed to list slow query logs: ${err instanceof Error ? err.message : String(err)}`,
×
153
        });
×
154
        throw new Error(`Failed to list slow query logs: ${err instanceof Error ? err.message : String(err)}`);
×
155
    }
×
UNCOV
156
}
×
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

© 2026 Coveralls, Inc