UNPKG

histoire

Version:

A fast story book powered by Vite

25 lines (24 loc) • 1.3 kB
/** Validates an explicit CLI/config TCP port without permissive parseInt coercion. */ function resolvePort(value) { if (typeof value === 'string' && !/^\d+$/.test(value)) throw new Error('MCP port must be an integer from 0 to 65535'); const port = Number(value); if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('MCP port must be an integer from 0 to 65535'); return port; } /** Resolves default-on config and explicit CLI overrides independently of UI --host. */ export function resolveDevMcpOptions(config, cli) { const disabled = cli['no-mcp'] === true || cli.mcp === false; if (disabled && cli.mcp === true) throw new Error('--mcp and --no-mcp cannot be combined'); if (disabled && cli['mcp-port'] !== undefined) throw new Error('--no-mcp and --mcp-port cannot be combined'); const configOptions = typeof config === 'object' && config !== null ? config : undefined; const port = cli['mcp-port'] ?? configOptions?.port; return { enabled: disabled ? false : cli.mcp === true || cli['mcp-port'] !== undefined ? true : config === false ? false : configOptions?.enabled !== false, port: port === undefined ? 6007 : resolvePort(port), explicitPort: port !== undefined, }; }