Skip to content

Commit bc16c95

Browse files
chore: add accuracy tests for drop-index tool
1 parent 517538a commit bc16c95

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

tests/accuracy/dropIndex.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2+
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
3+
import { Matcher } from "./sdk/matcher.js";
4+
5+
// We don't want to delete actual indexes
6+
const mockedTools = {
7+
"drop-index": ({ indexName, database, collection }: Record<string, unknown>): CallToolResult => {
8+
return {
9+
content: [
10+
{
11+
text: `Successfully dropped the index with name "${String(indexName)}" from the provided namespace "${String(database)}.${String(collection)}".`,
12+
type: "text",
13+
},
14+
],
15+
};
16+
},
17+
} as const;
18+
19+
describeAccuracyTests([
20+
{
21+
prompt: "Delete the index called year_1 from mflix.movies namespace",
22+
expectedToolCalls: [
23+
{
24+
toolName: "drop-index",
25+
parameters: {
26+
database: "mflix",
27+
collection: "movies",
28+
indexName: "year_1",
29+
},
30+
},
31+
],
32+
mockedTools,
33+
},
34+
{
35+
prompt: "First create a text index on field 'title' in 'mflix.movies' namespace and then drop all the indexes from 'mflix.movies' namespace",
36+
expectedToolCalls: [
37+
{
38+
toolName: "create-index",
39+
parameters: {
40+
database: "mflix",
41+
collection: "movies",
42+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
43+
keys: {
44+
title: "text",
45+
},
46+
},
47+
},
48+
{
49+
toolName: "collection-indexes",
50+
parameters: {
51+
database: "mflix",
52+
collection: "movies",
53+
},
54+
},
55+
{
56+
toolName: "drop-index",
57+
parameters: {
58+
database: "mflix",
59+
collection: "movies",
60+
indexName: Matcher.string(),
61+
},
62+
},
63+
{
64+
toolName: "drop-index",
65+
parameters: {
66+
database: "mflix",
67+
collection: "movies",
68+
indexName: Matcher.string(),
69+
},
70+
},
71+
],
72+
mockedTools,
73+
},
74+
]);

tests/accuracy/sdk/accuracyTestingClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MCP_SERVER_CLI_SCRIPT } from "./constants.js";
77
import type { LLMToolCall } from "./accuracyResultStorage/resultStorage.js";
88
import type { VercelMCPClient, VercelMCPClientTools } from "./agent.js";
99

10-
type ToolResultGeneratorFn = (...parameters: unknown[]) => CallToolResult | Promise<CallToolResult>;
10+
type ToolResultGeneratorFn = (parameters: Record<string, unknown>) => CallToolResult | Promise<CallToolResult>;
1111
export type MockedTools = Record<string, ToolResultGeneratorFn>;
1212

1313
/**
@@ -44,7 +44,7 @@ export class AccuracyTestingClient {
4444
try {
4545
const toolResultGeneratorFn = this.mockedTools[toolName];
4646
if (toolResultGeneratorFn) {
47-
return await toolResultGeneratorFn(args);
47+
return await toolResultGeneratorFn(args as Record<string, unknown>);
4848
}
4949

5050
return await tool.execute(args, options);

0 commit comments

Comments
 (0)