Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bd69450
Add base atlas performance advisor MCP server tool
kylelai1 Sep 4, 2025
f331bac
Cleanup comments
kylelai1 Sep 4, 2025
78f9888
Merge main
kylelai1 Sep 4, 2025
2f023eb
Fix API return type
kylelai1 Sep 5, 2025
a4cbc8b
Clean up getting slow query logs from atlas admin api
kylelai1 Sep 8, 2025
2ef0ded
Fix types for performance advisor api response
kylelai1 Sep 8, 2025
923263e
Address comments
kylelai1 Sep 13, 2025
8272719
Move utils to util file
kylelai1 Sep 13, 2025
5871dc0
Cleanup naming
kylelai1 Sep 13, 2025
d2c2ee6
Draft
kylelai1 Sep 16, 2025
ce0466b
Remove processId arg
kylelai1 Sep 16, 2025
eb2b1dc
Merge branch 'atlas-list-performance-advisor-base-tool' into atlas-li…
kylelai1 Sep 16, 2025
fe2e79a
Accuracy tests for all operations
kylelai1 Sep 16, 2025
f0b24bb
Address comments
kylelai1 Sep 17, 2025
3217e95
Typing
kylelai1 Sep 18, 2025
817b961
Merge base tool branch
kylelai1 Sep 18, 2025
ea41c0c
Add args to slow query test
kylelai1 Sep 18, 2025
016af0e
Clean up PA retrieval code
kylelai1 Sep 18, 2025
a2fbe34
Merge branch 'main' into atlas-list-performance-advisor-base-tool
kylelai1 Sep 19, 2025
4645d07
Clean up nits
kylelai1 Sep 19, 2025
372adbb
Merge branch 'atlas-list-performance-advisor-base-tool' into atlas-li…
kylelai1 Sep 19, 2025
68c5d14
Merge branch 'atlas-list-performance-advisor-tool' into atlas-list-pe…
kylelai1 Sep 19, 2025
6d4c54f
Merge tool feature branch
kylelai1 Sep 19, 2025
80bc769
More concise logic for adding api id/secret
kylelai1 Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/accuracy/runAccuracyTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export MDB_ACCURACY_RUN_ID=$(npx uuid v4)
# export MDB_AZURE_OPEN_AI_API_KEY=""
# export MDB_AZURE_OPEN_AI_API_URL=""

# For providing Atlas API credentials (required for Atlas tools)
# Set dummy values for testing (allows Atlas tools to be registered for mocking)
export MDB_MCP_API_CLIENT_ID=${MDB_MCP_API_CLIENT_ID:-"test-atlas-client-id"}
export MDB_MCP_API_CLIENT_SECRET=${MDB_MCP_API_CLIENT_SECRET:-"test-atlas-client-secret"}

# For providing a mongodb based storage to store accuracy result
# export MDB_ACCURACY_MDB_URL=""
# export MDB_ACCURACY_MDB_DB=""
Expand Down
165 changes: 165 additions & 0 deletions tests/accuracy/listPerformanceAdvisor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";

// Shared mock tool implementations
const mockedTools = {
"atlas-list-projects": (): CallToolResult => {
return {
content: [
{
type: "text",
text: "Found 1 project\n\n# | Name | ID\n---|------|----\n1 | mflix | mflix",
},
],
};
},
"atlas-list-clusters": (): CallToolResult => {
return {
content: [
{
type: "text",
text: "Found 1 cluster\n\n# | Name | Type | State\n---|------|------|-----\n1 | mflix-cluster | REPLICASET | IDLE",
},
],
};
},
"atlas-list-performance-advisor": (): CallToolResult => {
return {
content: [
{
type: "text",
text: "Found 2 performance advisor recommendations\n\n## Suggested Indexes\n# | Namespace | Weight | Avg Obj Size | Index Keys\n---|-----------|--------|--------------|------------\n1 | mflix.movies | 0.8 | 1024 | title, year\n2 | mflix.shows | 0.6 | 512 | genre, rating",
},
],
};
},
};

describeAccuracyTests([
// Test for Suggested Indexes operation
{
prompt: "Can you give me index suggestions for the database 'mflix' in the project 'mflix' and cluster 'mflix-cluster'?",
expectedToolCalls: [
{
toolName: "atlas-list-projects",
parameters: {},
},
{
toolName: "atlas-list-clusters",
parameters: {
projectId: "mflix",
},
},
{
toolName: "atlas-list-performance-advisor",
parameters: {
projectId: "mflix",
clusterName: "mflix-cluster",
operations: ["suggestedIndexes"],
},
},
],
mockedTools,
},
// Test for Drop Index Suggestions operation
{
prompt: "Show me drop index suggestions for the 'mflix' project and 'mflix-cluster' cluster",
expectedToolCalls: [
{
toolName: "atlas-list-projects",
parameters: {},
},
{
toolName: "atlas-list-clusters",
parameters: {
projectId: "mflix",
},
},
{
toolName: "atlas-list-performance-advisor",
parameters: {
projectId: "mflix",
clusterName: "mflix-cluster",
operations: ["dropIndexSuggestions"],
},
},
],
mockedTools,
},
// Test for Slow Query Logs operation
{
prompt: "Show me the slow query logs for the 'mflix' project and 'mflix-cluster' cluster for the namespaces 'mflix.movies' and 'mflix.shows' since January 1st, 2025.",
expectedToolCalls: [
{
toolName: "atlas-list-projects",
parameters: {},
},
{
toolName: "atlas-list-clusters",
parameters: {
projectId: "mflix",
},
},
{
toolName: "atlas-list-performance-advisor",
parameters: {
projectId: "mflix",
clusterName: "mflix-cluster",
operations: ["slowQueryLogs"],
namespaces: ["mflix.movies", "mflix.shows"],
since: "2025-01-01T00:00:00Z",
},
},
],
mockedTools,
},
// Test for Schema Suggestions operation
{
prompt: "Give me schema suggestions for the 'mflix' project and 'mflix-cluster' cluster",
expectedToolCalls: [
{
toolName: "atlas-list-projects",
parameters: {},
},
{
toolName: "atlas-list-clusters",
parameters: {
projectId: "mflix",
},
},
{
toolName: "atlas-list-performance-advisor",
parameters: {
projectId: "mflix",
clusterName: "mflix-cluster",
operations: ["schemaSuggestions"],
},
},
],
mockedTools,
},
// Test for all operations
{
prompt: "Show me all performance advisor recommendations for the 'mflix' project and 'mflix-cluster' cluster",
expectedToolCalls: [
{
toolName: "atlas-list-projects",
parameters: {},
},
{
toolName: "atlas-list-clusters",
parameters: {
projectId: "mflix",
},
},
{
toolName: "atlas-list-performance-advisor",
parameters: {
projectId: "mflix",
clusterName: "mflix-cluster",
},
},
],
mockedTools,
},
]);
16 changes: 14 additions & 2 deletions tests/accuracy/sdk/accuracyTestingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@ export class AccuracyTestingClient {
this.llmToolCalls = [];
}

static async initializeClient(mdbConnectionString: string): Promise<AccuracyTestingClient> {
static async initializeClient(
mdbConnectionString: string,
atlasApiClientId?: string,
atlasApiClientSecret?: string
): Promise<AccuracyTestingClient> {
const args = [
MCP_SERVER_CLI_SCRIPT,
"--connectionString",
mdbConnectionString,
...(atlasApiClientId ? ["--apiClientId", atlasApiClientId] : []),
...(atlasApiClientSecret ? ["--apiClientSecret", atlasApiClientSecret] : []),
];

const clientTransport = new StdioClientTransport({
command: process.execPath,
args: [MCP_SERVER_CLI_SCRIPT, "--connectionString", mdbConnectionString],
args,
});

const client = await createMCPClient({
Expand Down
9 changes: 8 additions & 1 deletion tests/accuracy/sdk/describeAccuracyTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export function describeAccuracyTests(accuracyTestConfigs: AccuracyTestConfig[])
const mdbIntegration = setupMongoDBIntegrationTest({}, []);
const { populateTestData, cleanupTestDatabases } = prepareTestData(mdbIntegration);

const atlasApiClientId = process.env.MDB_MCP_API_CLIENT_ID;
const atlasApiClientSecret = process.env.MDB_MCP_API_CLIENT_SECRET;

let commitSHA: string;
let accuracyResultStorage: AccuracyResultStorage;
let testMCPClient: AccuracyTestingClient;
Expand All @@ -79,7 +82,11 @@ export function describeAccuracyTests(accuracyTestConfigs: AccuracyTestConfig[])
commitSHA = retrievedCommitSHA;

accuracyResultStorage = getAccuracyResultStorage();
testMCPClient = await AccuracyTestingClient.initializeClient(mdbIntegration.connectionString());
testMCPClient = await AccuracyTestingClient.initializeClient(
mdbIntegration.connectionString(),
atlasApiClientId,
atlasApiClientSecret
);
agent = getVercelToolCallingAgent();
});

Expand Down
Loading