/** * Utility Helpers * * Common utility functions used across the MCP codebase. */ /** * Safely parse JSON with a default fallback value. * Prevents crashes from malformed JSON in the database. * * @param json - The JSON string to parse (can be null/undefined) * @param defaultValue - Value to return if parsing fails * @returns Parsed value or default */ export declare function safeJsonParse(json: string | null | undefined, defaultValue: T): T; /** * Safely stringify an object to JSON. * Returns null on error instead of throwing. * * @param value - The value to stringify * @returns JSON string or null on error */ export declare function safeJsonStringify(value: unknown): string | null; /** * Wrap a function with error handling. * Logs errors and optionally rethrows. * * @param name - Name for logging * @param fn - Function to wrap * @param rethrow - Whether to rethrow errors (default: false) * @returns Wrapped function */ export declare function withErrorHandling unknown>(name: string, fn: T, rethrow?: boolean): T; /** * Ensure a value is an array. * * @param value - Value that might be an array * @returns Array (original if array, wrapped in array if single value, empty if null/undefined) */ export declare function ensureArray(value: T | T[] | null | undefined): T[]; /** * Truncate a string to a maximum length with ellipsis. * * @param str - String to truncate * @param maxLength - Maximum length (including ellipsis) * @returns Truncated string */ export declare function truncate(str: string, maxLength: number): string; /** * Generate a unique ID. * * @param prefix - Optional prefix for the ID * @returns Unique ID string */ export declare function generateId(prefix?: string): string; /** * Check if a value is a non-empty string. */ export declare function isNonEmptyString(value: unknown): value is string; /** * Check if a value is a valid MITRE technique ID. */ export declare function isValidMitreId(value: unknown): boolean; /** * Format a date to ISO string safely. */ export declare function formatDate(date?: Date | string | number): string;