diff --git a/src/tools/mongodb/delete/dropSearchIndex.ts b/src/tools/mongodb/delete/dropSearchIndex.ts new file mode 100644 index 00000000..d13566c6 --- /dev/null +++ b/src/tools/mongodb/delete/dropSearchIndex.ts @@ -0,0 +1,29 @@ +import { CallToolResult } from "@modelcontextprotocol/sdk/types.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 = { + ...SearchIndexOperationArgs, + }; + protected operationType: OperationType = "delete"; + + protected async execute({ + database, + collection, + searchIndexName, + }: ToolArgs): Promise { + const provider = await this.ensureConnected(); + await provider.dropSearchIndex(database, collection, searchIndexName); + return { + content: [ + { + 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..5d387b25 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"; diff --git a/src/tools/mongodb/tools.ts b/src/tools/mongodb/tools.ts index cf1e52d3..34074a07 100644 --- a/src/tools/mongodb/tools.ts +++ b/src/tools/mongodb/tools.ts @@ -19,6 +19,7 @@ import { ExplainTool } from "./metadata/explain.js"; import { CreateCollectionTool } from "./create/createCollection.js"; import { LogsTool } from "./metadata/logs.js"; import { CollectionSearchIndexesTool } from "./read/collectionSearchIndexes.js"; +import { DropSearchIndexTool } from "./delete/dropSearchIndex.js"; export const MongoDbTools = [ ConnectTool, @@ -42,4 +43,5 @@ export const MongoDbTools = [ ExplainTool, CreateCollectionTool, LogsTool, + DropSearchIndexTool, ];