UNPKG

lance-mcp

Version:

MCP server for interacting with LanceDB database

57 lines (56 loc) 2.05 kB
import { client } from "../../mongodb/client.js"; import { BaseTool } from "../base/tool.js"; export class UpdateOneTool extends BaseTool { constructor() { super(...arguments); this.name = "updateOne"; this.description = "Update a single document 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 document", }, 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).updateOne(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); } } }