/** * Format Utility Module * * Provides utilities for formatting response data as JSON or TOON format. * TOON (Token Optimized Object Notation) is a human-readable format that * uses fewer tokens than JSON while maintaining semantic clarity. * * @see MCI-014-03-format-utility-module */ /** * Supported output formats for response data */ export type OutputFormat = 'json' | 'toon'; /** * Format response data as JSON or TOON. * * JSON format (default) returns the original data object unchanged, * allowing the MCP protocol to handle JSON serialization. * * TOON format returns a human-readable string optimized for token efficiency. * * @param data - The data to format * @param format - Output format ('json' or 'toon'), defaults to 'json' * @returns Formatted data - original object for JSON, string for TOON * * @example * ```typescript * // JSON (default) - returns unchanged * formatResponse({ id: "123" }) // returns { id: "123" } * * // TOON - returns formatted string * formatResponse({ id: "123" }, 'toon') * // returns "id: 123" * * // Complex objects * formatResponse({ * ticket: { id: "T-001", title: "Task", status: "done" } * }, 'toon') * // returns: * // ticket.id: T-001 * // ticket.title: Task * // ticket.status: done * ``` */ export declare function formatResponse(data: T, format?: OutputFormat): string | T; /** * Format an array of items with optional TOON tabular formatting * * For TOON format, arrays with homogeneous objects can be rendered * in a more compact tabular format. This is useful for lists of * tickets, epics, etc. * * @param items - Array of items to format * @param format - Output format * @returns Formatted items * * @example * ```typescript * formatArrayResponse([ * { id: '1', status: 'done' }, * { id: '2', status: 'todo' } * ], 'toon') * // Returns: * // []: * // - id: 1 * // status: done * // - id: 2 * // status: todo * ``` */ export declare function formatArrayResponse(items: T[], format?: OutputFormat): string | T[]; /** * Format an error response with consistent structure * * @param error - Error message or Error object * @param code - Optional error code * @param format - Output format * @returns Formatted error response * * @example * ```typescript * formatErrorResponse('Not found', 'NOT_FOUND', 'toon') * // Returns: * // error: Not found * // code: NOT_FOUND * ``` */ export declare function formatErrorResponse(error: string | Error, code?: string, format?: OutputFormat): string | { error: string; code?: string; }; /** * Format a success response with optional data * * @param message - Success message * @param data - Optional additional data * @param format - Output format * @returns Formatted success response * * @example * ```typescript * formatSuccessResponse('Created', { id: '123' }, 'toon') * // Returns: * // success: true * // message: Created * // id: 123 * ``` */ export declare function formatSuccessResponse>(message: string, data?: T, format?: OutputFormat): string | { success: true; message: string; } & T; //# sourceMappingURL=format.d.ts.map