From 89ccbcd2aab05aa6dafafbbc669b6652e57986d2 Mon Sep 17 00:00:00 2001 From: Kyle W Lai Date: Mon, 13 Oct 2025 18:16:10 -0400 Subject: [PATCH 1/2] Convey the sample of slow queries to the LLM --- src/tools/atlas/read/getPerformanceAdvisor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/atlas/read/getPerformanceAdvisor.ts b/src/tools/atlas/read/getPerformanceAdvisor.ts index 120c765af..b930e217f 100644 --- a/src/tools/atlas/read/getPerformanceAdvisor.ts +++ b/src/tools/atlas/read/getPerformanceAdvisor.ts @@ -102,7 +102,7 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase { : "No suggested indexes found." }`, `## Drop Index Suggestions\n${hasDropIndexSuggestions ? JSON.stringify(dropIndexSuggestionsResult.value) : "No drop index suggestions found."}`, - `## Slow Query Logs\n${hasSlowQueryLogs ? JSON.stringify(slowQueryLogsResult.value?.slowQueryLogs) : "No slow query logs found."}`, + `## Slow Query Logs\n${hasSlowQueryLogs ? `Please notify the user that the slow query logs are limited to the most recent ${DEFAULT_SLOW_QUERY_LOGS_LIMIT} slow query logs. This is a limitation of the MCP server tool only.\n${JSON.stringify(slowQueryLogsResult.value?.slowQueryLogs)}` : "No slow query logs found."}`, `## Schema Suggestions\n${hasSchemaSuggestions ? JSON.stringify(schemaSuggestionsResult.value?.recommendations) : "No schema suggestions found."}`, ]; From e716cae1e974c786aea9e756a64d21834b1d440f Mon Sep 17 00:00:00 2001 From: Kyle W Lai Date: Tue, 14 Oct 2025 12:20:01 -0400 Subject: [PATCH 2/2] Tweak copy for slow queries --- src/common/atlas/performanceAdvisorUtils.ts | 3 +++ src/tools/atlas/read/getPerformanceAdvisor.ts | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/atlas/performanceAdvisorUtils.ts b/src/common/atlas/performanceAdvisorUtils.ts index 11549039c..61a79d188 100644 --- a/src/common/atlas/performanceAdvisorUtils.ts +++ b/src/common/atlas/performanceAdvisorUtils.ts @@ -9,6 +9,9 @@ export type SlowQueryLog = components["schemas"]["PerformanceAdvisorSlowQuery"]; export const DEFAULT_SLOW_QUERY_LOGS_LIMIT = 50; +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.`; +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/.`; + interface SuggestedIndexesResponse { content: components["schemas"]["PerformanceAdvisorResponse"]; } diff --git a/src/tools/atlas/read/getPerformanceAdvisor.ts b/src/tools/atlas/read/getPerformanceAdvisor.ts index b930e217f..fa7ec5194 100644 --- a/src/tools/atlas/read/getPerformanceAdvisor.ts +++ b/src/tools/atlas/read/getPerformanceAdvisor.ts @@ -9,6 +9,8 @@ import { getSchemaAdvice, getSlowQueries, DEFAULT_SLOW_QUERY_LOGS_LIMIT, + SUGGESTED_INDEXES_COPY, + SLOW_QUERY_LOGS_COPY, } from "../../../common/atlas/performanceAdvisorUtils.js"; import { AtlasArgs } from "../../args.js"; @@ -98,11 +100,11 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase { const performanceAdvisorData = [ `## Suggested Indexes\n${ hasSuggestedIndexes - ? `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.\n${JSON.stringify(suggestedIndexesResult.value?.suggestedIndexes)}` + ? `${SUGGESTED_INDEXES_COPY}\n${JSON.stringify(suggestedIndexesResult.value?.suggestedIndexes)}` : "No suggested indexes found." }`, `## Drop Index Suggestions\n${hasDropIndexSuggestions ? JSON.stringify(dropIndexSuggestionsResult.value) : "No drop index suggestions found."}`, - `## Slow Query Logs\n${hasSlowQueryLogs ? `Please notify the user that the slow query logs are limited to the most recent ${DEFAULT_SLOW_QUERY_LOGS_LIMIT} slow query logs. This is a limitation of the MCP server tool only.\n${JSON.stringify(slowQueryLogsResult.value?.slowQueryLogs)}` : "No slow query logs found."}`, + `## Slow Query Logs\n${hasSlowQueryLogs ? `${SLOW_QUERY_LOGS_COPY}\n${JSON.stringify(slowQueryLogsResult.value?.slowQueryLogs)}` : "No slow query logs found."}`, `## Schema Suggestions\n${hasSchemaSuggestions ? JSON.stringify(schemaSuggestionsResult.value?.recommendations) : "No schema suggestions found."}`, ];