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 1 commit
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 { 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 =

Check failure on line 8 in src/tools/mongodb/delete/dropSearchIndex.ts

View workflow job for this annotation

GitHub Actions / check-style

Delete `⏎·······`
"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"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to repeat this often, so let's register a

export const SearchIndexOperationArgs = {
    database: z.string().describe("Database name"),
    collection: z.string().describe("Collection name"),
    searchIndexName: z.string().describe("Search or VectorSearch Index Name"); 
};

in mongodbTool.ts and import it here and use it on L16 and anywhere else we need.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see 17f9022

};
protected operationType: OperationType = "delete";

protected async execute({ database, collection, indexName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {

Check failure on line 16 in src/tools/mongodb/delete/dropSearchIndex.ts

View workflow job for this annotation

GitHub Actions / check-style

Replace `·database,·collection,·indexName` with `⏎········database,⏎········collection,⏎········indexName,⏎···`
const provider = await this.ensureConnected();
const result = await provider.dropSearchIndex(database, collection, indexName);

Check failure on line 18 in src/tools/mongodb/delete/dropSearchIndex.ts

View workflow job for this annotation

GitHub Actions / check-style

'result' is assigned a value but never used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should the tool be a bit smarter and check whether the index exists first? If it doesn't, maybe we notify the LLM? I guess the more context LLM has, the better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provider already checks and returns an error if the index doesn't exist


return {
content: [
{
text: `"Successfully dropped index "${indexName}" from database "${database}"`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like we don't need double quotes

`"Successfully - before
`Successfully - after

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see 17f9022

type: "text",
},
],
};
}
}

Check failure on line 29 in src/tools/mongodb/delete/dropSearchIndex.ts

View workflow job for this annotation

GitHub Actions / check-style

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