Skip to content

feat: Add drop-search-index tool #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/tools/mongodb/delete/dropSearchIndex.ts
Original file line number Diff line number Diff line change
@@ -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<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
await provider.dropSearchIndex(database, collection, searchIndexName);
return {
content: [
{
text: `Successfully dropped index ${searchIndexName} from database ${database}`,
type: "text",
},
],
};
}
}
6 changes: 6 additions & 0 deletions src/tools/mongodb/mongodbTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions src/tools/mongodb/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,4 +43,5 @@ export const MongoDbTools = [
ExplainTool,
CreateCollectionTool,
LogsTool,
DropSearchIndexTool,
];
Loading