lance-mcp
Version:
MCP server for interacting with LanceDB database
54 lines (53 loc) • 1.85 kB
JavaScript
import { chunksVectorStore } from "../../lancedb/client.js";
import { BaseTool } from "../base/tool.js";
export class ChunksSearchTool extends BaseTool {
constructor() {
super(...arguments);
this.name = "chunks_search";
this.description = "Search for relevant document chunks in the vector store based on a source document from the catalog";
this.inputSchema = {
type: "object",
properties: {
text: {
type: "string",
description: "Search string",
default: {},
},
source: {
type: "string",
description: "Source document to filter the search",
default: {},
},
},
required: ["text", "source"],
};
}
async execute(params) {
try {
const retriever = chunksVectorStore.asRetriever();
const results = await retriever.invoke(params.text);
// Filter results by source if provided
// TODO: this needs to be pushed down to LanceDB
if (params.source) {
return {
content: [
{
type: "text",
text: JSON.stringify(results.filter((result) => result.metadata.source === params.source), null, 2),
},
],
isError: false,
};
}
return {
content: [
{ type: "text", text: JSON.stringify(results, null, 2) },
],
isError: false,
};
}
catch (error) {
return this.handleError(error);
}
}
}