Skip to content

Commit fe2e79a

Browse files
committed
Accuracy tests for all operations
1 parent eb2b1dc commit fe2e79a

File tree

2 files changed

+137
-32
lines changed

2 files changed

+137
-32
lines changed

src/tools/atlas/read/listPerformanceAdvisor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class ListPerformanceAdvisorTool extends AtlasToolBase {
2525
clusterName: z.string().describe("Atlas cluster name to list performance advisor recommendations"),
2626
operations: z
2727
.array(z.nativeEnum(PerformanceAdvisorOperation))
28-
.default(Object.values(PerformanceAdvisorOperation))
2928
.describe("Operations to list performance advisor recommendations"),
3029
since: z.date().describe("Date to list slow query logs since").optional(),
3130
namespaces: z.array(z.string()).describe("Namespaces to list slow query logs").optional(),

tests/accuracy/listPerformanceAdvisor.test.ts

Lines changed: 137 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,42 @@ import { PerformanceAdvisorOperation } from "../../src/common/atlas/performanceA
22
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
33
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44

5+
// Shared mock tool implementations
6+
const mockedTools = {
7+
"atlas-list-projects": (): CallToolResult => {
8+
return {
9+
content: [
10+
{
11+
type: "text",
12+
text: "Found 1 project\n\n# | Name | ID\n---|------|----\n1 | mflix | mflix",
13+
},
14+
],
15+
};
16+
},
17+
"atlas-list-clusters": (): CallToolResult => {
18+
return {
19+
content: [
20+
{
21+
type: "text",
22+
text: "Found 1 cluster\n\n# | Name | Type | State\n---|------|------|-----\n1 | mflix-cluster | REPLICASET | IDLE",
23+
},
24+
],
25+
};
26+
},
27+
"atlas-list-performance-advisor": (): CallToolResult => {
28+
return {
29+
content: [
30+
{
31+
type: "text",
32+
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",
33+
},
34+
],
35+
};
36+
},
37+
};
38+
539
describeAccuracyTests([
40+
// Test for Suggested Indexes operation
641
{
742
prompt: "Can you give me index suggestions for the database 'mflix' in the project 'mflix' and cluster 'mflix-cluster'?",
843
expectedToolCalls: [
@@ -25,40 +60,111 @@ describeAccuracyTests([
2560
},
2661
},
2762
],
28-
mockedTools: {
29-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
30-
"atlas-list-performance-advisor": (..._parameters): CallToolResult => {
31-
return {
32-
content: [
33-
{
34-
type: "text",
35-
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",
36-
},
37-
],
38-
};
63+
mockedTools,
64+
},
65+
// Test for Drop Index Suggestions operation
66+
{
67+
prompt: "Show me drop index suggestions for the 'mflix' project and 'mflix-cluster' cluster",
68+
expectedToolCalls: [
69+
{
70+
toolName: "atlas-list-projects",
71+
parameters: {},
3972
},
40-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
41-
"atlas-list-projects": (..._parameters): CallToolResult => {
42-
return {
43-
content: [
44-
{
45-
type: "text",
46-
text: "Found 1 project\n\n# | Name | ID\n---|------|----\n1 | mflix | mflix",
47-
},
48-
],
49-
};
73+
{
74+
toolName: "atlas-list-clusters",
75+
parameters: {
76+
projectId: "mflix",
77+
},
78+
},
79+
{
80+
toolName: "atlas-list-performance-advisor",
81+
parameters: {
82+
projectId: "mflix",
83+
clusterName: "mflix-cluster",
84+
operations: [PerformanceAdvisorOperation.DROP_INDEX_SUGGESTIONS],
85+
},
86+
},
87+
],
88+
mockedTools,
89+
},
90+
// Test for Slow Query Logs operation
91+
{
92+
prompt: "Show me the slow query logs for the 'mflix' project and 'mflix-cluster' cluster?",
93+
expectedToolCalls: [
94+
{
95+
toolName: "atlas-list-projects",
96+
parameters: {},
97+
},
98+
{
99+
toolName: "atlas-list-clusters",
100+
parameters: {
101+
projectId: "mflix",
102+
},
103+
},
104+
{
105+
toolName: "atlas-list-performance-advisor",
106+
parameters: {
107+
projectId: "mflix",
108+
clusterName: "mflix-cluster",
109+
operations: [PerformanceAdvisorOperation.SLOW_QUERY_LOGS],
110+
},
111+
},
112+
],
113+
mockedTools,
114+
},
115+
// Test for Schema Suggestions operation
116+
{
117+
prompt: "Give me schema suggestions for the 'mflix' project and 'mflix-cluster' cluster",
118+
expectedToolCalls: [
119+
{
120+
toolName: "atlas-list-projects",
121+
parameters: {},
50122
},
51-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
52-
"atlas-list-clusters": (..._parameters): CallToolResult => {
53-
return {
54-
content: [
55-
{
56-
type: "text",
57-
text: "Found 1 cluster\n\n# | Name | Type | State\n---|------|------|-----\n1 | mflix-cluster | REPLICASET | IDLE",
58-
},
123+
{
124+
toolName: "atlas-list-clusters",
125+
parameters: {
126+
projectId: "mflix",
127+
},
128+
},
129+
{
130+
toolName: "atlas-list-performance-advisor",
131+
parameters: {
132+
projectId: "mflix",
133+
clusterName: "mflix-cluster",
134+
operations: [PerformanceAdvisorOperation.SCHEMA_SUGGESTIONS],
135+
},
136+
},
137+
],
138+
mockedTools,
139+
},
140+
// Test for all operations
141+
{
142+
prompt: "Show me all performance advisor recommendations for the 'mflix' project and 'mflix-cluster' cluster",
143+
expectedToolCalls: [
144+
{
145+
toolName: "atlas-list-projects",
146+
parameters: {},
147+
},
148+
{
149+
toolName: "atlas-list-clusters",
150+
parameters: {
151+
projectId: "mflix",
152+
},
153+
},
154+
{
155+
toolName: "atlas-list-performance-advisor",
156+
parameters: {
157+
projectId: "mflix",
158+
clusterName: "mflix-cluster",
159+
operations: [
160+
PerformanceAdvisorOperation.SUGGESTED_INDEXES,
161+
PerformanceAdvisorOperation.DROP_INDEX_SUGGESTIONS,
162+
PerformanceAdvisorOperation.SLOW_QUERY_LOGS,
163+
PerformanceAdvisorOperation.SCHEMA_SUGGESTIONS,
59164
],
60-
};
165+
},
61166
},
62-
},
167+
],
168+
mockedTools,
63169
},
64170
]);

0 commit comments

Comments
 (0)