using System.Diagnostics;
using Microsoft.Extensions.AI;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
///
/// Represents a message within the Model Context Protocol (MCP) system, used for communication between clients and AI models.
///
///
///
/// A encapsulates content sent to or received from AI models in the Model Context Protocol.
/// Each message has a specific role ( or ) and contains content, which can be
/// text, images, audio, or embedded resources.
///
///
/// This class is similar to , but with enhanced support for embedding resources from the MCP server.
/// It serves as a core data structure in the MCP message exchange flow, particularly in prompt formation and model responses.
///
///
/// objects are typically used in collections within
/// to represent complete conversations or prompt sequences. They can be converted to and from
/// objects using the extension methods and
/// .
///
///
/// See the schema for details.
///
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public sealed class PromptMessage
{
///
/// Gets or sets the content of the message, which can be text, image, audio, or an embedded resource.
///
///
/// The object contains all the message payload, whether it's simple text,
/// base64-encoded binary data (for images/audio), or a reference to an embedded resource.
/// The property indicates the specific content type.
///
[JsonPropertyName("content")]
public required ContentBlock Content { get; set; }
///
/// Gets or sets the role of the message sender, specifying whether it's from a "user" or an "assistant".
///
///
/// In the Model Context Protocol, each message must have a clear role assignment to maintain
/// the conversation flow. User messages represent queries or inputs from users, while assistant
/// messages represent responses generated by AI models.
///
[JsonPropertyName("role")]
public required Role Role { get; set; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get
{
// Show actual text content if it's a TextContentBlock
if (Content is TextContentBlock textBlock)
{
return $"Role = {Role}, Text = \"{textBlock.Text}\"";
}
return $"Role = {Role}, ContentType = {Content.Type}";
}
}
}