vibe-coder-mcp
Version:
Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.
79 lines (78 loc) • 2.73 kB
JavaScript
import { readFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const toolConfig = JSON.parse(readFileSync(path.join(__dirname, "..", "..", "..", "mcp-config.json"), "utf-8"));
export function detectIntent(request) {
const words = request.toLowerCase().split(/\s+/);
const scores = {};
for (const [toolName, toolData] of Object.entries(toolConfig.tools)) {
let score = 0;
const descWords = toolData.description.toLowerCase().split(/\s+/);
for (const word of words) {
if (word.length > 3 && descWords.includes(word)) {
score += 1;
}
}
for (const useCase of toolData.use_cases) {
const useCaseWords = useCase.toLowerCase().split(/\s+/);
for (const word of words) {
if (word.length > 3 && useCaseWords.includes(word)) {
score += 2;
}
}
}
const normalizedScore = score / words.length;
scores[toolName] = normalizedScore;
}
let bestTool = "";
let highestScore = 0;
for (const [toolName, score] of Object.entries(scores)) {
if (score > highestScore) {
highestScore = score;
bestTool = toolName;
}
}
const confidence = Math.min(highestScore, 0.85);
if (confidence > 0.3 && bestTool) {
return {
toolName: bestTool,
confidence,
matchedPattern: "intent_matching"
};
}
return null;
}
export function extractContextParameters(request) {
const params = {};
const words = request.split(/\s+/);
const forMatch = request.match(/\bfor\s+([^.,;]+)/i);
if (forMatch) {
params["target"] = forMatch[1].trim();
}
const aboutMatch = request.match(/\babout\s+([^.,;]+)/i);
if (aboutMatch) {
params["topic"] = aboutMatch[1].trim();
}
for (let i = 0; i < words.length; i++) {
if (words[i].length > 1 &&
words[i][0] === words[i][0].toUpperCase() &&
words[i][0] !== 'I' &&
!/^(The|A|An|In|On|At|By|For|With|To)$/i.test(words[i])) {
let entity = words[i];
let j = i + 1;
while (j < words.length &&
words[j][0] === words[j][0].toUpperCase() &&
!/^(The|A|An|In|On|At|By|For|With|To)$/i.test(words[j])) {
entity += " " + words[j];
j++;
}
if (!params["entity"]) {
params["entity"] = entity;
}
i = j - 1;
}
}
return params;
}