using System; using System.Collections.Generic; namespace MCPForUnity.Editor.Helpers { /// /// Provides static methods for creating standardized success and error response objects. /// Ensures consistent JSON structure for communication back to the Python server. /// public static class Response { /// /// Creates a standardized success response object. /// /// A message describing the successful operation. /// Optional additional data to include in the response. /// An object representing the success response. public static object Success(string message, object data = null) { if (data != null) { return new { success = true, message = message, data = data, }; } else { return new { success = true, message = message }; } } /// /// Creates a standardized error response object. /// /// A message describing the error. /// Optional additional data (e.g., error details) to include. /// An object representing the error response. public static object Error(string errorCodeOrMessage, object data = null) { if (data != null) { // Note: The key is "error" for error messages, not "message" return new { success = false, // Preserve original behavior while adding a machine-parsable code field. // If callers pass a code string, it will be echoed in both code and error. code = errorCodeOrMessage, error = errorCodeOrMessage, data = data, }; } else { return new { success = false, code = errorCodeOrMessage, error = errorCodeOrMessage }; } } } }