lance-mcp
Version:
MCP server for interacting with LanceDB database
45 lines (44 loc) • 1.53 kB
JavaScript
import { client } from "../../mongodb/client.js";
import { BaseTool } from "../base/tool.js";
export class CountTool extends BaseTool {
constructor() {
super(...arguments);
this.name = "count";
this.description = "Count 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: {},
},
},
required: ["database", "collection"],
};
}
async execute(params) {
try {
const database = this.validateDatabase(params.database);
const collection = this.validateCollection(params.collection);
const count = await client.db(database).collection(collection).countDocuments(params.filter || {});
return {
content: [
{ type: "text", text: JSON.stringify({ count }, null, 2) },
],
isError: false,
};
}
catch (error) {
return this.handleError(error);
}
}
}