lance-mcp
Version:
MCP server for interacting with LanceDB database
44 lines (43 loc) • 1.39 kB
JavaScript
import { BaseTool } from "../base/tool.js";
import { db } from "../../mongodb/client.js";
export class CreateIndexTool extends BaseTool {
constructor() {
super(...arguments);
this.name = "createIndex";
this.description = "Create a new index on a collection";
this.inputSchema = {
type: "object",
properties: {
collection: {
type: "string",
description: "Name of the collection",
},
indexSpec: {
type: "object",
description: "Index specification (e.g., { field: 1 } for ascending index)",
},
},
required: ["collection", "indexSpec"],
};
}
async execute(params) {
try {
const collection = this.validateCollection(params.collection);
const indexName = await db
.collection(collection)
.createIndex(params.indexSpec);
return {
content: [
{
type: "text",
text: JSON.stringify({ indexName }, null, 2),
},
],
isError: false,
};
}
catch (error) {
return this.handleError(error);
}
}
}