UNPKG

lance-mcp

Version:

MCP server for interacting with LanceDB database

51 lines (50 loc) 1.76 kB
import { client } from "../../mongodb/client.js"; import { BaseTool } from "../base/tool.js"; export class InsertOneTool extends BaseTool { constructor() { super(...arguments); this.name = "insertOne"; this.description = "Insert a single document into 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", }, document: { type: "object", description: "Document to insert", }, }, required: ["database", "collection", "document"], }; } async execute(params) { try { const database = this.validateDatabase(params.database); const collection = this.validateCollection(params.collection); const document = this.validateObject(params.document, "Document"); const result = await client.db(database).collection(collection).insertOne(document); return { content: [ { type: "text", text: JSON.stringify({ acknowledged: result.acknowledged, insertedId: result.insertedId, }, null, 2), }, ], isError: false, }; } catch (error) { return this.handleError(error); } } }