UNPKG

@xiaohui-wang/mcpadvisor

Version:

MCP Advisor & Installation - Find the right MCP server for your needs

39 lines (38 loc) 1.37 kB
import logger from '../../../utils/logger.js'; export class RequestHandlerFactory { static createListToolsHandler(toolHandlers) { return async () => { logger.debug('Handling ListTools request'); return { tools: toolHandlers.map(handler => handler.getToolDefinition()), }; }; } static createCallToolHandler(toolHandlers) { return async (request) => { const { name } = request.params; logger.info(`Handling tool call: ${name}`); try { const handler = toolHandlers.find(h => h.canHandle(name)); if (!handler) { return RequestHandlerFactory.createErrorResponse(`Unknown tool: ${name}`); } return await handler.handleRequest(request); } catch (error) { const message = error instanceof Error ? error.message : String(error); logger.error(`Error handling request: ${message}`); return RequestHandlerFactory.createErrorResponse(message); } }; } static createErrorResponse(message) { return { content: [{ type: 'text', text: `Error: ${message}`, }], isError: true, }; } }