|
1 | 1 | import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; |
2 | 2 | import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js"; |
3 | 3 | import { Matcher } from "./sdk/matcher.js"; |
| 4 | +import { formatUntrustedData } from "../../src/tools/tool.js"; |
4 | 5 |
|
5 | 6 | // We don't want to delete actual indexes |
6 | 7 | const mockedTools = { |
7 | 8 | "drop-index": ({ indexName, database, collection }: Record<string, unknown>): CallToolResult => { |
8 | 9 | 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 | | - ], |
| 10 | + content: formatUntrustedData( |
| 11 | + "Successfully dropped the index from the provided namespace.", |
| 12 | + JSON.stringify({ |
| 13 | + indexName, |
| 14 | + namespace: `${database as string}.${collection as string}`, |
| 15 | + }) |
| 16 | + ), |
15 | 17 | }; |
16 | 18 | }, |
17 | 19 | } as const; |
18 | 20 |
|
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", |
| 21 | +describeAccuracyTests( |
| 22 | + [ |
| 23 | + { |
| 24 | + prompt: "Delete the index called year_1 from mflix.movies namespace", |
| 25 | + expectedToolCalls: [ |
| 26 | + { |
| 27 | + toolName: "drop-index", |
| 28 | + parameters: { |
| 29 | + database: "mflix", |
| 30 | + collection: "movies", |
| 31 | + indexName: "year_1", |
| 32 | + type: "classic", |
| 33 | + }, |
29 | 34 | }, |
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 | | - definition: [ |
44 | | - { |
45 | | - keys: { |
46 | | - title: "text", |
| 35 | + ], |
| 36 | + mockedTools, |
| 37 | + }, |
| 38 | + { |
| 39 | + prompt: "First create a text index on field 'title' in 'mflix.movies' namespace and then drop all the indexes from 'mflix.movies' namespace", |
| 40 | + expectedToolCalls: [ |
| 41 | + { |
| 42 | + toolName: "create-index", |
| 43 | + parameters: { |
| 44 | + database: "mflix", |
| 45 | + collection: "movies", |
| 46 | + name: Matcher.anyOf(Matcher.undefined, Matcher.string()), |
| 47 | + definition: [ |
| 48 | + { |
| 49 | + keys: { |
| 50 | + title: "text", |
| 51 | + }, |
| 52 | + type: "classic", |
47 | 53 | }, |
48 | | - type: "classic", |
49 | | - }, |
50 | | - ], |
| 54 | + ], |
| 55 | + }, |
51 | 56 | }, |
52 | | - }, |
53 | | - { |
54 | | - toolName: "collection-indexes", |
55 | | - parameters: { |
56 | | - database: "mflix", |
57 | | - collection: "movies", |
| 57 | + { |
| 58 | + toolName: "collection-indexes", |
| 59 | + parameters: { |
| 60 | + database: "mflix", |
| 61 | + collection: "movies", |
| 62 | + }, |
58 | 63 | }, |
59 | | - }, |
60 | | - { |
61 | | - toolName: "drop-index", |
62 | | - parameters: { |
63 | | - database: "mflix", |
64 | | - collection: "movies", |
65 | | - indexName: Matcher.string(), |
| 64 | + { |
| 65 | + toolName: "drop-index", |
| 66 | + parameters: { |
| 67 | + database: "mflix", |
| 68 | + collection: "movies", |
| 69 | + indexName: Matcher.string(), |
| 70 | + type: "classic", |
| 71 | + }, |
66 | 72 | }, |
67 | | - }, |
68 | | - { |
69 | | - toolName: "drop-index", |
70 | | - parameters: { |
71 | | - database: "mflix", |
72 | | - collection: "movies", |
73 | | - indexName: Matcher.string(), |
| 73 | + { |
| 74 | + toolName: "drop-index", |
| 75 | + parameters: { |
| 76 | + database: "mflix", |
| 77 | + collection: "movies", |
| 78 | + indexName: Matcher.string(), |
| 79 | + type: "classic", |
| 80 | + }, |
74 | 81 | }, |
75 | | - }, |
76 | | - ], |
77 | | - mockedTools, |
78 | | - }, |
79 | | -]); |
| 82 | + ], |
| 83 | + mockedTools, |
| 84 | + }, |
| 85 | + { |
| 86 | + prompt: "Create a vector search index on 'mflix.movies' namespace on the 'plotSummary' field. The index should use 1024 dimensions. Confirm that its created and then drop the index.", |
| 87 | + expectedToolCalls: [ |
| 88 | + { |
| 89 | + toolName: "create-index", |
| 90 | + parameters: { |
| 91 | + database: "mflix", |
| 92 | + collection: "movies", |
| 93 | + name: Matcher.anyOf(Matcher.undefined, Matcher.string()), |
| 94 | + definition: [ |
| 95 | + { |
| 96 | + type: "vectorSearch", |
| 97 | + fields: [ |
| 98 | + { |
| 99 | + type: "vector", |
| 100 | + path: "plotSummary", |
| 101 | + numDimensions: 1024, |
| 102 | + }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + ], |
| 106 | + }, |
| 107 | + }, |
| 108 | + { |
| 109 | + toolName: "collection-indexes", |
| 110 | + parameters: { |
| 111 | + database: "mflix", |
| 112 | + collection: "movies", |
| 113 | + }, |
| 114 | + }, |
| 115 | + { |
| 116 | + toolName: "drop-index", |
| 117 | + parameters: { |
| 118 | + database: "mflix", |
| 119 | + collection: "movies", |
| 120 | + indexName: Matcher.string(), |
| 121 | + type: "search", |
| 122 | + }, |
| 123 | + }, |
| 124 | + ], |
| 125 | + mockedTools, |
| 126 | + }, |
| 127 | + ], |
| 128 | + { |
| 129 | + userConfig: { |
| 130 | + voyageApiKey: "voyage-api-key", |
| 131 | + }, |
| 132 | + clusterConfig: { search: true }, |
| 133 | + } |
| 134 | +); |
0 commit comments