From de22ac50e16faa446d69923b48c8c2e19b2d6fec Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Tue, 13 May 2025 13:29:35 -0700 Subject: [PATCH 1/4] Add drop-search-index tool --- src/tools/mongodb/delete/dropSearchIndex.ts | 29 +++++++++++++++++++++ src/tools/mongodb/tools.ts | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 src/tools/mongodb/delete/dropSearchIndex.ts diff --git a/src/tools/mongodb/delete/dropSearchIndex.ts b/src/tools/mongodb/delete/dropSearchIndex.ts new file mode 100644 index 00000000..34d3f28a --- /dev/null +++ b/src/tools/mongodb/delete/dropSearchIndex.ts @@ -0,0 +1,29 @@ +import { z } from "zod"; +import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; +import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js"; +import { ToolArgs, OperationType } from "../../tool.js"; + +export class DropSearchIndexTool extends MongoDBToolBase { + protected name = "drop-search-index"; + protected description = + "Deletes a text or vector search index from the database."; + protected argsShape = { + ...DbOperationArgs, + indexName: z.string().describe("The name of the search or vector index to delete"), + }; + protected operationType: OperationType = "delete"; + + protected async execute({ database, collection, indexName }: ToolArgs): Promise { + const provider = await this.ensureConnected(); + const result = await provider.dropSearchIndex(database, collection, indexName); + + return { + content: [ + { + text: `"Successfully dropped index "${indexName}" from database "${database}"`, + type: "text", + }, + ], + }; + } +} \ No newline at end of file diff --git a/src/tools/mongodb/tools.ts b/src/tools/mongodb/tools.ts index d64d53ea..ac3cbcc3 100644 --- a/src/tools/mongodb/tools.ts +++ b/src/tools/mongodb/tools.ts @@ -18,6 +18,7 @@ import { DropCollectionTool } from "./delete/dropCollection.js"; import { ExplainTool } from "./metadata/explain.js"; import { CreateCollectionTool } from "./create/createCollection.js"; import { LogsTool } from "./metadata/logs.js"; +import { DropSearchIndexTool } from "./delete/dropSearchIndex.js"; export const MongoDbTools = [ ConnectTool, @@ -40,4 +41,5 @@ export const MongoDbTools = [ ExplainTool, CreateCollectionTool, LogsTool, + DropSearchIndexTool, ]; From 7ec6141da41a387f49918f8aea0efe85965b4557 Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Tue, 13 May 2025 13:39:23 -0700 Subject: [PATCH 2/4] Fix style errors --- src/tools/mongodb/delete/dropSearchIndex.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tools/mongodb/delete/dropSearchIndex.ts b/src/tools/mongodb/delete/dropSearchIndex.ts index 34d3f28a..859aa4c8 100644 --- a/src/tools/mongodb/delete/dropSearchIndex.ts +++ b/src/tools/mongodb/delete/dropSearchIndex.ts @@ -5,17 +5,20 @@ import { ToolArgs, OperationType } from "../../tool.js"; export class DropSearchIndexTool extends MongoDBToolBase { protected name = "drop-search-index"; - protected description = - "Deletes a text or vector search index from the database."; + protected description = "Deletes a text or vector search index from the database."; protected argsShape = { ...DbOperationArgs, indexName: z.string().describe("The name of the search or vector index to delete"), }; protected operationType: OperationType = "delete"; - protected async execute({ database, collection, indexName }: ToolArgs): Promise { + protected async execute({ + database, + collection, + indexName, + }: ToolArgs): Promise { const provider = await this.ensureConnected(); - const result = await provider.dropSearchIndex(database, collection, indexName); + await provider.dropSearchIndex(database, collection, indexName); return { content: [ @@ -26,4 +29,4 @@ export class DropSearchIndexTool extends MongoDBToolBase { ], }; } -} \ No newline at end of file +} From 17f90228210fe5c4f38ecc87608851261a3c59f5 Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Tue, 13 May 2025 14:34:56 -0700 Subject: [PATCH 3/4] Address comments --- src/tools/mongodb/delete/dropSearchIndex.ts | 12 +++++------- src/tools/mongodb/mongodbTool.ts | 6 ++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tools/mongodb/delete/dropSearchIndex.ts b/src/tools/mongodb/delete/dropSearchIndex.ts index 859aa4c8..c72724a6 100644 --- a/src/tools/mongodb/delete/dropSearchIndex.ts +++ b/src/tools/mongodb/delete/dropSearchIndex.ts @@ -1,29 +1,27 @@ import { z } from "zod"; import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; -import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js"; +import { SearchIndexOperationArgs, MongoDBToolBase } from "../mongodbTool.js"; import { ToolArgs, OperationType } from "../../tool.js"; export class DropSearchIndexTool extends MongoDBToolBase { protected name = "drop-search-index"; protected description = "Deletes a text or vector search index from the database."; protected argsShape = { - ...DbOperationArgs, - indexName: z.string().describe("The name of the search or vector index to delete"), + ...SearchIndexOperationArgs, }; protected operationType: OperationType = "delete"; protected async execute({ database, collection, - indexName, + searchIndexName, }: ToolArgs): Promise { const provider = await this.ensureConnected(); - await provider.dropSearchIndex(database, collection, indexName); - + await provider.dropSearchIndex(database, collection, searchIndexName); return { content: [ { - text: `"Successfully dropped index "${indexName}" from database "${database}"`, + text: `Successfully dropped index ${searchIndexName} from database ${database}`, type: "text", }, ], diff --git a/src/tools/mongodb/mongodbTool.ts b/src/tools/mongodb/mongodbTool.ts index 2ef1aee0..0ca66454 100644 --- a/src/tools/mongodb/mongodbTool.ts +++ b/src/tools/mongodb/mongodbTool.ts @@ -10,6 +10,12 @@ export const DbOperationArgs = { collection: z.string().describe("Collection name"), }; +export const SearchIndexOperationArgs = { + database: z.string().describe("Database name"), + collection: z.string().describe("Collection name"), + searchIndexName: z.string().describe("Search Index or Vector Search Index name"), +}; + export abstract class MongoDBToolBase extends ToolBase { protected category: ToolCategory = "mongodb"; From 98ac5bcb100330d0d0e5bcc7718d3e4caf923fae Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Tue, 13 May 2025 14:39:40 -0700 Subject: [PATCH 4/4] Fix remaining style issues --- src/tools/mongodb/delete/dropSearchIndex.ts | 1 - src/tools/mongodb/mongodbTool.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/mongodb/delete/dropSearchIndex.ts b/src/tools/mongodb/delete/dropSearchIndex.ts index c72724a6..d13566c6 100644 --- a/src/tools/mongodb/delete/dropSearchIndex.ts +++ b/src/tools/mongodb/delete/dropSearchIndex.ts @@ -1,4 +1,3 @@ -import { z } from "zod"; import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; import { SearchIndexOperationArgs, MongoDBToolBase } from "../mongodbTool.js"; import { ToolArgs, OperationType } from "../../tool.js"; diff --git a/src/tools/mongodb/mongodbTool.ts b/src/tools/mongodb/mongodbTool.ts index 0ca66454..5d387b25 100644 --- a/src/tools/mongodb/mongodbTool.ts +++ b/src/tools/mongodb/mongodbTool.ts @@ -13,7 +13,7 @@ export const DbOperationArgs = { export const SearchIndexOperationArgs = { database: z.string().describe("Database name"), collection: z.string().describe("Collection name"), - searchIndexName: z.string().describe("Search Index or Vector Search Index name"), + searchIndexName: z.string().describe("Search Index or Vector Search Index name"), }; export abstract class MongoDBToolBase extends ToolBase {