UNPKG

@cequenceai/mcp-cli

Version:

Cequence MCP CLI - Command-line tool for setting up Cequence MCP servers with AI clients

44 lines (37 loc) 1.04 kB
import { URL } from 'url'; /** * Validates if a string is a valid Cequence MCP server URL */ export function validateMcpUrl(url: string): boolean { try { const parsedUrl = new URL(url); // Check if it's HTTP or HTTPS if (!['http:', 'https:'].includes(parsedUrl.protocol)) { return false; } // Check if URL has a valid host if (!parsedUrl.hostname) { return false; } return true; } catch (error) { return false; } } /** * Validates server name (basic validation) */ export function validateServerName(name: string): boolean { if (!name || typeof name !== 'string') { return false; } // Name should be 1-50 characters, alphanumeric with spaces, hyphens, underscores const nameRegex = /^[a-zA-Z0-9\s\-_]{1,50}$/; return nameRegex.test(name.trim()); } /** * Sanitizes server name for use in configuration files */ export function sanitizeServerName(name: string): string { return name.trim().replace(/[^a-zA-Z0-9\s\-_]/g, '').substring(0, 50); }