Skip to content

Commit 49ac3d8

Browse files
committed
add definitions
1 parent 49a75e8 commit 49ac3d8

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/tools/mongodb/mongodbTool.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from "zod";
2-
import { ToolArgs, ToolBase, ToolCategory, TelemetryToolMetadata } from "../tool.js";
2+
import { TelemetryToolMetadata, ToolArgs, ToolBase, ToolCategory } from "../tool.js";
33
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
44
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
55
import { ErrorCodes, MongoDBError } from "../../errors.js";
@@ -10,6 +10,61 @@ export const DbOperationArgs = {
1010
collection: z.string().describe("Collection name"),
1111
};
1212

13+
export const SearchIndexArgs = {
14+
name: z.string().describe("The name of the index"),
15+
type: z.enum(["search", "vectorSearch"]).optional().default("search").describe("The type of the index"),
16+
analyzer: z
17+
.string()
18+
.optional()
19+
.default("lucene.standard")
20+
.describe(
21+
"The analyzer to use for the index. Can be one of the built-in lucene analyzers (`lucene.standard`, `lucene.simple`, `lucene.whitespace`, `lucene.keyword`), a language-specific analyzer, such as `lucene.cjk` or `lucene.czech`, or a custom analyzer defined in the Atlas UI."
22+
),
23+
mappings: z
24+
.object({
25+
dynamic: z
26+
.boolean()
27+
.optional()
28+
.default(false)
29+
.describe(
30+
"Enables or disables dynamic mapping of fields for this index. If set to true, Atlas Search recursively indexes all dynamically indexable fields. If set to false, you must specify individual fields to index using mappings.fields."
31+
),
32+
fields: z
33+
.record(
34+
z.string().describe("The field name"),
35+
z
36+
.object({
37+
type: z
38+
.enum([
39+
"autocomplete",
40+
"boolean",
41+
"date",
42+
"document",
43+
"embeddedDocuments",
44+
"geo",
45+
"knnVector",
46+
"number",
47+
"objectId",
48+
"string",
49+
"token",
50+
"uuid",
51+
])
52+
.describe("The field type"),
53+
})
54+
.passthrough()
55+
56+
.describe(
57+
"The field index definition. It must contain the field type, as well as any additional options for that field type."
58+
)
59+
)
60+
.optional()
61+
.describe("The field mapping definitions. If `dynamic` is set to false, this is required."),
62+
})
63+
.describe(
64+
"Document describing the index to create. The definition syntax depends on whether you create a standard search index or a Vector Search index."
65+
),
66+
};
67+
1368
export abstract class MongoDBToolBase extends ToolBase {
1469
protected category: ToolCategory = "mongodb";
1570

src/tools/mongodb/tools.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { DropCollectionTool } from "./delete/dropCollection.js";
1818
import { ExplainTool } from "./metadata/explain.js";
1919
import { CreateCollectionTool } from "./create/createCollection.js";
2020
import { LogsTool } from "./metadata/logs.js";
21+
import { CreateSearchIndexTool } from "./create/createSearchIndex.js";
22+
import { UpdateSearchIndexTool } from "./update/updateSearchIndex.js";
2123

2224
export const MongoDbTools = [
2325
ConnectTool,
@@ -40,4 +42,6 @@ export const MongoDbTools = [
4042
ExplainTool,
4143
CreateCollectionTool,
4244
LogsTool,
45+
CreateSearchIndexTool,
46+
UpdateSearchIndexTool,
4347
];

0 commit comments

Comments
 (0)