lance-mcp
Version:
MCP server for interacting with LanceDB database
57 lines (56 loc) • 2.05 kB
JavaScript
import { client } from "../../mongodb/client.js";
import { BaseTool } from "../base/tool.js";
export class UpdateManyTool extends BaseTool {
constructor() {
super(...arguments);
this.name = "updateMany";
this.description = "Update multiple documents in a collection";
this.inputSchema = {
type: "object",
properties: {
database: {
type: "string",
description: "Name of the database to use",
},
collection: {
type: "string",
description: "Name of the collection",
},
filter: {
type: "object",
description: "Filter to identify documents",
},
update: {
type: "object",
description: "Update operations to apply",
},
},
required: ["database", "collection", "filter", "update"],
};
}
async execute(params) {
try {
const database = this.validateDatabase(params.database);
const collection = this.validateCollection(params.collection);
const filter = this.validateObject(params.filter, "Filter");
const update = this.validateObject(params.update, "Update");
const result = await client.db(database).collection(collection).updateMany(filter, update);
return {
content: [
{
type: "text",
text: JSON.stringify({
matched: result.matchedCount,
modified: result.modifiedCount,
upsertedId: result.upsertedId,
}, null, 2),
},
],
isError: false,
};
}
catch (error) {
return this.handleError(error);
}
}
}