1- using Microsoft . Extensions . AI ;
1+ using Microsoft . Extensions . AI ;
22using ModelContextProtocol . Protocol . Types ;
33using ModelContextProtocol . Utils ;
44using ModelContextProtocol . Utils . Json ;
77
88namespace ModelContextProtocol ;
99
10- /// <summary>Provides helpers for conversions related to <see cref="AIContent"/>.</summary>
10+ /// <summary>
11+ /// Provides extension methods for converting between Model Context Protocol (MCP) types and Microsoft.Extensions.AI types.
12+ /// </summary>
13+ /// <remarks>
14+ /// This class serves as an adapter layer between Model Context Protocol (MCP) types and the <see cref="AIContent"/> model types
15+ /// from the Microsoft.Extensions.AI namespace.
16+ /// </remarks>
1117public static class AIContentExtensions
1218{
13- /// <summary>Creates a <see cref="ChatMessage"/> from a <see cref="PromptMessage"/>.</summary>
14- /// <param name="promptMessage">The message to convert.</param>
15- /// <returns>The created <see cref="ChatMessage"/>.</returns>
19+ /// <summary>
20+ /// Converts a <see cref="PromptMessage"/> to a <see cref="ChatMessage"/> object.
21+ /// </summary>
22+ /// <param name="promptMessage">The prompt message to convert.</param>
23+ /// <returns>A <see cref="ChatMessage"/> object created from the prompt message.</returns>
24+ /// <remarks>
25+ /// This method transforms a protocol-specific <see cref="PromptMessage"/> from the Model Context Protocol
26+ /// into a standard <see cref="ChatMessage"/> object that can be used with AI client libraries.
27+ /// </remarks>
1628 public static ChatMessage ToChatMessage ( this PromptMessage promptMessage )
1729 {
1830 Throw . IfNull ( promptMessage ) ;
@@ -25,19 +37,32 @@ public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
2537 } ;
2638 }
2739
28- /// <summary>Creates <see cref="ChatMessage"/>s from a <see cref="GetPromptResult"/>.</summary>
29- /// <param name="promptResult">The messages to convert.</param>
30- /// <returns>The created <see cref="ChatMessage"/>.</returns>
40+ /// <summary>
41+ /// Converts a <see cref="GetPromptResult"/> to a list of <see cref="ChatMessage"/> objects.
42+ /// </summary>
43+ /// <param name="promptResult">The prompt result containing messages to convert.</param>
44+ /// <returns>A list of <see cref="ChatMessage"/> objects created from the prompt messages.</returns>
45+ /// <remarks>
46+ /// This method transforms protocol-specific <see cref="PromptMessage"/> objects from a Model Context Protocol
47+ /// prompt result into standard <see cref="ChatMessage"/> objects that can be used with AI client libraries.
48+ /// </remarks>
3149 public static IList < ChatMessage > ToChatMessages ( this GetPromptResult promptResult )
3250 {
3351 Throw . IfNull ( promptResult ) ;
3452
3553 return promptResult . Messages . Select ( m => m . ToChatMessage ( ) ) . ToList ( ) ;
3654 }
3755
38- /// <summary>Gets <see cref="PromptMessage"/> instances for the specified <see cref="ChatMessage"/>.</summary>
39- /// <param name="chatMessage">The message for which to extract its contents as <see cref="PromptMessage"/> instances.</param>
40- /// <returns>The converted content.</returns>
56+ /// <summary>
57+ /// Converts a <see cref="ChatMessage"/> to a list of <see cref="PromptMessage"/> objects.
58+ /// </summary>
59+ /// <param name="chatMessage">The chat message to convert.</param>
60+ /// <returns>A list of <see cref="PromptMessage"/> objects created from the chat message's contents.</returns>
61+ /// <remarks>
62+ /// This method transforms standard <see cref="ChatMessage"/> objects used with AI client libraries into
63+ /// protocol-specific <see cref="PromptMessage"/> objects for the Model Context Protocol system.
64+ /// Only representable content items are processed.
65+ /// </remarks>
4166 public static IList < PromptMessage > ToPromptMessages ( this ChatMessage chatMessage )
4267 {
4368 Throw . IfNull ( chatMessage ) ;
@@ -59,6 +84,10 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
5984 /// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="Content"/>.</summary>
6085 /// <param name="content">The <see cref="Content"/> to convert.</param>
6186 /// <returns>The created <see cref="AIContent"/>.</returns>
87+ /// <remarks>
88+ /// This method converts Model Context Protocol content types to the equivalent Microsoft.Extensions.AI
89+ /// content types, enabling seamless integration between the protocol and AI client libraries.
90+ /// </remarks>
6291 public static AIContent ToAIContent ( this Content content )
6392 {
6493 Throw . IfNull ( content ) ;
@@ -85,6 +114,10 @@ public static AIContent ToAIContent(this Content content)
85114 /// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="ResourceContents"/>.</summary>
86115 /// <param name="content">The <see cref="ResourceContents"/> to convert.</param>
87116 /// <returns>The created <see cref="AIContent"/>.</returns>
117+ /// <remarks>
118+ /// This method converts Model Context Protocol resource types to the equivalent Microsoft.Extensions.AI
119+ /// content types, enabling seamless integration between the protocol and AI client libraries.
120+ /// </remarks>
88121 public static AIContent ToAIContent ( this ResourceContents content )
89122 {
90123 Throw . IfNull ( content ) ;
@@ -105,6 +138,17 @@ public static AIContent ToAIContent(this ResourceContents content)
105138 /// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="Content"/>.</summary>
106139 /// <param name="contents">The <see cref="Content"/> instances to convert.</param>
107140 /// <returns>The created <see cref="AIContent"/> instances.</returns>
141+ /// <remarks>
142+ /// <para>
143+ /// This method converts a collection of Model Context Protocol content objects into a collection of
144+ /// Microsoft.Extensions.AI content objects. It's useful when working with multiple content items, such as
145+ /// when processing the contents of a message or response.
146+ /// </para>
147+ /// <para>
148+ /// Each <see cref="Content"/> object is converted using <see cref="ToAIContent(Content)"/>,
149+ /// preserving the type-specific conversion logic for text, images, audio, and resources.
150+ /// </para>
151+ /// </remarks>
108152 public static IList < AIContent > ToAIContents ( this IEnumerable < Content > contents )
109153 {
110154 Throw . IfNull ( contents ) ;
@@ -114,7 +158,19 @@ public static IList<AIContent> ToAIContents(this IEnumerable<Content> contents)
114158
115159 /// <summary>Creates a list of <see cref="AIContent"/> from a sequence of <see cref="ResourceContents"/>.</summary>
116160 /// <param name="contents">The <see cref="ResourceContents"/> instances to convert.</param>
117- /// <returns>The created <see cref="AIContent"/> instances.</returns>
161+ /// <returns>A list of <see cref="AIContent"/> objects created from the resource contents.</returns>
162+ /// <remarks>
163+ /// <para>
164+ /// This method converts a collection of Model Context Protocol resource objects into a collection of
165+ /// Microsoft.Extensions.AI content objects. It's useful when working with multiple resources, such as
166+ /// when processing the contents of a <see cref="ReadResourceResult"/>.
167+ /// </para>
168+ /// <para>
169+ /// Each <see cref="ResourceContents"/> object is converted using <see cref="ToAIContent(ResourceContents)"/>,
170+ /// preserving the type-specific conversion logic: text resources become <see cref="TextContent"/> objects and
171+ /// binary resources become <see cref="DataContent"/> objects.
172+ /// </para>
173+ /// </remarks>
118174 public static IList < AIContent > ToAIContents ( this IEnumerable < ResourceContents > contents )
119175 {
120176 Throw . IfNull ( contents ) ;
0 commit comments