UNPKG

@kya-os/mcp-i

Version:

The TypeScript MCP framework with identity features built-in

57 lines (56 loc) 1.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidPath = isValidPath; const constants_1 = require("./constants"); // Simplified - remove chalk styling for now const chalk = { red: { bold: (text) => text, }, yellow: (text) => text, }; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function isValidPath(pathStr, type) { function isNonEmptyString(str) { return typeof str === "string" && str.length > 0; } function isGlob(str) { return /[*?\[\]{}]/.test(str); } function normalizePath(p) { // normalize to posix (forward slashes) return p.split(/\\|\//).join("/"); } function resolveAndCheckExists(p) { const normalized = normalizePath(p); const absPath = path_1.default.resolve(constants_1.rootFolder, normalized); if (!fs_1.default.existsSync(absPath)) { exitError(`The path set in xmcp config for ${type} does not exist: ${absPath}`); } return normalized; // still return the normalized path cause we're formatting to glob later } if (pathStr === undefined) { return undefined; } // reject empty string if (pathStr === "") { exitError(`${type} path cannot be an empty string`); } if (isNonEmptyString(pathStr)) { if (isGlob(pathStr)) { exitError(`If you are using a glob pattern, please use a string for the ${type} path`); } return resolveAndCheckExists(pathStr); } exitError(`${type} path must be a non-empty string`); } function exitError(message) { console.log(""); console.log(chalk.red.bold(message)); console.log(""); process.exit(1); }