UNPKG

vibe-coder-mcp

Version:

Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.

86 lines (83 loc) 3.54 kB
import { processWithSequentialThinking } from "../../tools/sequential-thinking.js"; import { findBestSemanticMatch } from "../routing/semanticMatcher.js"; import logger from "../../logger.js"; const HIGH_CONFIDENCE = 0.8; export async function hybridMatch(request, config) { let matchResult = null; let parameters = {}; let matchMethod = "sequential"; let requiresConfirmation = true; logger.debug('Trying semantic matching...'); const semanticMatchResult = await findBestSemanticMatch(request); if (semanticMatchResult) { matchMethod = "semantic"; matchResult = semanticMatchResult; parameters = {}; requiresConfirmation = semanticMatchResult.confidence < HIGH_CONFIDENCE; logger.info(`Match found via semantic search: ${matchResult.toolName} (Confidence: ${matchResult.confidence.toFixed(3)})`); return { ...matchResult, parameters, matchMethod, requiresConfirmation }; } else { logger.debug('Semantic matching did not yield a confident result. Falling back to sequential thinking...'); } try { const sequentialResult = await performSequentialThinking(request, "What tool should I use for this request? Options are: research-manager, prd-generator, user-stories-generator, task-list-generator, rules-generator, workflow-manager.", config); const toolName = sequentialResult.toLowerCase() .trim() .split("\n")[0] .replace(/^.*?: /, ""); if (toolName && (toolName.includes("generator") || toolName.includes("manager"))) { matchResult = { toolName: toolName, confidence: 0.5, matchedPattern: "sequential_thinking" }; matchMethod = "sequential"; requiresConfirmation = true; parameters = {}; return { ...matchResult, parameters, matchMethod, requiresConfirmation }; } } catch (error) { logger.error({ err: error }, "Sequential thinking failed"); } return { toolName: "research-manager", confidence: 0.2, matchedPattern: "fallback", parameters: { query: request }, matchMethod: "sequential", requiresConfirmation: true }; } async function performSequentialThinking(request, systemPrompt, config) { const prompt = `Given this user request: "${request}" ${systemPrompt} Analyze the request and determine which tool is most appropriate. Reply with just the name of the most appropriate tool.`; return await processWithSequentialThinking(prompt, config); } export function getMatchExplanation(match) { switch (match.matchMethod) { case "semantic": return `I chose the ${match.toolName} because your request seems semantically similar to its purpose. I'm ${Math.round(match.confidence * 100)}% confident.`; case "sequential": if (match.matchedPattern === "fallback") { return `I wasn't sure which tool to use, so I'm defaulting to the ${match.toolName}. Please let me know if you'd prefer a different tool.`; } else { return `After analyzing your request, I believe the ${match.toolName} is the most appropriate tool to use.`; } default: return `I selected the ${match.toolName} based on your request.`; } }