-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeleteOne.ts
38 lines (35 loc) · 1.31 KB
/
deleteOne.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 DeleteOneTool extends MongoDBToolBase {
protected name = "delete-one";
protected description = "Removes a single document that match the filter from a MongoDB collection";
protected argsShape = {
...DbOperationArgs,
filter: z
.object({})
.passthrough()
.optional()
.describe(
"The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany()"
),
};
protected operationType: OperationType = "delete";
protected async execute({
database,
collection,
filter,
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
const result = await provider.deleteOne(database, collection, filter);
return {
content: [
{
text: `Deleted \`${result.deletedCount}\` documents from collection \`${collection}\``,
type: "text",
},
],
};
}
}