lance-mcp
Version:
MCP server for interacting with LanceDB database
40 lines (39 loc) • 1.36 kB
JavaScript
import { BroadSearchTool } from "./operations/broad_chunks_search.js";
import { CatalogSearchTool } from "./operations/catalog_search.js";
import { ChunksSearchTool } from "./operations/chunks_search.js";
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
export class ToolRegistry {
constructor() {
this.tools = new Map();
this.registerTool(new ChunksSearchTool());
this.registerTool(new CatalogSearchTool());
this.registerTool(new BroadSearchTool());
}
registerTool(tool) {
this.tools.set(tool.name, tool);
}
getTool(name) {
const tool = this.tools.get(name);
if (!tool) {
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
}
return tool;
}
getAllTools() {
return Array.from(this.tools.values());
}
getToolSchemas() {
return this.getAllTools().map((tool) => {
const inputSchema = tool.inputSchema;
return {
name: tool.name,
description: tool.description,
inputSchema: {
type: "object",
properties: inputSchema.properties || {},
...(inputSchema.required && { required: inputSchema.required }),
},
};
});
}
}