UNPKG

lance-mcp

Version:

MCP server for interacting with LanceDB database

63 lines (62 loc) 2.13 kB
import { client } from "../../mongodb/client.js"; import { BaseTool } from "../base/tool.js"; export class FindTool extends BaseTool { constructor() { super(...arguments); this.name = "find"; this.description = "Query documents in a collection using MongoDB query syntax"; this.inputSchema = { type: "object", properties: { database: { type: "string", description: "Name of the database to use", }, collection: { type: "string", description: "Name of the collection to query", }, filter: { type: "object", description: "MongoDB query filter", default: {}, }, limit: { type: "number", description: "Maximum documents to return", default: 10, minimum: 1, maximum: 1000, }, projection: { type: "object", description: "Fields to include/exclude", default: {}, }, }, required: ["database", "collection"], }; } async execute(params) { try { const database = this.validateDatabase(params.database); const collection = this.validateCollection(params.collection); const results = await client .db(database) .collection(collection) .find(params.filter || {}) .project(params.projection || {}) .limit(Math.min(params.limit || 10, 1000)) .toArray(); return { content: [ { type: "text", text: JSON.stringify(results, null, 2) }, ], isError: false, }; } catch (error) { return this.handleError(error); } } }